Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 16 additions & 0 deletions bin/clockset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ CLOCK=${1-monitor/clock.json}
GLUCOSE=${2-monitor/glucose.json}

die() { echo "$@" ; exit 1; }
self=$(basename $0)
function usage ( ) {

cat <<EOF
$self
$self - Restart NTP, manipulate realtime clock
EOF
}

case "$1" in
--help|help|-h)
usage
exit 0
;;
esac


ntp-wait -n 1 -v && die "NTP already synchronized." || ( sudo /etc/init.d/ntp restart && ntp-wait -n 1 -v && die "NTP re-synchronized." )

Expand Down
15 changes: 15 additions & 0 deletions bin/mm-format-ns-glucose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@
NSONLY=""
test "$1" = "--oref0" && NSONLY="this.glucose = this.sgv" && shift

self=$(basename $0)
function usage ( ) {

cat <<EOT
$self [--oref0] <medtronic-glucose.json>
$self - Format Medtronic glucose data into something acceptable to Nightscout.
EOT
}

case "$1" in
--help|-h|help)
usage
exit 0
esac

HISTORY=${1-glucosehistory.json}
OUTPUT=${2-/dev/fd/1}
#TZ=${3-$(date +%z)}
Expand Down
23 changes: 21 additions & 2 deletions bin/mm-format-ns-profile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,32 @@

# Author: Ben West

self=$(basename $0)
SETTINGS=${1-monitor/settings.json}
CARBS=${2-monitor/carb-ratios.json}
BASALRATES=${3-monitor/active-basal-profile.json}
SENSITIVITIES=${4-monitor/insulin-sensitivities.json}
TARGETS=${5-monitor/bg-targets.json}
OUTPUT=${6-settings/ns-profile.json}
OUTPUT=${6-/dev/fd/1}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where to cat the results (- aka, stdout is also named /dev/fd/1) Many tools allow for an --output - or any other file, this is the bashism to do that.

# DIA
# CARBRATIO
#TZ=${3-$(date +%z)}

function usage ( ) {
cat <<EOF
$self: Format known pump data into Nightscout "profile".

Profile documents allow Nightscout to establish a common set of settings for
therapy, including the type of units used, the timezone, carb-ratios, active
basal profiles, insulin sensitivities, and BG targets. This compiles the
separate pump reports into a single profile document for Nightscout.

Usage:
$self pump-settings carb-ratios active-basal-profile insulin-sensitivities bg-targets

Examples:
bewest@bewest-MacBookPro:~/Documents/openaps$ mm-format-ns-profile monitor/settings.json monitor/carb-ratios.json monitor/active-basal-profile.json monitor/insulin-sensitivities.json monitor/bg-targets.json

EOF
}

Expand Down Expand Up @@ -132,7 +146,12 @@ function stub ( ) {
}
EOF
}

case $1 in
--help|config|help|-h)
usage
exit 0
;;
esac
stub $SETTINGS | fix-dates \
| add-carbs $CARBS \
| add-basals $BASALRATES \
Expand Down
16 changes: 16 additions & 0 deletions bin/mm-format-ns-pump-history.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
# Author: Ben West
# Maintainer: Scott Leibrand

self=$(basename $0)
function usage ( ) {

cat <<EOT
$self <medtronic-pump-history.json>
$self - Format Medtronic pump-history data into something acceptable to Nightscout.
EOT
}

case "$1" in
--help|-h|help)
usage
exit 0
esac


HISTORY=${1-pumphistory.json}
OUTPUT=${2-/dev/fd/1}
#TZ=${3-$(date +%z)}
Expand Down
14 changes: 14 additions & 0 deletions bin/mm-format-ns-treatments.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ MODEL=${2-model.json}
OUTPUT=${3-/dev/fd/1}
#TZ=${3-$(date +%z)}
self=$(basename $0)
function usage ( ) {

cat <<EOT
$self <pump-history-zoned.json> <model.json>
$self - Format medtronic history data into Nightscout treatments data.
EOT
}

case "$1" in
--help|-h|help)
usage
exit 0
esac


# | json -e "this.type = 'mm://openaps/$self'" \
model=$(json -f $MODEL)
Expand Down
14 changes: 14 additions & 0 deletions bin/mm-format-oref0-glucose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,23 @@
# Maintainer: @tghoward

# Written for decocare v0.0.18. Will need updating the the decocare json format changes.
self=$(basename $0)
HISTORY=${1-glucosehistory.json}
OUTPUT=${2-/dev/fd/1}
#TZ=${3-$(date +%z)}
function usage ( ) {

cat <<EOT
$self <glucose-history.json>
$self - Format medtronic glucose data into oref0 format.
EOT
}

case "$1" in
--help|-h|help)
usage
exit 0
esac

cat $HISTORY | \
json -e "this.medtronic = this._type;" | \
Expand Down
2 changes: 1 addition & 1 deletion bin/mm-stick.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ case $OPERATION in
print_fail $*
exit 1
;;
*|help)
*|help|--help|-h)
print_help
;;
esac
Expand Down
86 changes: 85 additions & 1 deletion bin/nightscout.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,105 @@ function help_message ( ) {
Usage:
$self <cmd>

* latest-openaps-treatment
* cull-latest-openaps-treatments

* get
* upload
* dedupe-treatments
* status
* upload-entries
* autoconfigure-device-crud

EOF
}

function setup_help ( ) {

cat <<EOF
$self autoconfigure-device-crud <NIGHTSCOUT_HOST> <API_SECRET>

sets up:
openaps use ns shell get entries.json 'count=10'
openaps use ns shell upload treatments.json recently/combined-treatments.json
EOF
}

function ns_help ( ) {
cat <<EOF
TODO: improve help
openaps use ns shell get entries.json 'count=10'
openaps use ns shell upload treatments.json recently/combined-treatments.json
EOF
}
case $NAME in
latest-openaps-treatment)
ns-get treatments.json'?find[enteredBy]=/openaps:\/\//&count=1' $* | json 0
;;
ns)
NIGHTSCOUT_HOST=$1
API_SECRET=$2
OP=$3
shift
shift
shift

case $OP in
-h|--help|help)
ns_help
exit 0
;;
get)
exec ns-get host $NIGHTSCOUT_HOST $*
;;
upload)
exec ns-upload $NIGHTSCOUT_HOST $API_SECRET $*
;;
*)
echo "Unknown request:" $OP
ns_help
exit 1;
;;
esac

;;
hash-api-secret)
if [[ -z "$1" ]] ; then
echo "Missing plain Nightscout passphrase".
echo "Usage: $self hash-api-secret 'myverylongsecret'".
exit 1;
fi
API_SECRET=$(echo -n $1 | sha1sum | cut -d ' ' -f 1 | tr -d "\n")
echo $API_SECRET
;;
autoconfigure-device-crud)
NIGHTSCOUT_HOST=$1
PLAIN_NS_SECRET=$2
API_SECRET=$($self hash-api-secret $2)
case $1 in
help|-h|--help)
setup_help
exit 0
;;
esac
# openaps device add ns-get host
test -z "$NIGHTSCOUT_HOST" && setup_help && exit 1;
test -z "$API_SECRET" && setup_help && exit 1;
openaps device add ns process --require "oper remote input" nightscout ns "NIGHTSCOUT_HOST" "API_SECRET"
openaps device show ns --json | json \
| json -e "this.extra.args = this.extra.args.replace(' NIGHTSCOUT_HOST ', ' $NIGHTSCOUT_HOST ')" \
| json -e "this.extra.args = this.extra.args.replace(' API_SECRET', ' $API_SECRET')" \
| openaps import
;;
cull-latest-openaps-treatments)
INPUT=$1
MODEL=$2
LAST_TIME=$3
mm-format-ns-treatments $INPUT $MODEL | json -c "this.created_at > '$LAST_TIME'"
;;
help)
help|--help|-h)
help_message
exit 0
;;
*)
test -n "$COMMAND" && exec $COMMAND $*
Expand Down
2 changes: 1 addition & 1 deletion bin/ns-dedupe-treatments.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ case "$1" in
delete)
main $2 delete_cmd
;;
*|help)
*|help|--help|-h)
usage
exit 1;
;;
Expand Down
4 changes: 3 additions & 1 deletion bin/ns-get.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ EOF
QUERY=${4}
OUTPUT=${5-/dev/fd/1}
REPORT_ENDPOINT=$NIGHTSCOUT_HOST/api/v1/${REPORT}'?'${QUERY}
test -z "$NIGHTSCOUT_HOST" && usage && exit 1;
curl -g -s $REPORT_ENDPOINT | json

;;
type)
Expand All @@ -49,7 +51,7 @@ EOF
--noop)
echo "curl -s $REPORT_ENDPOINT | json"
;;
help)
help|--help|-h)
usage
;;
*)
Expand Down
15 changes: 15 additions & 0 deletions bin/ns-upload-entries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,26 @@
# Author: Ben West
# Maintainer: @cjo20, @scottleibrand

self=$(basename $0)
ENTRIES=${1-entries.json}
NIGHTSCOUT_HOST=${NIGHTSCOUT_HOST-localhost:1337}
#TZ=${3-$(date +%z)}
OUTPUT=${2}

function usage ( ) {
cat <<EOF
$self <entries.json> <http://nightscout.host:1337>
$self - Upload entries (glucose data) to NS.
EOF
}

case "$1" in
-h|--help|help)
usage
exit 0
;;
esac

export ENTRIES API_SECRET NIGHTSCOUT_HOST
# requires API_SECRET and NIGHTSCOUT_HOST to be set in calling environment (i.e. in crontab)
(
Expand Down
6 changes: 6 additions & 0 deletions bin/ns-upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ EOF
fi
# requires API_SECRET and NIGHTSCOUT_HOST to be set in calling environment
# (i.e. in crontab)
if [[ "$ENTRIES" != "-" ]] ; then
if [[ ! -f $ENTRIES ]] ; then
echo "Input file $ENTRIES" does not exist.
exit 1;
fi
fi
(test "$ENTRIES" != "-" && cat $ENTRIES || cat )| (
curl -m 30 -s -X POST --data-binary @- \
-H "API-SECRET: $API_SECRET" \
Expand Down
16 changes: 16 additions & 0 deletions bin/ns-uploader-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ die() {
}

self=$(basename $0)

function usage ( ) {

cat <<EOF
$self <directory> <serial> <??> <diyps_url>
$self - setup uploading to NS?
EOF
}

case "$1" in
--help|help|-h)
usage
exit 0
;;
esac

if [[ $# -lt 2 ]]; then
openaps device show pump 2>/dev/null >/dev/null || die "Usage: $self <directory> <pump serial #>"
fi
Expand Down
10 changes: 9 additions & 1 deletion bin/oref0-calculate-iob.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@
*/

var generate = require('oref0/lib/iob');
function usage ( ) {
console.log('usage: ', process.argv.slice(0, 2), '<pumphistory.json> <profile.json> <clock.json>');

}

if (!module.parent) {
var pumphistory_input = process.argv.slice(2, 3).pop();
if ([null, '--help', '-h', 'help'].indexOf(pumphistory_input) > 0) {
usage( );
process.exit(0)
}
var profile_input = process.argv.slice(3, 4).pop();
var clock_input = process.argv.slice(4, 5).pop();

if (!pumphistory_input || !profile_input) {
console.log('usage: ', process.argv.slice(0, 2), '<pumphistory.json> <profile.json> <clock.json>');
usage( );
process.exit(1);
}

Expand Down
Loading