burnedikt / diasend-nightscout-bridge

Synchronize your diasend data to nightscout.
MIT License
18 stars 18 forks source link
camaps diasend nightscout sync

Attention

⚠️ diasend.com has been superseded by glooko.com. ⚠️

This project will no longer work since diasend will be spun down in the future and be completely replaced by glooko. For more information, visit the official resources of diasend / glooko.

If you want to import data from e.g. CamAPS into nightscout, here are some options to look into.

Thank you for everyone who contributed to this project!


Diasend -> Nightscout Bridge #WeAreNotWaiting

Synchronizes treatments (insulin boli, temp basal changes) as well as continuous glucose values (CGV) from diasend to nightscout. This can e.g. help CamAPS FX users to view their treatments and glucose values via nightscout.

While diasend will eventually be replaced by glooko which will (presumably) provide a more open API to access the data and forward it to nightscout, this project can help in the meantime. #WeAreNotWaiting

Supported Features / Data

✅ Glucose Values (CGM)
✅ Correction and Meal Boli
✅ Carb Corrections
✅ Basal rates (Pre-programmed)
✅ Basal rates (temporary, as applied by the CamAPS FX hybrid closed loop)
✅ Pump settings (see issue)

A word of advice

Depending on your use case and requirements, you may not need a synchronization solution from diasend to nightscout as provided by this project.

If all you need is to monitor the glucose values remotely via nightscout and don't want to use diasend for it, or the delay of uploading to diasend and synchronizing to nightscout (5+ minutes) is unbearable, I recommend taking a look at running xDrip in Companion mode which will provide glucose values faster to nightscout than this project can.

However, if you need to see more data than the pure continuous glucose values (CGV) within nightscout, e.g. insulin boli, carb corrections, basal rates or temporary adjustments of basal rates, the diasend-nightscout-bridge has got you covered.

And finally - you don't have to pick: You can run both the xDrip Companion and the diasend-nightscout-bridge to get the best out of both worlds: Near-Realtime blood glucose monitoring and trends as well as proper import of all treatments issued via CamAPS FX / stored on diasend. For more details, see here

Configuration

The following environment variables are required, also see env.example:

Optionally, you can also provide the following values:

Running

There are two different ways to use this project in order to synchronize data from diasend to nightscout. You can either run this bridge standalone in which case it will pull the data via the diasend API and forward it to nightscout via nightscout's REST API. The downside here is that you need to run it on an additional server or PC which is why the more intuitive way is running the bridge as a plugin directly as part of nightscout. This way, the data will still be pulled from diasend via its HTTP API but the data will directly be imported into nightscout without going through its REST API, which should likely be more reliable and remove the need to run the bridge separately.

Nightscout Plugin

To run this bridge as a plugin directly in nightscout, you can simply install the bridge as an npm package within your nightscout installation and implement a handler to import the data directly into nightscout. A sample implementation can be found here: https://github.com/nightscout/cgm-remote-monitor/compare/master...burnedikt:cgm-remote-monitor:master?expand=1.

Once installed, the plugin needs to be enabled via nightscout's ENABLE="... diasend ..." environment variable and the following two environment variables need to be defined: DIASEND_USERNAME and DIASEND_PASSWORD so that nightscout will automatically pull data in from diasend.

A future goal is to either merge the example implementation above upstream or publish the bridge as a nightscout plugin directly to npm so that the integration with nightscout becomes easier.

Standalone / Sidecar

To run the bridge, ensure that all required environment variables are set. You can set environment variables manually or create a file called .env and fill it with values similar to env.example. All variables defined within the .env file will be loaded automatically thanks to dotenv.

Next, run yarn install to install all dependencies.

Finally run the following command to synchronize CGV from diasend to nightscout every 5 minutes:

yarn start

Docker

You can also run the bridge as a docker container either side-by-side with nightscout (if it is running containerized using docker or docker-compose). To do so, you can use the Dockerfile within this repository to build the bridge into a docker container image:

docker build -t diasend2nightscout .

You can use the resulting container image (in this case named diasend2nightscout) to run the bridge as a container using docker-compose like:

# nightscout services

services:
  diasend-bridge:
    build:
      context: .
    environment:
      DIASEND_USERNAME: <diasend-username>
      DIASEND_PASSWORD: <diasend-password>
      NIGHTSCOUT_URL: <url-of-nightscout-instance>
      NIGHTSCOUT_API_SECRET: <retracted>
      # ... other environment variables for configuration, see readme

... or directly using docker à la docker run -e DIASEND_USERNAME=... -e DIASEND_PASSWORD=...diasend2nightscout. See here for more details.

Notes & Known Issues

Debugging / Logging

This project uses the loglevel library to control the verbosity / level of logging. You can turn on more verbose and detailed logging by setting the environment variable NODE_ENV to development. This will output detailed information about what kind of data has been fetched from diasend and how it will be sent to nightscout.

Further information

This project works by connecting to diasend's internal (!) API, which may change at any time without warning, so use with caution, and pulling the latest number of so-called patient data, converts it to CGV values compatible with nightscout and then uses the nightscout API to push those values.

More information and sample calls on the diasend-api can be found in diasend-api.http which can be used with VSCode's REST Client plugin to quickly try out the API calls.

This project is written in Typescript.

Related Projects

Contributing

File an issue if you'd like to give feedback, request an enhancement, or report a bug.

Pull requests are welcome.

Disclaimer

This project is intended for educational and informational purposes only. It relies on a series of fragile components and assumptions, any of which may break at any time. It is not FDA approved and should not be used to make medical decisions. It is neither affiliated with nor endorsed by diasend / glooko, and may violate their Terms of Service.