forked from pazaan/decoding-contour-next-link
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pi640g.sh
executable file
·150 lines (121 loc) · 4.31 KB
/
pi640g.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#! /bin/bash
# Initialising Carelink Automation
# Proof of concept ONLY - 640g csv to NightScout
#
echo '*****************************'
echo '*** CHIP640G ***'
echo '*** FOR TEST PURPOSES ONLY***'
echo '*Only Use If You Accept This*'
echo '* Started 5th May 2016 *'
echo '*** Thanks - @LittleDMatt ***'
echo '*****************************'
VERSION='V0.12 10th May 2016'
echo $VERSION
echo
echo "Indebted to Lennart Goerdhart for https://github.com/pazaan/decoding-contour-next-link"
echo "Please use with caution. There'll be bugs here..."
echo "You run this at your own risk."
echo "Thank you."
echo '*****************************'
echo ' Known Issues TO (TRY TO) FIX'
echo '*****************************'
echo 'Tons - this is thrown together...'
echo '*****************************'
echo Setting Varables...
source pi_config.sh
# Capture empty JSON files later ie "[]"
EMPTYSIZE=3 #bytes
# ****************************************************************************************
# Let's go...
# ****************************************************************************************
# Uploader setup
#START_TIME=0 #last time we ran the uploader (if at all)
# Check if we're probably running as cron job
#uptime1=$(</proc/uptime)
#uptime1=${uptime%%.*}
# Allow to run for ~240 hours (roughly), ~5 min intervals
# This thing is bound to need some TLC and don't want it running indefinitely...
#COUNT=0
#MAXCNT=2880
#until [ $COUNT -gt $MAXCNT ]; do
# Set up value file
touch latest_sg.json
#Check time to avoid overlap with pump and transmitter communication
M=$(date +%M)
echo $M > t.txt
sed -i '1s/^.\(.*\)/\1/' t.txt
time=$(<t.txt)
if [ $time -eq 1 ] || [ $time -eq 6 ] || [ $time -eq 2 ] || [ $time -eq 7 ]; then
echo Waiting
sleep 90
else
echo Running
sleep 5
sudo python read_minimed_next24.py
sleep 10
sudo python read_minimed_next24.py
fi
# Time to extract and upload entries (SG only)
filesize=0
if [ -s latest_sg.json ]
then
filesize=$(stat -c%s latest_sg.json)
fi
if [ $filesize -gt $EMPTYSIZE ]
then
# sed -i '1s/^/[{/' latest_sg.json
# echo '}]' >> latest_sg.json
# more latest_sg.json
sed -i '1s/^/{/' latest_sg.json
echo '}' >> latest_sg.json
more latest_sg.json
fi
# Write data to local file for offline use ensuring that the glucose level has been updated
./line_add.sh
echo "line add complete"
./comma_check.sh
echo "comma check complete"
# cp sg_monitor.json /home/pi/timsaps/monitor/glucose.json
cp sg_monitor.json /home/pi/myopenaps/monitor/glucose.json
echo "file copied"
curl -s -X POST --header "Content-Type: application/json" --header "Accept: application/json" --header "api-secret:"$api_secret_hash --data-binary @latest_sg.json "$your_nightscout"$"/api/v1/entries"
cp latest_sg.json old_data/latest.json
cp latest_sg_prev.json old_data/latest_sg_prev.json
cp latest_sg.json latest_sg_prev.json
rm latest_sg.json
echo "file removed"
#echo
# And now basal info
# filesize=$(wc -c <latest_basal.json)
#filesize=0
#if [ -s latest_basal.json ]
#then
# filesize=$(stat -c%s latest_basal.json)
#fi
#if [ $filesize -gt $EMPTYSIZE ]
#then
# sed -i '1s/^/[{/' latest_basal.json
# echo '}]' >> latest_basal.json
# more latest_basal.json
# curl -s -X POST --header "Content-Type: application/json" --header "Accept: application/json" --header "api-secret:"$api_secret_hash --data-binary @latest_basal.json "$your_nightscout"$"/api/v1/treatments"
#fi
#echo
#echo "Checking for Bayer..."
#lsusb > /home/pi/decoding-contour-next-link/lsusb.log
#grep 'Bayer' /home/pi/decoding-contour-next-link/lsusb.log > /home/pi/decoding-contour-next-link/usb.log
# Bayer will be listed - "Bayer Health Care LLC"
# Action (if required): reboot (ffs, got to be a better way :o )
#if [ ! -s /home/pi/decoding-contour-next-link/usb.log ]
#then
# echo 'Announcement - USB Loss'
# echo '{"enteredBy": "Uploader", "eventType": "Announcement", "reason": "", "notes": "Cycle Bayer Power", "created_at": "'$(date +"%Y-%m-%dT%H:%M:%S.000%z")$'", " isAnnouncement": true }' > announcement.json
# curl -s -X POST --header "Content-Type: application/json" --header "Accept: application/json" --header "api-secret:"$api_secret_hash --data-binary @announcement.json "$your_nightscout"$"/api/v1/treatments"
#/sbin/shutdown -r +1
#fi
#echo "Waiting..."
#sleep $gap_seconds
#rm -f latest_sg.json
#rm -f latest_basal.json
#let COUNT=COUNT+1
#echo $COUNT
# done