diff --git a/bin/mm-format-ns-glucose.sh b/bin/mm-format-ns-glucose.sh new file mode 100755 index 0000000..5dba394 --- /dev/null +++ b/bin/mm-format-ns-glucose.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# Author: Ben West @bewest +# Maintainer: Chris Oattes @cjo20 + +# Written for decocare v0.0.17. Will need updating the the decocare json format changes. +HISTORY=${1-glucosehistory.json} +OUTPUT=${2-/dev/fd/1} +#TZ=${3-$(date +%z)} + +cat $HISTORY | \ + json -e "this.medtronic = this._type;" | \ + json -e "this.dateString = this.date + '$(date +%z)'" | \ + json -e "this.date = new Date(this.dateString).getTime();" | \ + json -e "this.type = (this.name == 'GlucoseSensorData') ? 'sgv' : 'pumpdata'" | \ + json -e "this.device = 'openaps://medtronic/pump/cgm'" \ + > $OUTPUT + diff --git a/bin/mm-format-ns-pump-history.sh b/bin/mm-format-ns-pump-history.sh new file mode 100755 index 0000000..6556249 --- /dev/null +++ b/bin/mm-format-ns-pump-history.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# Author: Ben West +# Maintainer: Scott Leibrand + +HISTORY=${1-pumphistory.json} +OUTPUT=${2-/dev/fd/1} +#TZ=${3-$(date +%z)} + +cat $HISTORY | \ + json -e "this.medtronic = this._type;" | \ + #json -e "this.dateString = this.timestamp + '$(TZ=TZ date +%z)'" | \ + json -e "this.dateString = this.timestamp + '$(date +%z)'" | \ + json -e "this.type = 'medtronic'" | \ + json -e "this.date = this.date ? this.date : new Date(Date.parse(this.dateString)).getTime( )" \ + > $OUTPUT + + diff --git a/bin/mm-stick.sh b/bin/mm-stick.sh new file mode 100755 index 0000000..00c7bfa --- /dev/null +++ b/bin/mm-stick.sh @@ -0,0 +1,100 @@ +#!/bin/bash -eu + +# Author: Ben West @bewest + +# Written for decocare v0.0.17. +OUTPUT=/dev/fd/1 +if [[ "${1-}" == "-f" ]] ; then +shift +OUTPUT=$1 +shift +fi +OPERATION=${1-help} +export $OPERATION + +function print_help ( ) { + cat < unbind + echo -n "$i" > bind + done + done + ;; + list-usb) + if [[ $EUID != 0 ]] ; then + echo This must be run as root! + exit 1 + fi + + for xhci in /sys/bus/pci/drivers/?hci_hcd ; do + + if ! cd $xhci ; then + echo Weird error. Failed to change directory to $xhci + exit 1 + fi + + echo Resetting devices from $xhci... + + for i in ????:??:??.? ; do + pwd + echo $i + ls $i + done + done + ;; + *|help) + print_help + ;; + esac +) +shift +OPERATION=${1-} +done > $OUTPUT +exit $? diff --git a/bin/ns-upload-entries.sh b/bin/ns-upload-entries.sh new file mode 100755 index 0000000..0bb0f56 --- /dev/null +++ b/bin/ns-upload-entries.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Author: Ben West +# Maintainer: @cjo20, @scottleibrand + +ENTRIES=${1-entries.json} +NIGHTSCOUT_HOST=${NIGHTSCOUT_HOST-localhost:1337} +#TZ=${3-$(date +%z)} +OUTPUT=${2} + +export ENTRIES API_SECRET NIGHTSCOUT_HOST +# requires API_SECRET and NIGHTSCOUT_HOST to be set in calling environment (i.e. in crontab) +( +curl -s -X POST --data-binary @$ENTRIES \ + -H "API-SECRET: $API_SECRET" \ + -H "content-type: application/json" \ + $NIGHTSCOUT_HOST/api/v1/entries.json +) && ( test -n "$OUTPUT" && touch $OUTPUT ; logger "Uploaded $ENTRIES to $NIGHTSCOUT_HOST" ) || logger "Unable to upload to $NIGHTSCOUT_HOST" + diff --git a/bin/ns-upload.sh b/bin/ns-upload.sh deleted file mode 100755 index 7805de3..0000000 --- a/bin/ns-upload.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -# Author: Ben West, Maintainer: Scott Leibrand - -HISTORY=${1-pumphistory.json} -OUTPUT=${2-pumphistory.ns.json} -#TZ=${3-$(date +%z)} - -cat $HISTORY | \ - json -e "this.medtronic = this._type;" | \ - #json -e "this.dateString = this.timestamp + '$(TZ=TZ date +%z)'" | \ - json -e "this.dateString = this.timestamp + '$(date +%z)'" | \ - json -e "this.type = 'medtronic'" | \ - json -e "this.date = this.date ? this.date : new Date(Date.parse(this.dateString)).getTime( )" \ - > $OUTPUT - - -# requires API_SECRET and NIGHTSCOUT_HOST to be set in calling environment (i.e. in crontab) -curl -s -X POST --data-binary @$OUTPUT -H "API-SECRET: $API_SECRET" -H "content-type: application/json" $NIGHTSCOUT_HOST/api/v1/entries.json >/dev/null && ( touch /tmp/openaps.online && echo "Uploaded $OUTPUT to $NIGHTSCOUT_HOST" ) || echo "Unable to upload to $NIGHTSCOUT_HOST" diff --git a/bin/iob.js b/bin/oref0-calculate-iob.js old mode 100644 new mode 100755 similarity index 100% rename from bin/iob.js rename to bin/oref0-calculate-iob.js diff --git a/bin/determine-basal.js b/bin/oref0-determine-basal.js old mode 100644 new mode 100755 similarity index 99% rename from bin/determine-basal.js rename to bin/oref0-determine-basal.js index fbcce80..83a3467 --- a/bin/determine-basal.js +++ b/bin/oref0-determine-basal.js @@ -47,7 +47,7 @@ if (!module.parent) { } else { console.error("Could not determine last BG time"); } var minAgo = (systemTime - bgTime) / 60 / 1000 - if (minAgo > 10 && minAgo < -5) { // Dexcom data is too old, or way in the future + if (minAgo > 10 || minAgo < -5) { // Dexcom data is too old, or way in the future var reason = "BG data is too old, or clock set incorrectly"; console.error(reason); return 1; diff --git a/bin/getprofile.js b/bin/oref0-get-profile.js old mode 100644 new mode 100755 similarity index 100% rename from bin/getprofile.js rename to bin/oref0-get-profile.js diff --git a/bin/oref0-iftt-notify b/bin/oref0-iftt-notify new file mode 100755 index 0000000..774b30a --- /dev/null +++ b/bin/oref0-iftt-notify @@ -0,0 +1,99 @@ +#!/bin/bash + +self=$(basename $0) +# Something like this: +# https://maker.ifttt.com/trigger/{event}/with/key/MyKey +IFTTT_TRIGGER=${IFTTT_TRIGGER-${1}} +IFTT_NOTIFY_USAGE="${2-pump model}" + +function help_message ( ) { +cat < + +## Setup IFTTT Account + +You need to create an account and connect to the Maker channel and the +notification channel of your choice. I use pushover as I already had the app +and it allows me more control over the notification on my phone. + +## Create an IF recipe +The trigger is the maker channel. You can customize the notification message +if you wish. + +## Get the event trigger +On the Maker channel there is a "how to trigger" link. Copy and paste the url +for the example curl command, be sure to change the event name field. +The URL, something like: +# https://maker.ifttt.com/trigger/{event}/with/key/MyKey + +You can pass the IFTTT_TRIGGER, which is the trigger URL as the first +argument, or define it as an environment variable in your crontab. + +Command line: + + $self https://maker.ifttt.com/trigger/{event}/with/key/MyKey + + +Crontab: + IFTTT_TRIGGER=https://maker.ifttt.com/trigger/{event}/with/key/MyKey + +By default $self will check that the stick works, and notify the IFTTT_TRIGGER +endpoint only if the the stick fails to check out. If the stick diagnostics +indicate the carelink stick is working, $self will run: + + openaps use $IFTT_NOTIFY_USAGE + +You can specify which openaps use command to use in the second argument, or by +setting the IFTT_NOTIFY_USAGE environment variable in crontab: + +Command line, note the quotes, the second term must be passed as single word. + + $self https://maker.ifttt.com/trigger/{event}/with/key/MyKey 'pump model' + +Crontab: + + IFTT_NOTIFY_USAGE='pump model' + +Author: @audiefile +EOF + +} + + + +case $1 in +env) + echo PATH=$PATH + env + exit + ;; +help) + help_message + ;; +*) + if [[ -z "$IFTTT_TRIGGER" || -z "$IFTT_NOTIFY_USAGE" ]] ; then + help_message + exit 1 + fi + ;; +esac + + +empty="" +# check carelink is working - if not send notification +# maybe switch: +# mm-stick diagnose > /dev/null || curl -X POST $IFTTT_TRIGGER + +python -m decocare.stick $(python -m decocare.scan) >/dev/null || curl -X POST $IFTTT_TRIGGER +echo "Carelink Stick OK" + +# check carelink can talk to pump - if not send notification +model=$(openaps use $IFTT_NOTIFY_USAGE) +echo "Model: " $model +if [ $model=$empty ]; +then + echo "Model is empty" + curl -X POST $IFTTT_TRIGGER +fi + diff --git a/bin/pebble.js b/bin/oref0-pebble.js old mode 100644 new mode 100755 similarity index 100% rename from bin/pebble.js rename to bin/oref0-pebble.js diff --git a/bin/oref0.sh b/bin/oref0.sh new file mode 100755 index 0000000..3070f30 --- /dev/null +++ b/bin/oref0.sh @@ -0,0 +1,45 @@ +#!/bin/bash + + +self=$(basename $0) +NAME=${1-help} +shift +PROGRAM="oref0-${NAME}" +COMMAND=$(which $PROGRAM | head -n 1) + +function help_message ( ) { + cat < + + ______ ______ ______ ______ 0 +/ | | \ | | | \ | | | | +| | | | | |__| | | |---- | |---- +\_|__|_/ |_| \_\ |_|____ |_| + +Valid commands: + oref0 env - print information about environment. + oref0 pebble + oref0 iftt-notify + oref0 get-profile + oref0 calculate-iob + oref0 determine-basal + oref0 help - this message +EOF +} + +case $NAME in +env) + echo PATH=$PATH + env + exit + ;; +help) + help_message + ;; +*) + test -n "$COMMAND" && exec $COMMAND $* + ;; +esac + + diff --git a/bin/fix-dead-carelink.sh b/bin/reset-wifi-dongle.sh similarity index 100% rename from bin/fix-dead-carelink.sh rename to bin/reset-wifi-dongle.sh diff --git a/bin/sendtempbasal-Azure.js b/bin/send-tempbasal-Azure.js similarity index 100% rename from bin/sendtempbasal-Azure.js rename to bin/send-tempbasal-Azure.js diff --git a/package.json b/package.json index 2df3e67..d224738 100644 --- a/package.json +++ b/package.json @@ -17,11 +17,23 @@ "bugs": { "url": "https://github.com/openaps/openaps-js/issues" }, - "bin" : { - "calculate-iob" : "./bin/iob.js", - "determine-basal" : "./bin/determine-basal.js", - "send-tempbasal-Azure" : "./bin/sendtempbasal-Azure.js", - "get-profile" : "./bin/getprofile.js" + "bin": { + "oref0-calculate-iob": "./bin/oref0-calculate-iob.js", + "oref0-determine-basal": "./bin/oref0-determine-basal.js", + "send-tempbasal-Azure": "./bin/send-tempbasal-Azure.js", + "oref0-get-profile": "./bin/oref0-get-profile.js", + "oref0-iftt-notify": "./bin/oref0-iftt-notify", + "reset-wifi-dongle": "bin/reset-wifi-dongle.sh", + "mm-format-ns-glucose": "./bin/mm-format-ns-glucose.sh", + "mm-format-ns-pump-history": "./bin/mm-format-ns-pump-history.sh", + "oref0": "./bin/oref0.sh", + "mm-stick": "./bin/mm-stick.sh", + "openaps-js": "./bin/oref0.sh", + "ns-upload-entries": "./bin/ns-upload-entries.sh", + "oref0-pebble": "./bin/oref0-pebble.js" }, - "homepage": "https://github.com/openaps/openaps-js" + "homepage": "https://github.com/openaps/openaps-js", + "dependencies": { + "share2nightscout-bridge": "^0.1.5" + } }