Skip to content

Commit da7015c

Browse files
carbsReq pushover improvements (#1421)
* comment out shared-node cp to avoid full disk * don't send carbsReq alerts if COB is zero due to clock data parsing error * run pushover in pump-loop * run pushover in pump-loop * check pushover_snooze immediately before sending a pushover * pathfix * run pushover in pump-loop instead of cron-every-minute * don't background pushover for now * uncomment debug line * debugging * debugging * debugging * -e to make jq return non-zero if no snooze found * apparently this line never worked * comment out debug line * no newline * don't print date * remove extra logging * fix check for empty MAKER_KEY * only print snooze message if there's something to snooze * don't print contents of file * update Pushover Glances to include temp basal rate*duration * direction arrows * U/h * use NS to coordinate glances snoozes between rigs * more compact carbsreq string * make glanceDelay configurable * better check of whether pushoverGlances is a number * fix glanceDelay=pushoverGlances if numeric check * wait_for_silence before refreshing profile and pumphistory * fix glanceDelay=pushoverGlances if numeric check * fix carbhistory egrep syntax * ls profile.json.new if invalid * Invalid profile.json.new debugging * Invalid profile.json.new debugging * Invalid profile.json.new debugging * NS uses UTC now * grep -q exits early w/ 141 in some race conditions: use grep >/dev/null instead * remove debug lines * Revert "NS uses UTC now" This reverts commit e9f8810. * convert NS UTC date into local time * don't print * comment out debug lines * don't print snooze.json, just the fact we uploaded one * check that glance api returns status: 1 * don't print snooze.json * just print the fact we sent a carbsReq pushover * don't print meal.json (twice) * less verbose logging after wait_for_silence * don't print * check that pushover api returns status: 1 * spacing * just print COB after refreshing meal.json * less verbose logging * print entirer meal.json, colorized * remove duplicate cat of meal.json * add delta to glance title * print last_glance time inline * display tick instead of delta * tick before arrow * remove quotes * retry w/o new BG after failure to parse clock data * don't use grep -q to avoid return code 141 race condition * don't use grep -q to avoid return code 141 race condition * don't use grep -q to avoid return code 141 race condition * don't mkdir: directory entries eventually fill up the disk
1 parent 5e4ee98 commit da7015c

File tree

7 files changed

+104
-57
lines changed

7 files changed

+104
-57
lines changed

bin/oref0-autosens-loop.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ function completed_recently {
3333
# openaps use detect-sensitivity shell monitor/glucose.json settings/pumphistory-24h-zoned.json settings/insulin_sensitivities.json settings/basal_profile.json settings/profile.json monitor/carbhistory.json settings/temptargets.json
3434
function autosens {
3535
# only run autosens if pumphistory-24h is newer than autosens
36-
if find monitor/ -newer settings/autosens.json | grep -q pumphistory-24h-zoned.json \
37-
|| find settings/ -size -5c | grep -q autosens.json \
38-
|| ! find settings/ | grep -q autosens \
36+
if find monitor/ -newer settings/autosens.json | grep pumphistory-24h-zoned.json \
37+
|| find settings/ -size -5c | grep autosens.json \
38+
|| ! find settings/ | grep autosens \
3939
|| ! find settings/autosens.json >/dev/null; then
40-
if oref0-detect-sensitivity monitor/glucose.json monitor/pumphistory-24h-zoned.json settings/insulin_sensitivities.json settings/basal_profile.json settings/profile.json monitor/carbhistory.json settings/temptargets.json > settings/autosens.json.new && cat settings/autosens.json.new | jq .ratio | grep -q [0-9]; then
40+
if oref0-detect-sensitivity monitor/glucose.json monitor/pumphistory-24h-zoned.json settings/insulin_sensitivities.json settings/basal_profile.json settings/profile.json monitor/carbhistory.json settings/temptargets.json > settings/autosens.json.new && cat settings/autosens.json.new | jq .ratio | grep "[0-9]"; then
4141
mv settings/autosens.json.new settings/autosens.json
4242
echo -n "Autosens refreshed: "
4343
else

bin/oref0-bash-common-functions.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ function wait_for_silence {
542542
echo -n .
543543
# returns true if it hears pump comms, false otherwise
544544
if ! listen -t $waitfor's' 2>&4 ; then
545-
echo "No interfering pump comms detected from other rigs (this is a good thing!)"
545+
echo " All clear."
546546
echo -n "Continuing oref0-pump-loop at "; date
547547
return 0
548548
else

bin/oref0-cron-every-minute.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ if [[ ! -z "$BT_PEB" || ! -z "$BT_MAC" ]]; then
129129
fi
130130

131131
if [[ ! -z "$PUSHOVER_TOKEN" && ! -z "$PUSHOVER_USER" ]]; then
132-
oref0-pushover $PUSHOVER_TOKEN $PUSHOVER_USER 2>&1 >> /var/log/openaps/pushover.log &
132+
#oref0-pushover $PUSHOVER_TOKEN $PUSHOVER_USER 2>&1 >> /var/log/openaps/pushover.log &
133133
fi
134134

135135
# if disk has less than 10MB free, delete something and logrotate

bin/oref0-ns-loop.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ main() {
2525
fi
2626
fi
2727

28-
pushover_snooze
28+
#pushover_snooze
2929
ns_temptargets || die "ns_temptargets failed"
3030
ns_meal_carbs || echo "ns_meal_carbs failed"
3131
battery_status
@@ -73,7 +73,7 @@ function get_ns_bg {
7373
# if ns-glucose.json data is <10m old, no more than 5m in the future, and valid (>38),
7474
# copy cgm/ns-glucose.json over to cgm/glucose.json if it's newer
7575
valid_glucose=$(find_valid_ns_glucose)
76-
if echo $valid_glucose | grep -q glucose; then
76+
if echo $valid_glucose | grep glucose >/dev/null; then
7777
echo Found recent valid BG:
7878
echo $valid_glucose | colorize_json '.[0] | { glucose: .glucose, dateString: .dateString }'
7979
cp -pu cgm/ns-glucose.json cgm/glucose.json
@@ -104,7 +104,7 @@ function find_valid_ns_glucose {
104104
function ns_temptargets {
105105
#openaps report invoke settings/temptargets.json settings/profile.json >/dev/null
106106
nightscout ns $NIGHTSCOUT_HOST $API_SECRET temp_targets > settings/ns-temptargets.json.new
107-
cat settings/ns-temptargets.json.new | jq .[0].duration | egrep -q [0-9] && mv settings/ns-temptargets.json.new settings/ns-temptargets.json
107+
cat settings/ns-temptargets.json.new | jq .[0].duration | egrep "[0-9]" >/dev/null && mv settings/ns-temptargets.json.new settings/ns-temptargets.json
108108
# TODO: merge local-temptargets.json with ns-temptargets.json
109109
#openaps report invoke settings/ns-temptargets.json settings/profile.json
110110
echo -n "Latest NS temptargets: "
@@ -119,11 +119,11 @@ function ns_temptargets {
119119

120120
dir_name=~/test_data/oref0-get-profile$(date +"%Y-%m-%d-%H%M")-ns
121121
#echo dir_name = $dir_name
122-
mkdir -p $dir_name
122+
# mkdir -p $dir_name
123123
#cp settings/settings.json settings/bg_targets.json settings/insulin_sensitivities.json settings/basal_profile.json preferences.json settings/carb_ratios.json settings/temptargets.json settings/model.json settings/autotune.json $dir_name
124124

125125
run_remote_command 'oref0-get-profile settings/settings.json settings/bg_targets.json settings/insulin_sensitivities.json settings/basal_profile.json preferences.json settings/carb_ratios.json settings/temptargets.json --model=settings/model.json --autotune settings/autotune.json' | jq . > settings/profile.json.new || die "Couldn't refresh profile"
126-
if cat settings/profile.json.new | jq . | grep -q basal; then
126+
if cat settings/profile.json.new | jq . | grep basal > /dev/null; then
127127
mv settings/profile.json.new settings/profile.json
128128
else
129129
die "Invalid profile.json.new after refresh"
@@ -134,11 +134,11 @@ function ns_temptargets {
134134
function ns_meal_carbs {
135135
#openaps report invoke monitor/carbhistory.json >/dev/null
136136
nightscout ns $NIGHTSCOUT_HOST $API_SECRET carb_history > monitor/carbhistory.json.new
137-
cat monitor/carbhistory.json.new | jq .[0].carbs | egrep -q [0-9] && mv monitor/carbhistory.json.new monitor/carbhistory.json
137+
cat monitor/carbhistory.json.new | jq .[0].carbs | egrep "[0-9]" >/dev/null && mv monitor/carbhistory.json.new monitor/carbhistory.json
138138

139139
dir_name=~/test_data/oref0-meal$(date +"%Y-%m-%d-%H%M")
140140
#echo dir_name = $dir_name
141-
mkdir -p $dir_name
141+
# mkdir -p $dir_name
142142
#cp monitor/pumphistory-24h-zoned.json settings/profile.json monitor/clock-zoned.json monitor/glucose.json settings/basal_profile.json monitor/carbhistory.json $dir_name
143143

144144

@@ -191,7 +191,7 @@ function upload {
191191
function upload_ns_status {
192192
set -o pipefail
193193
#echo Uploading devicestatus
194-
grep -q iob monitor/iob.json || die "IOB not found"
194+
grep iob monitor/iob.json >/dev/null || die "IOB not found"
195195
# set the timestamp on enact/suggested.json to match the deliverAt time
196196
touch -d $(cat enact/suggested.json | jq .deliverAt | sed 's/"//g') enact/suggested.json
197197
if ! file_is_recent_and_min_size enact/suggested.json 10; then
@@ -200,12 +200,12 @@ function upload_ns_status {
200200
return 1
201201
fi
202202
ns_status_file_name=ns-status$(date +"%Y-%m-%d-%T").json
203-
format_ns_status $ns_status_file_name && grep -q iob upload/$ns_status_file_name || die "Couldn't generate ns-status.json"
203+
format_ns_status $ns_status_file_name && grep iob upload/$ns_status_file_name >/dev/null || die "Couldn't generate ns-status.json"
204204
# Delete files older than 24 hours.
205205
find upload -maxdepth 1 -mmin +1440 -type f -name "ns-status*.json" -delete
206206
# Upload the files one by one according to their order.
207207
ls upload/ns-status*.json | while read -r file_name ; do
208-
if ! grep -q iob $file_name ; then
208+
if ! grep iob $file_name >/dev/null ; then
209209
#echo deleteing file $file_name
210210
rm $file_name
211211
continue
@@ -239,7 +239,7 @@ function upload_recent_treatments {
239239
}
240240

241241
function latest_ns_treatment_time {
242-
nightscout latest-openaps-treatment $NIGHTSCOUT_HOST $API_SECRET | jq -r .created_at
242+
date -Is -d $(nightscout latest-openaps-treatment $NIGHTSCOUT_HOST $API_SECRET | jq -r .created_at)
243243
}
244244

245245
#nightscout cull-latest-openaps-treatments monitor/pumphistory-zoned.json settings/model.json $(openaps latest-ns-treatment-time) > upload/latest-treatments.json

bin/oref0-pump-loop.sh

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,17 @@ main() {
6868
fi
6969
fi
7070
touch /tmp/pump_loop_completed -r /tmp/pump_loop_enacted
71+
# run pushover immediately after completing loop for more timely carbsReq notifications without race conditions
72+
PUSHOVER_TOKEN="$(get_pref_string .pushover_token "")"
73+
PUSHOVER_USER="$(get_pref_string .pushover_user "")"
74+
if [[ ! -z "$PUSHOVER_TOKEN" && ! -z "$PUSHOVER_USER" ]]; then
75+
oref0-pushover $PUSHOVER_TOKEN $PUSHOVER_USER # 2>&1 >> /var/log/openaps/pushover.log &
76+
fi
77+
7178
# before each of these (optional) refresh checks, make sure we don't have fresh glucose data
7279
# if we do, then skip the optional checks to finish up this loop and start the next one
7380
if ! glucose-fresh; then
81+
wait_for_silence $upto10s
7482
if onbattery; then
7583
refresh_profile 30
7684
else
@@ -317,7 +325,7 @@ function smb_suggest {
317325
}
318326
319327
function determine_basal {
320-
cat monitor/meal.json
328+
#cat monitor/meal.json
321329
322330
update_glucose_noise
323331
@@ -480,7 +488,7 @@ function refresh_after_bolus_or_enact {
480488
481489
function unsuspend_if_no_temp {
482490
# If temp basal duration is zero, unsuspend pump
483-
if (cat monitor/temp_basal.json | jq '. | select(.duration == 0)' | grep -q duration); then
491+
if (cat monitor/temp_basal.json | jq '. | select(.duration == 0)' | grep duration); then
484492
if check_pref_bool .unsuspend_if_no_temp false; then
485493
echo Temp basal has ended: unsuspending pump
486494
mdt resume 2>&3
@@ -600,15 +608,15 @@ function refresh_pumphistory_and_meal {
600608
601609
dir_name=~/test_data/oref0-meal$(date +"%Y-%m-%d-%H%M")
602610
#echo dir_name = $dir_name
603-
mkdir -p $dir_name
611+
# mkdir -p $dir_name
604612
#cp monitor/pumphistory-24h-zoned.json settings/profile.json monitor/clock-zoned.json monitor/glucose.json settings/basal_profile.json monitor/carbhistory.json $dir_name
605613
if ! retry_return run_remote_command 'oref0-meal monitor/pumphistory-24h-zoned.json settings/profile.json monitor/clock-zoned.json monitor/glucose.json settings/basal_profile.json monitor/carbhistory.json' > monitor/meal.json.new ; then
606614
echo; echo "Couldn't calculate COB"
607615
return 1
608616
fi
609617
try_return check_cp_meal || return 1
610618
echo -n "refreshed: "
611-
cat monitor/meal.json
619+
cat monitor/meal.json | jq -cC .
612620
}
613621
614622
function check_cp_meal {
@@ -631,7 +639,7 @@ function check_cp_meal {
631639
function calculate_iob {
632640
dir_name=~/test_data/oref0-calculate-iob$(date +"%Y-%m-%d-%H%M")
633641
#echo dir_name = $dir_name
634-
mkdir -p $dir_name
642+
# mkdir -p $dir_name
635643
#cp monitor/pumphistory-24h-zoned.json settings/profile.json monitor/clock-zoned.json settings/autosens.json $dir_name
636644
637645
run_remote_command 'oref0-calculate-iob monitor/pumphistory-24h-zoned.json settings/profile.json monitor/clock-zoned.json settings/autosens.json' > monitor/iob.json.new || { echo; echo "Couldn't calculate IOB"; fail "$@"; }
@@ -687,7 +695,7 @@ function get_settings {
687695

688696
#dir_name=~/test_data/oref0-get-profile$(date +"%Y-%m-%d-%H%M")-pump
689697
#echo dir_name = $dir_name
690-
mkdir -p $dir_name
698+
# mkdir -p $dir_name
691699
#cp settings/settings.json settings/bg_targets.json settings/insulin_sensitivities.json settings/basal_profile.json preferences.json settings/carb_ratios.json settings/temptargets.json settings/model.json $dir_name
692700

693701
run_remote_command 'oref0-get-profile settings/settings.json settings/bg_targets.json settings/insulin_sensitivities.json settings/basal_profile.json preferences.json settings/carb_ratios.json settings/temptargets.json --model=settings/model.json' 2>&3 | jq . > settings/pumpprofile.json.new || { echo "Couldn't refresh pumpprofile"; fail "$@"; }
@@ -701,7 +709,7 @@ function get_settings {
701709
# generate settings/profile.json.new with autotune
702710
dir_name=~/test_data/oref0-get-profile$(date +"%Y-%m-%d-%H%M")-pump-auto
703711
#echo dir_name = $dir_name
704-
mkdir -p $dir_name
712+
# mkdir -p $dir_name
705713
#cp settings/settings.json settings/bg_targets.json settings/insulin_sensitivities.json settings/basal_profile.json preferences.json settings/carb_ratios.json settings/temptargets.json settings/model.json settings/autotune.json $dir_name
706714

707715
run_remote_command 'oref0-get-profile settings/settings.json settings/bg_targets.json settings/insulin_sensitivities.json settings/basal_profile.json preferences.json settings/carb_ratios.json settings/temptargets.json --model=settings/model.json --autotune settings/autotune.json' | jq . > settings/profile.json.new || { echo "Couldn't refresh profile"; fail "$@"; }
@@ -736,7 +744,7 @@ function onbattery {
736744
function wait_for_bg {
737745
if [ "$(get_pref_string .cgm '')" == "mdt" ]; then
738746
echo "MDT CGM configured; not waiting"
739-
elif egrep -q "Warning:" enact/smb-suggested.json 2>&3; then
747+
elif egrep -q "Warning:" enact/smb-suggested.json 2>&3 || egrep -q "Could not parse clock data" monitor/meal.json 2>&3; then
740748
echo "Retrying without waiting for new BG"
741749
elif egrep -q "Waiting [0](\.[0-9])?m ([0-6]?[0-9]s )?to microbolus again." enact/smb-suggested.json 2>&3; then
742750
echo "Retrying microbolus without waiting for new BG"

bin/oref0-pushover.sh

Lines changed: 68 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,38 @@ else
7676
PRIORITY_OPTIONS=""
7777
fi
7878

79-
date
79+
#date
8080

81-
if file_is_recent monitor/pushover-sent $SNOOZE; then
82-
echo "Last pushover sent less than $SNOOZE minutes ago."
83-
elif ! file_is_recent "$FILE"; then
81+
#function pushover_snooze {
82+
# check Nightscout to see if another rig has already sent a carbsReq pushover recently
83+
URL=$NIGHTSCOUT_HOST/api/v1/devicestatus.json?count=100
84+
if [[ "${API_SECRET}" =~ "token=" ]]; then
85+
URL="${URL}&${API_SECRET}"
86+
else
87+
CURL_AUTH='-H api-secret:'${API_SECRET}
88+
fi
89+
90+
if snooze=$(curl -s ${CURL_AUTH} ${URL} | jq '.[] | select(.snooze=="carbsReq") | select(.date>'$(date +%s -d "10 minutes ago")')' | jq -s .[0].date | noquotes | grep -v null); then
91+
#echo $snooze
92+
#echo date -Is -d @$snooze; echo
93+
touch -d $(date -Is -d @$snooze) monitor/pushover-sent
94+
#ls -la monitor/pushover-sent | awk '{print $8,$9}'
95+
fi
96+
#}
97+
98+
if ! file_is_recent "$FILE"; then
8499
echo "$FILE more than 5 minutes old"
85100
exit
86-
elif ! cat $FILE | egrep "add'l|maxBolus"; then
87-
echo "No additional carbs or bolus required."
88-
elif [[ $ONLYFOR =~ "carb" ]] && ! cat $FILE | egrep "add'l"; then
89-
echo "No additional carbs required."
90-
elif [[ $ONLYFOR =~ "insulin" ]] && ! cat $FILE | egrep "maxBolus"; then
91-
echo "No additional insulin required."
101+
elif ! cat $FILE | egrep "add'l|maxBolus" > /dev/null; then
102+
echo -n "No carbsReq. "
103+
elif [[ $ONLYFOR =~ "carb" ]] && ! cat $FILE | egrep "add'l" > /dev/null; then
104+
echo -n "No carbsReq. "
105+
elif [[ $ONLYFOR =~ "insulin" ]] && ! cat $FILE | egrep "maxBolus" > /dev/null; then
106+
echo -n "No additional insulin required. "
107+
elif file_is_recent monitor/pushover-sent $SNOOZE; then
108+
echo -n "Last pushover sent less than $SNOOZE minutes ago. "
92109
else
93-
curl -s -F token=$TOKEN -F user=$USER $SOUND_OPTION -F priority=$PRIORITY $PRIORITY_OPTIONS -F "message=$(jq -c "{bg, tick, carbsReq, insulinReq, reason}|del(.[] | nulls)" $FILE) - $(hostname)" https://api.pushover.net/1/messages.json && touch monitor/pushover-sent && echo '{"date":'$(epochtime_now)',"device":"openaps://'$(hostname)'","snooze":"carbsReq"}' | tee /tmp/snooze.json && ns-upload $NIGHTSCOUT_HOST $API_SECRET devicestatus.json /tmp/snooze.json
110+
curl -s -F token=$TOKEN -F user=$USER $SOUND_OPTION -F priority=$PRIORITY $PRIORITY_OPTIONS -F "message=$(jq -c "{bg, tick, carbsReq, insulinReq, reason}|del(.[] | nulls)" $FILE) - $(hostname)" https://api.pushover.net/1/messages.json | jq .status| grep 1 >/dev/null && touch monitor/pushover-sent && echo '{"date":'$(epochtime_now)',"device":"openaps://'$(hostname)'","snooze":"carbsReq"}' > /tmp/snooze.json && ns-upload $NIGHTSCOUT_HOST $API_SECRET devicestatus.json /tmp/snooze.json >/dev/null && echo "carbsReq pushover sent."
94111
echo
95112
fi
96113

@@ -106,6 +123,8 @@ source $HOME/.bash_profile
106123
key=${MAKER_KEY:-"null"}
107124
carbsReq=`jq .carbsReq ${FILE}`
108125
tick=`jq .tick ${FILE}`
126+
tick="${tick%\"}"
127+
tick="${tick#\"}"
109128
bgNow=`jq .bg ${FILE}`
110129
delta=`echo "${tick}" | tr -d +`
111130
delta="${delta%\"}"
@@ -119,50 +138,68 @@ pushoverGlances=$(get_prefs_json | jq -M '.pushoverGlances')
119138
if [ "${pushoverGlances}" == "null" -o "${pushoverGlances}" == "false" ]; then
120139
echo "pushoverGlances not enabled in preferences.json"
121140
else
141+
# if pushoverGlances is a number instead of just true, use it to set the minutes allowed between glances
142+
re='^[0-9]+$'
143+
if [[ ${pushoverGlances} =~ $re ]]; then
144+
glanceDelay=${pushoverGlances}
145+
else
146+
glanceDelay=10
147+
fi
122148
GLANCES="monitor/last_glance"
123149
GLUCOSE="monitor/glucose.json"
124150
if [ ! -f $GLANCES ]; then
125-
# First time through it will get created older than 10 minutes so it'll fire
126-
touch $GLANCES && touch -r $GLANCES -d '-11 mins' $GLANCES
151+
# First time through it will get created 1h old so it'll fire
152+
touch $GLANCES && touch -r $GLANCES -d '-60 mins' $GLANCES
153+
fi
154+
155+
if snooze=$(curl -s ${CURL_AUTH} ${URL} | jq '.[] | select(.snooze=="glance") | select(.date>'$(date +%s -d "$glanceDelay minutes ago")')' | jq -s .[0].date | noquotes | grep -v null); then
156+
#echo $snooze
157+
#echo date -Is -d @$snooze; echo
158+
touch -d $(date -Is -d @$snooze) $GLANCES
159+
#ls -la $GLANCES | awk '{print $8,$9}'
127160
fi
128161

129-
if test `find $GLANCES -mmin +10`
162+
if test `find $GLANCES -mmin +$glanceDelay` || cat $FILE | egrep "add'l" >/dev/null
130163
then
131-
enactTime=$(ls -l --time-style=+"%l:%M" ${FILE} | awk '{printf ($6)}')
132-
164+
curTime=$(ls -l --time-style=+"%l:%M" ${FILE} | awk '{printf ($6)}')
165+
133166
lastDirection=`jq -M '.[0] .direction' $GLUCOSE`
134167
lastDirection="${lastDirection%\"}"
135168
lastDirection="${lastDirection#\"}"
136169

170+
rate=`jq -M '.rate' monitor/temp_basal.json`
171+
duration=`jq -M '.duration' monitor/temp_basal.json`
137172
#echo lastDirection=$lastDirection
138173

139174
if [ "${lastDirection}" == "SingleUp" ]; then
140-
direction="+"
175+
direction=""
141176
elif [ "${lastDirection}" == "FortyFiveUp" ]; then
142-
direction="++"
177+
direction=""
143178
elif [ "${lastDirection}" == "DoubleUp" ]; then
144-
direction="+++"
179+
direction="↑↑"
145180
elif [ "${lastDirection}" == "SingleDown" ]; then
146-
direction="-"
181+
direction=""
147182
elif [ "${lastDirection}" == "FortyFiveDown" ]; then
148-
direction="--"
183+
direction=""
149184
elif [ "${lastDirection}" == "DoubleDown" ]; then
150-
direction="---"
185+
direction="↓↓"
151186
else
152-
direction="" # default for NONE or Flat
187+
direction="" # default for NONE or Flat
153188
fi
154189

155-
if [ test cat $FILE | egrep "add'l" ]; then
156-
subtext="cr ${carbsReq}g"
157-
else
158-
subtext="e${enactTime}"
190+
title="${bgNow} ${tick} ${direction} @ ${curTime}"
191+
text="IOB ${iob}, COB ${cob}"
192+
if cat $FILE | egrep "add'l" >/dev/null; then
193+
carbsMsg="${carbsReq}g req "
159194
fi
160-
text="${bgNow}${direction}"
161-
title="cob ${cob}, iob ${iob}"
195+
subtext="$carbsMsg${rate}U/h ${duration}m"
162196

163197
# echo "pushover glance text=${text} subtext=${subtext} delta=${delta} title=${title} battery percent=${battery}"
164-
curl -s -F "token=$TOKEN" -F "user=$USER" -F "text=${text}" -F "subtext=${subtext}" -F "count=$bgNow" -F "percent=${battery}" -F "title=${title}" https://api.pushover.net/1/glances.json
198+
curl -s -F "token=$TOKEN" -F "user=$USER" -F "text=${text}" -F "subtext=${subtext}" -F "count=$bgNow" -F "percent=${battery}" -F "title=${title}" https://api.pushover.net/1/glances.json | jq .status| grep 1 >/dev/null && echo '{"date":'$(epochtime_now)',"device":"openaps://'$(hostname)'","snooze":"glance"}' > /tmp/snooze.json && ns-upload $NIGHTSCOUT_HOST $API_SECRET devicestatus.json /tmp/snooze.json >/dev/null && echo "Glance uploaded and snoozed"
165199
touch $GLANCES
200+
else
201+
echo -n "Pushover glance last updated less than $glanceDelay minutes ago @ "
202+
ls -la $GLANCES | awk '{print $8}'
166203
fi
167204
fi
168205

@@ -174,7 +211,7 @@ fi
174211
# call with this event that will read out in human language the additional carbs and other
175212
# vital facts. It will leave a voice mail if not answered.
176213

177-
if [[ "$MAKER_KEY" != "null" ]] && cat $FILE | egrep "add'l"; then
214+
if ! [ -z "$MAKER_KEY" ] && [[ "$MAKER_KEY" != "null" ]] && cat $FILE | egrep "add'l"; then
178215
if file_is_recent monitor/ifttt-sent 60; then
179216
echo "carbsReq=${carbsReq} but last IFTTT event sent less than 60 minutes ago."
180217
else

0 commit comments

Comments
 (0)