Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions bin/mm-format-ns-glucose.sh
Original file line number Diff line number Diff line change
@@ -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

18 changes: 18 additions & 0 deletions bin/mm-format-ns-pump-history.sh
Original file line number Diff line number Diff line change
@@ -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


100 changes: 100 additions & 0 deletions bin/mm-stick.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
Usage: $0 [{scan,diagnose,help},...]

scan - Print the local location of a plugged in stick.
diagnose - Run python -m decocare.stick \$(python -m decocare.scan)
insert - Insert usbserial kernel module.
remove - Remove usbserial kernel module.
udev-info - Print udev information about the stick.
list-usb - List usb information about the stick.
reset-usb - Reset entire usb stack. WARNING, be careful.
help - This message.
EOF
}

while [ -n "$OPERATION" ] ; do
(
case $OPERATION in
scan)
eval python -m decocare.scan
;;
diagnose)
eval python -m decocare.stick $(python -m decocare.scan)
;;
remove)
eval modprobe -r usbserial
;;
insert)
#Bus 002 Device 011: ID 0a21:8001 Medtronic Physio Control Corp.
eval modprobe --first-time usbserial vendor=0x0a21 product=0x8001
;;
udev-info)
eval udevadm info --query=all $(python -m decocare.scan)
;;
reset-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
echo -n "$i" > 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 $?
19 changes: 19 additions & 0 deletions bin/ns-upload-entries.sh
Original file line number Diff line number Diff line change
@@ -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"

19 changes: 0 additions & 19 deletions bin/ns-upload.sh

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion bin/determine-basal.js → bin/oref0-determine-basal.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
File renamed without changes.
99 changes: 99 additions & 0 deletions bin/oref0-iftt-notify
Original file line number Diff line number Diff line change
@@ -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 <<EOF
Usage:
$self <IFTTT_TRIGGER> <NOTIFY_USAGE>

## 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

File renamed without changes.
45 changes: 45 additions & 0 deletions bin/oref0.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
Usage:
$self <cmd>

______ ______ ______ ______ 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


File renamed without changes.
File renamed without changes.
24 changes: 18 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}