Skip to content

Instantly share code, notes, and snippets.

@scottleibrand
Created January 10, 2015 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottleibrand/37234e6c643aa5d68b5e to your computer and use it in GitHub Desktop.
Save scottleibrand/37234e6c643aa5d68b5e to your computer and use it in GitHub Desktop.
closedloop.live.sh
#!/bin/bash
/home/pi/bin/mm-uploader.live.sh >> /var/log/uploader.log
curl -sk https://<hostname>/closedloop.php
# if it's been more than 5 minutes, unlock the CarelinkUSB
#find /tmp/carelink.lock -mmin +5 -exec rm -f {} \; 2>/dev/null >/dev/null
# only one process can talk to the pump at a time
ls /tmp/carelink.lock >/dev/null 2>/dev/null && echo "Carelink locked: exiting" && exit
if /usr/bin/curl -sk https://<hostname>/closedloop.txt | /bin/grep set; then
echo "No lockfile: continuing"
touch /tmp/carelink.lock
export SERIAL=<snip>
/usr/bin/curl -sk https://<hostname>/closedloop.txt | while read line; do echo "/usr/local/bin/mm-temp-basals.py $line" | bash; done
rm /tmp/carelink.lock
/home/pi/bin/mm-uploader.live.short.sh >> /var/log/uploader.log
fi
# if there are still any mm-* processes running, kill them off and remove the lock
/bin/ps aux | /bin/grep mm-.* | /bin/grep -v grep | /usr/bin/awk '{print $2}' | while read line; do /bin/kill $line; done
rm /tmp/carelink.lock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment