Skip to content

Commit

Permalink
Moves offline monitoring away from the offline looping page
Browse files Browse the repository at this point in the history
  • Loading branch information
danamlewis committed Jul 10, 2017
1 parent 7b31cd7 commit 7b1ce8a
Showing 1 changed file with 15 additions and 252 deletions.
267 changes: 15 additions & 252 deletions docs/docs/Customize-Iterate/offline-looping-and-monitoring.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
# Offline monitoring
# Offline looping - aka, running OpenAPS without internet connectivity

There are a number of ways to have an "offline" OpenAPS rig, and numerous ways to monitor offline. Offline refers to situations where your rig moves into an area where it does not have internet access (i.e., the rig does not have a known wifi network available and the cell phone used with the rig does not have cell coverage/hotspot available). By setting up one of these offline solutions, your rig can still loop while in an offline area. Depending on the setup, the opportunities to visualize or monitor the loop actions (e.g., check what temp basal is actually being set) may vary until you can get back into an online area.
There are a number of ways to have an "offline" OpenAPS rig, and numerous ways to monitor offline (see the monitoring section for information about monitoring offline). Offline refers to situations where your rig moves into an area where it does not have internet access (i.e., the rig does not have a known wifi network available and the cell phone used with the rig does not have cell coverage/hotspot available). By setting up one of these offline solutions, your rig can still loop while in an offline area. Depending on the setup, the opportunities to visualize or monitor the loop actions (e.g., check what temp basal is actually being set) may vary until you can get back into an online area.

## Offline looping

### Medtronic CGM users
Medtronic CGM users can, by default, automatically loop offline because the rig will read CGM data directly from the pump.

#### 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

```
openaps first-upload
```
from inside your openAPS directory, before your loop will start updating correctly to your nightscout site.

********************************

### Dexcom CGM users
Dexcom CGM users have a few different alternatives to retrieve blood glucose values locally for offline use. The options to choose from are:

Expand All @@ -30,142 +41,9 @@ Dexcom CGM users have a few different alternatives to retrieve blood glucose val

* If you are using this configuration for G4 receivers and (1) are online and (2) want to see RAW BGs in NS, then you must remember to add `rawbg` to your ENABLE line in your Heroku/Azure settings. You will also have to go to your Nightscout site's settings and select "always" from the Show RAW BG options. You will also have to select `g4-raw` (if on master branch) or `g4-upload` (if on dev branch) as the CGM type in the loop setup script.

## Offline monitoring

* See Pancreabble instructions below for connecting your rig to your watch
* See xDrip/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

```
openaps first-upload
```
from inside your openAPS directory, before your loop will start updating correctly to your nightscout site.

### Pancreabble

_(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.

[Pancreabble]: https://github.com/mddub/pancreabble

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.

Go to `~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. NOTE: Make sure the MAC address is in ALL CAPS.

Once you've installed, you will need to pair the watch to your Edison.

#### Bluetooth setup for Pancreabble

* 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 found` returned. 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 `killall` and wait longer between steps.

* Now launch the Bluetooth control program: `bluetoothctl`

* And run: `power off`

* then `power on`

* and each of the following:

```
discoverable on
scan on
agent on
default-agent
```

#### On Your Pebble

Settings/BLUETOOTH to make sure Pebble is in pairing mode

from terminal

`trust AA:BB:CC:DD:EE:FF`
`pair AA:BB:CC:DD:EE:FF`

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.


Currently the `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

the `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 for Android users
### xDripAPS for offline BGs and looping for Android users

**Note as of 1/26/17:** The below documentation is WIP and needs additional testing.

Expand Down Expand Up @@ -277,119 +155,4 @@ http://<nightscout_api_secret>@<rig_ip_address1>:5000/api/v1/ http://<nightscout
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
```

### Hot Button - also for Android users

#### Purpose
[Hot Button app](https://play.google.com/store/apps/details?id=crosien.HotButton) can be used to monitor and control OpenAPS using SSH commands. It is especialy useful for offline setups. Internet connection is not required, it is enough to have the rig connected to your android smartphone using bluetooth tethering.

#### App Setup
To setup the button you need to long click. Setup the Server Settings and set them as default. For every other button you can load them.

#### Basic commands
To the Command part of the button setup you can write any command which you would run in the ssh session. For example to show the automatic sensitivity ratio, you can set:
`cat /root/myopenaps/settings/autosens.json`

After button click the command is executed and the results are displayed in the black text area bellow the buttons.

#### Temporary targets
It is possible to use Hot Button application for setup of temporary targets. This [script](https://github.com/lukas-ondriga/openaps-share/blob/master/start-temp-target.sh) generates the custom temporary target starting at the time of its execution. You need to edit the path to the openaps folder inside it.

To setup activity mode run:
`./set_temp_target.sh "Activity Mode" 130`

To setup eating soon mode run:
`./set_temp_target.sh "Eating Soon" 80`

The script is currently work in progress. The first parameter is probably not needed, it is there to have the same output as Nightscout produces. It is not possible to set different top and bottom target, but this could be easily added in the future.
To be able to use the script, the most straigtforward solution is to disable the download of temporary targets from Nightscout. To do that edit your openaps.ini and remove `openaps ns-temptargets` from ns-loop.

#### SSH Login Speedup
To speed up the command execution you can add to the `/etc/ssh/sshd_config` the following line:
`UseDNS no`

********************************

### Local, offline BGs for iPhone users using a separate Loop app

These instructions describe how to use a Loopkit/Loop app as a glucose data source for offline looping using OpenAPS. Note that most of the features of Loop itself are not used in this modification; we are using Loop simply as a local bridge for glucose data from the G5 transmitter to the OpenAPS rig. If you have a working version of Loop already installed, it is recommended build this branch as a separate app by using a unique bundle identifier.

Also, for those unfamiliar with Loop, note the below instructions are about creating a developer account to self-deploy the app. This is free, but you'd have to re-build the app every 7 days (and it will probably drive you crazy). Otherwise, it's $99 for a developer licenese where you don't have to re-deploy weekly. (For other alternatives for offline BG, see the top of this page).

#### Prerequisites for using Loop app on iPhone for local, offline BGs to the rig
1. Build (and deploy to your iPhone) a version of Loop using the `lookout` branch from @thebookins. Follow the instructions in [Loop Docs](https://loopkit.github.io/loopdocs/) but install Loop as follows:
```
git clone https://github.com/thebookins/Loop.git
cd Loop
git checkout lookout
```
(alternatively, merge the `lookout` changes with your own Loop fork). Depending on the version of XCode you are using, it may be necessary to rebuild the linked frameworks using carthage:
```
carthage update --platform iOS
```

2. If you haven't already done so, install the dev branch of OpenAPS using the [setup script](https://openaps.readthedocs.io/en/latest/docs/walkthrough/phase-2/oref0-setup.html) with `xdrip` as the glucose source.

3. Step 2 will set up [xDripAPS](https://github.com/colinlennon/xDripAPS) on your OpenAPS rig. This is a Python program that exposes a very simplified NightScout instance running on the rig to which we can send glucose data. A couple of changes to xDripAPS are required to get it to accept glucose data from Loop. Pull these changes as follows:
```
cd
rm -r .xDripAPS
git clone https://github.com/thebookins/xDripAPS.git $HOME/.xDripAPS
cd .xDripAPS
git checkout lookout
```

4. Setup up [Bluetooth tethering](http://openaps.readthedocs.io/en/latest/docs/walkthrough/phase-4/bluetooth-tethering-edison.html) between your iPhone and your OpenAPS rig.

5. Open Loop and the Dexcom app on your iPhone. The Dexcom app will control the G5 transmitter; Loop just listens in.

#### Setup
1. In Loop, select G5 Transmitter in Settings and enter the G5 Transmitter ID. Do not add the pump serial number as we are using Loop only as a local bridge to get BG data to OpenAPS. (Without a RileyLink, it's impossible to control the pump anyway.)

2. In Loop, select Nightscout in Settings and enter the local IP address for your Edison in URL format with the addition of `:5000` at the end (which will look like this `http://[YOUR EDISON'S IP ADDRESS]:5000`). Then, enter your API secret as requested in Loop.

All done. Loop will now send glucose data to the edison URL every five minutes, ready to be picked up by oref0.

********************************

### Creating an information web page that can be picked up using the rig's URL.

**TODO** - implement this as a proper oref0 script that can be installed by oref0-setup

This allows you to extract data from the various files that OpenAPS creates and access the locally from the phone that is connected to the rig, giving a full information set.

Firstly, you need to set up the script that will do this for you. An example is shown below:

```
rm ~/myopenaps/enact/index.html
touch ~/myopenaps/enact/index.html
(cat ~/myopenaps/enact/smb-enacted.json | jq -r .timestamp | awk '{print substr($0,12,5)}') >> ~/myopenaps/enact/index.html
(cat ~/myopenaps/enact/smb-enacted.json | jq -r .reason) >> ~/myopenaps/enact/index.html
(echo -n 'TBR: ' && cat ~/myopenaps/enact/smb-enacted.json | jq .rate) >> ~/myopenaps/enact/index.html
(echo -n 'IOB: ' && cat ~/myopenaps/enact/smb-enacted.json | jq .IOB) >> ~/myopenaps/enact/index.html
(echo -n 'Edison Battery: ' && cat ~/myopenaps/monitor/edison-battery.json | jq -r .battery | tr '\n' ' ' && echo '%') >> ~/myopenaps/enact/index.html
(echo -n 'Insulin Remaining: ' && cat ~/myopenaps/monitor/reservoir.json) >> ~/myopenaps/enact/index.html
```
You may need to adjust the values in `'{print substr($0,12,5)}'` - whilst I know these work on the rigs I have set them up on, other's have had better results with `{print substr($0,13,5)}'`

It can be set up where you choose, either in your openaps directory or at root.

You will also need to start up the SimpleHTTPserver service that is already installed on jubilinux in the location you will place your file. This is done by adding the following line to your Cron:

```
@reboot cd /root/myopenaps/enact && python -m SimpleHTTPServer 1337
```
The final thing to do is to make sure the script runs regularly to collect the data and publish it. This requires an additional cron line:

```
*/5 * * * * (bash /root/http.sh) 2>&1 | tee -a /var/log/openaps/http.log
```
In this case the script is running from the /root directory and I am publishing to the ~/myopenaps/enact directory.

To access this from an iphone browser, enter something like the following: http://172.20.10.x:1337/index.html and you should receive an unformatted html page with the data in it. If you want to improve the output for a browser, the script can be modified to generate html tags that will allow formatting and could provide colouring if various predicted numbers were looking too low.

On Android, you can download http-widget (https://play.google.com/store/apps/details?id=net.rosoftlab.httpwidget1&hl=en_GB) and add a widget to your home screen that will display this data.

If you use a Samsung Gear S3 watch, you can use the above http-widget with Wearable Widgets (http://wearablewidgets.com) to view what OpenAPS is doing locally, without internet connection.

0 comments on commit 7b1ce8a

Please sign in to comment.