Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin for synchronizing CGM / treatment data from diasend #7872

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ Also if you can't code, it's possible to contribute by improving the documentati
| [`iob` (Insulin-on-Board)](README.md#iob-insulin-on-board)| Please volunteer | Please volunteer |
| [`loop` (Loop)](README.md#loop-loop)| Please volunteer | Please volunteer |
| [`mmconnect` (MiniMed Connect bridge)](README.md#mmconnect-minimed-connect-bridge)| Please volunteer | Please volunteer |
| [`diasend` (Diasend bridge)](README.md#diasend-diasend-bridge)| [@burnedikt] | Please volunteer |
| [`openaps` (OpenAPS)](README.md#openaps-openaps)| Please volunteer | Please volunteer |
| [`profile` (Treatment Profile)](README.md#profile-treatment-profile)| Please volunteer | Please volunteer |
| [`pump` (Pump Monitoring)](README.md#pump-pump-monitoring)| Please volunteer | Please volunteer |
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,13 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs/ or
* `MMCONNECT_STORE_RAW_DATA` - Set this to "true" to store raw data returned from CareLink as `type: "carelink_raw"` database entries (useful for development).
* `MMCONNECT_SERVER` - Set this to `EU` if you're using the European Medtronic services

##### `diasend` (Diasend bridge)
Transfer near-real-time continuous glucose monitoring and treatment data from diasend into Nightscout ([read more](https://github.com/burnedikt/diasend-nightscout-bridge)). ⚠️ Due to diasend not providing any timezone information on the data, the timezone (`TZ`) of the nightscout instance needs to match the timezone in which the values were sent to diasend, i.e. the timezone of the device generating the data for diasend, most likely the user's local timezone.
* `DIASEND_USERNAME` - Your user name / e-mail address for diasend.
* `DIASEND_PASSWORD` - Your password for diasend.
* `DIASEND_POLLING_INTERVAL_MS` (`60000` *1 minute*) - Number of milliseconds to wait between requests to the diasend server.
* `DIASEND_PUMP_SETTINGS_POLLING_INTERVAL_MS` (`43200000` *12 hours*) - Number of milliseconds to wait between attempts to synchronize pump settings.

##### `pump` (Pump Monitoring)
Generic Pump Monitoring for OpenAPS, MiniMed Connect, RileyLink, t:slim, with more on the way
* Requires `DEVICESTATUS_ADVANCED="true"` to be set
Expand Down
67 changes: 67 additions & 0 deletions lib/plugins/diasend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* jshint node: true */
"use strict";

const diasendBridge = require("diasend-nightscout-bridge");
const NightscoutClient =
require("diasend-nightscout-bridge/dist/nightscout/internal-api").InternalApiNightscoutClient;

function init(env, entries, treatments, bus) {
if (
env.extendedSettings.diasend &&
env.extendedSettings.diasend.username &&
env.extendedSettings.diasend.password
) {
console.info("Booting Diasend Connector");
return {
run: makeRunner(env, entries, treatments, bus),
};
} else {
console.info("Diasend Connect not enabled");
return null;
}
}
function makeRunner(env, entries, treatments, profile, bus) {
var options = getOptions(env);

const nightscoutClient = new NightscoutClient(entries, treatments, profile);

return function run() {
const stopSynchronization = diasendBridge.startSynchronization({
...options,
pollingIntervalMs: options.diasendPollingInterval,
nightscoutClient,
});

const stopProfileSynchronization =
diasendBridge.startPumpSettingsSynchronization({
diasendPassword: options.diasendPassword,
diasendUsername: options.diasendUsername,
pollingIntervalMs: options.diasendPumpSettingsPollingInterval,
nightscoutProfileName: "Diasend",
nightscoutClient,
});

if (bus) {
bus.on("teardown", function serverTeardown() {
stopSynchronization();
stopProfileSynchronization();
});
}
};
}

function getOptions(env) {
return {
diasendUsername: env.extendedSettings.diasend.username,
diasendPassword: env.extendedSettings.diasend.password,
// default is 1 minute
diasendPollingInterval:
env.extendedSettings.diasend.pollingIntervalMs || 60 * 1000,
// default is 12 hours
diasendPumpSettingsPollingInterval:
env.extendedSettings.diasend.pumpSettingsPollingIntervalMs ||
12 * 60 * 60 * 1000,
};
}

module.exports = init;
15 changes: 15 additions & 0 deletions lib/server/bootevent.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,20 @@ function boot (env, language) {
next( );
}

function setupDiasend(ctx, next) {
console.log("Executing setupDiasend");

if (hasBootErrors(ctx)) {
return next();
}

ctx.diasend = require("../plugins/diasend")(env, ctx.entries, ctx.treatments, ctx.profile, ctx.bus);
if (ctx.diasend) {
ctx.diasend.run();
}
next();
}

function setupMMConnect (ctx, next) {

console.log('Executing setupMMConnect');
Expand Down Expand Up @@ -370,6 +384,7 @@ function boot (env, language) {
.acquire(setupListeners)
.acquire(setupBridge)
.acquire(setupMMConnect)
.acquire(setupDiasend)
.acquire(finishBoot);
}

Expand Down
Loading