There are a number of ways to have an “offline” OpenAPS rig, and numerous ways to monitor offline.
Medtronic CGM users can, by default, automatically loop offline because the rig will read CGM data directly from the pump.
Dexcom CGM users have a few different alternatives to retrieve blood glucose values locally for offline use.
- 1.) Use xDrip. See: http://stephenblackwasalreadytaken.github.io/xDrip/
- 2.) Plug the CGM receiver directly into your rig via USB.
- Explorer Boards that shipped at or after the end of February 2017/first week of March 2017 should enable users to simply plug in the CGM receiver to the OTG port, and a USB battery into the UART port, in order to run offline and pull BGs from the receiver.
- Explorer boards built prior to late January of 2017 are not always working well/automatically with a CGM receiver plugged in. This can be fixed with a single trace cut, but doing so will break the ability to re-flash your Edison. Please make sure you have a second Explorer board or another base block or breakout board that you can use to re-flash the Edison if needed before considering this modification. For more details, see this issue, and if you decide to make the cut, see this document for details on how to cut the copper trace from pin 61 of the 70 pin connector. Cut in two places and dig out the copper between. Cut by poking a razor point in. Avoid the narrow trace above the one being cut.
- See Pancreabble instructions below for connecting your rig to your watch
- See xDrip instructions below for seeing offline loop status
- See HotButton instructions below for setting temp targets and controlling your rig offline via an Android
Note about recovery from Camping Mode/Offline mode for Medtronic CGM users:¶
If you have been running offline for a significant amount of time, and use a Medtronic CGM, you may need to run
from inside your openAPS directory, before your loop will start updating correctly to your nightscout site.
(TO DO Note - Pancreabble instructions for OpenAPS need to be re-worked to reflect the oref0-setup script way of making it work. Below is notes about Pancreabble setup prior to oref0-setup.sh being in existence.)
Pancreabble is a way to monitor your loop locally, by pairing a Pebble smartwatch directly with the Raspberry Pi or Intel Edison.
In other words, whereas the default setup looks like this:
Raspberry Pi/Intel Edison -> network -> Nightscout server -> network -> smartphone | -> laptop | -> Pebble watch
And by default, your Pebble is paired thus:
smartphone -> Bluetooth -> Pebble watch
With Pancreabble, the setup looks like this:
Raspberry Pi/Intel Edison -> Bluetooth -> Pebble watch
Using a Pebble watch can be especially helpful during the “open loop” phase: you can send the loop’s recommendations directly to your wrist, making it easy to evaluate the decisions it would make in different contexts during the day (before/after eating, when active, etc.).
See Pancreabble for initial setup instructions.
Once you’ve done the first stages above, you’ll need to do generate a status file that can be passed over to the Pebble Urchin watch face. Fortunately, the core of this is available in oref0.
~src/oref0/bin and look for
peb-urchin-status.sh. This gives you the basic framework to generate output files that can be used with Pancreabble. To use it, you’ll need to install jq using:
apt-get install jq
If you get errors, you may need to run
apt-get update ahead of attempting to install jq.
Once jq is installed, the shell script runs and produces the
urchin-status.json file which is needed to update the status on the pebble. It can be incorporated into an alias that regularly updates the pebble. You can modify it to produce messages that you want to see there.
When installing the oref0-setup you will need to replace all instances of AA:BB:CC:DD:EE:FF with the Pebble MAC address. This can be found in Settings/System/Information/BT Address.
Once you’ve installed, you will need to pair the watch to your Edison.
- Restart the Bluetooth daemon to start up the bluetooth services. (This is normally done automatically by oref0-online once everything is set up, but we want to do things manually this first time):
sudo killall bluetoothd
- Wait a few seconds, and run it again, until you get
bluetoothd: no process foundreturned. Then start it back up again:
sudo /usr/local/bin/bluetoothd --experimental &
- Wait at least 10 seconds, and then run:
sudo hciconfig hci0 name $HOSTNAME
- If you get a
Can't change local name on hci0: Network is down (100)error, start over with
killalland wait longer between steps.
- Now launch the Bluetooth control program:
- And run:
- and each of the following:
discoverable on scan on agent on default-agent
Settings/BLUETOOTH to make sure Pebble is in pairing mode
you might need to do this several times before it pairs
you will see on the edison
Request confirmation [agent] Confirm passkey 123456 (yes/no): yes
- (WARNING: You must type in yes not just y to pair)
Once paired, type quit to exit.
peb-urchin-status.sh has 1 notification and 3 different options for urchin messages.
in you APS directory there is a file called ‘pancreoptions.json’
"urchin_loop_on": true, <--- to turn on or off urchin watchface update "urchin_loop_status": false, <--- Gives a message on urchin watchface that it's running "urchin_iob": true, <--- Gives a message on urchin watchface of current IOB "urchin_temp_rate": false, <--- Gives a message on urchin watchface of current temp basal "notify_temp_basal": false <--- Notificaiton of temp basal when one shows up in enact/suggested.json
note only one of the messages for the urchin watchface can be true at once
peb-urchin-status.sh gets called from the crontab and will run automatically.
By default the urchin_loop_on, and urchin_iob is set to true. You must manually change notify_temp_basal to true to start getting temp basal notifications.
you can edit this file using
nano pancreoptions.json from your APS directory.
xDripAPS for offline BGs¶
Note as of 1/26/17: The below documentation is WIP and needs additional testing.
Do you use OpenAPS and the xDrip Android App? Until now this required an internet connection to upload your xDrip Android App CGM data to an online Nightscout instance (the OpenAPS community recommends utilizing Heroku). Then your data was downloaded to your OpenAPS rig for use in your online loop. The xDripAPS code resides on your OpenAPS rig and allows the direct transfer of xDrip Android App CGM data to your OpenAPS rig without an internet connection. xDripAPS creates an offline OpenAPS rig which utilizes a “local” or “personal” network (WiFi hotspot or Bluetooth tethering) for direct communication between the xDrip Android device and the OpenAPS rig. Data which is ‘missing’ from Nightscout will be uploaded when the OpenAPS rig regains internet connectivity.
The OpenAPS community recommends an Explorer Board / Intel Edison rig, but xDripAPS also works with a Raspberry Pi rig.
Configuring an offline OpenAPS rig is quite easy because the OpenAPS setup script (oref0-setup.sh v0.4.0 and later) supports an automated installation of xDripAPS and dependencies. When running the OpenAPS setup script you simply specify “xdrip” (without the quotes) when promped to specify a CGM type (e.g. MDT, G4). Alternatively, manual installation instructions can be found at the bottom of this page.
Overview of xDripAPS¶
With xDripAPS, the flow of data is as follows -
(1) CGM transmitter –> (2) xDrip/xDrip+ Android app –> (3) OpenAPS rig (e.g. Edison) –> (4) Nightscout
- Usually a Dexcom G5, or G4 plus xDrip wireless bridge.
- Either xDrip or xDrip+ can be used. In the app, the REST API Upload feature is normally used to upload CGM data to Nightscout. Instead, we use this feature to upload to xDripAPS on your OpenAPS rig (further details below).
- Your OpenAPS rig - usually a Raspberry Pi or an Intel Edison.
- The xDrip app is now uploading your data to xDripAPS on your OpenAPS rig rather than to Nightscout. OpenAPS will now upload your CGM data to Nightscout as well as treatments, pump status, etc. So your Nightscout site will still be updated. Note that it will take a couple of minutes longer for CGM data to reach Nightscout, compared with when uploading directly from xDrip.
Setup Steps (using oref0-setup.sh script)¶
Setting up your OpenAPS rig¶
Install OpenAPS as per the documentation. While running the oref0-setup script you will be prompted to specify a CGM source. Enter “xdrip” (without the quotes). The setup script takes care of the rest! Follow the remainder of the setup script as normal.
Connect your Android phone and your OpenAPS rig¶
For the xDrip app on your Android phone to be able to send CGM data to xDripAPS on your OpenAPS rig, they need to be connected to the same “personal” network. Note that an internet connection is not required - this solution allows you to loop without internet connectivity.
There are two approaches for establishing a “personal” network between your phone and your OpenAPS rig. The first is to run a WiFi hotspot on your phone and connect your OpenAPS rig to the WiFi network your phone exposes. This is the easiest option, but there are two drawbacks - it drains your phone battery quickly, and your phone cannot connect to a normal WiFi network while the WiFi hotspot is enabled (it can connect to the internet via 3G/4G when coverage is available).
The other option is to enable bluetooth tethering on your phone and have your OpenAPS rig connect to it. This does not drain the phone’s battery as quickly and means that the phone can still connect to a normal WiFi network for internet access when available (and to 3G/4G networks when WiFi is not available). I use this approach 24/7 - my OpenAPS rig is permanently tethered to my Nexus 6P phone. I can get a full day of phone usage without running out of battery, unless I make a lot of calls or have a lot of screen-on time.
Instructions on both approaches can be found in the main OpenAPS documentation.
Configuring the xDrip Android app¶
First, determine your OpenAPS rig’s IP address within your “personal” network. If you can open a terminal session to your rig via serial, then
ifconfig wlan0 (when using the WiFi hostpost option) or
ifconfig bnep0 (when using bluetooth tethering) will display your IP address. Alternatively, you can use an Android app - there are lots of “Network IP Scanner” apps in the Play store. The Hurricane Electric Network Tools app works with both the WiFi hotspot and BT tethering options.
Then, open xDrip or xDrip+ settings and in the REST API Upload setting, configure the following URL -
A few notes to clarify: - enter “http://” NOT “https:// - <nightscout_api_secret> is the plain-text API secret used when creating your online Nightscout instance. - <rig_ip_address> is the IP address of your OpenAPS rig assigned by your WiFi hotspot or Bluetooth tether connection. It will take the form of: 192.168.xxx.xx
If using xDrip+ navigate to Settings > Cloud Upload > MongoDB and uncheck the “Skip LAN uploads” option. Do not turn on the “Enable Nightscout Mongo DB sync” option. If you don’t have these options, update to a recent version of the xDrip+ app. (This option was added to a nightly build around December 2016).
Manual installation steps¶
N.B. It is recommended that you use the oref0-setup script as described above, rather than installing manually.¶
- Install SQLite3 -
a. Raspbian -
apt-get install sqlite3
b. Yocto -
cd ~ wget https://sqlite.org/2016/sqlite-tools-linux-x86-3150200.zip unzip sqlite-tools-linux-x86-3150200.zip mv sqlite-tools-linux-x86-3150200 sqlite
- Get dependencies -
pip install flask pip install flask-restful
- Clone this repo -
cd ~ git clone https://github.com/colinlennon/xDripAPS.git .xDripAPS
- Create directory for database file -
mkdir -p ~/.xDripAPS_data
- Add cron entry to start the microservice at startup -
@reboot python /home/root/.xDripAPS/xDripAPS.py
- Cofigure the xDrip Android app -
xDrip > Settings > REST API Upload > Set Enabled and enter Base URL: http://[API_SECRET]@[Pi/Edison_IP_address]:5000/api/v1/
(Note: Enter your plain-text API_SECRET in the Android app, not the hashed version of it).
- Use the microservice within OpenAPS e.g.
openaps device add xdrip process 'bash -c "curl -s http://localhost:5000/api/v1/entries?count=288"' openaps report add monitor/glucose.json text xdrip shell