forked from nightscout/minimed-connect-to-nightscout
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read config from env instead of file
- Loading branch information
Showing
6 changed files
with
45 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
config.js | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,12 +17,26 @@ | |
|
||
1. Install [Node]. | ||
1. Clone this repository or [download a zip] with the latest version. | ||
1. Create a `config.js` file based on the provided `config.js.example`. | ||
1. `npm install` to install dependencies. | ||
1. Set environment variables (see below). | ||
1. `npm start` and leave it running. | ||
|
||
**Coming soon:** Deploy instructions for Heroku | ||
|
||
### Required environment variables | ||
|
||
* `CARELINK_USERNAME` - your username for [CareLink][carelink] | ||
* `CARELINK_PASSWORD` - your password for [CareLink][carelink] | ||
* `CARELINK_PUMP_TIMEZONE` - a timezone offset string like `"-0700"` which represents the pump's offset from UTC (**TODO:** use time zone names like `America/Los_Angeles` instead, since offsets vary depending on DST) | ||
* `API_SECRET` - the value you use for `API_SECRET` on your Nightscout website | ||
* `WEBSITE_HOSTNAME` - the hostname for your Nightscout instance, which looks like `your.host.com`. If you are running this script in the same Azure environment as Nightscout, there is no need to set this, as it will [already be set by Azure][azure-environment]. If you set `NS` (see below), you do not need to set this. | ||
|
||
### Optional environment variables | ||
|
||
* `CARELINK_REQUEST_INTERVAL` - number of milliseconds to wait between requests to the CareLink server (default: 60000) | ||
* `CARELINK_SGV_LIMIT` - maximum number of recent sensor glucose values to send to Nightscout (default: 24) | ||
* `NS` - a fully-qualified Nightscout URL (e.g. `https://sitename.azurewebsites.net`) which overrides `WEBSITE_HOSTNAME` | ||
|
||
## Currently supported data | ||
|
||
* Sensor glucose values | ||
|
@@ -49,6 +63,7 @@ This project is intended for educational and informational purposes only. It rel | |
[cgm-remote-monitor]: https://github.com/nightscout/cgm-remote-monitor | ||
[Node]: https://nodejs.org | ||
[download a zip]: https://github.com/mddub/minimed-connect-to-nightscout/archive/master.zip | ||
[azure-environment]: https://github.com/projectkudu/kudu/wiki/Azure-runtime-environment | ||
[this sensor-disabled gist]: https://gist.github.com/mddub/b033ec0c800deec02471 | ||
[this sensor-enabled gist]: https://gist.github.com/mddub/dc1baf74eda772dcb164 | ||
[get in touch]: mailto:[email protected] | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,38 @@ | ||
/* jshint node: true */ | ||
"use strict"; | ||
|
||
var config = require('./config'), | ||
carelink = require('./carelink'), | ||
var carelink = require('./carelink'), | ||
nightscout = require('./nightscout'); | ||
|
||
var client = carelink.Client({username: config.CARELINK_USERNAME, password: config.CARELINK_PASSWORD}), | ||
endpoint = config.NIGHTSCOUT_HOST + '/api/v1/entries.json', | ||
secret = config.NIGHTSCOUT_API_SECRET; | ||
function readEnv(key, defaultVal) { | ||
var val = process.env[key] || | ||
process.env[key.toLowerCase()] || | ||
// Azure prefixes environment variables with this | ||
process.env['CUSTOMCONNSTR_' + key] || | ||
process.env['CUSTOMCONNSTR_' + key.toLowerCase()]; | ||
return val !== undefined ? val : defaultVal; | ||
} | ||
|
||
var config = { | ||
username: readEnv('CARELINK_USERNAME'), | ||
password: readEnv('CARELINK_PASSWORD'), | ||
pumpTimezone: readEnv('CARELINK_PUMP_TIMEZONE'), | ||
nsHost: readEnv('WEBSITE_HOSTNAME'), | ||
nsBaseUrl: readEnv('NS'), | ||
nsSecret: readEnv('API_SECRET'), | ||
interval: parseInt(readEnv('CARELINK_REQUEST_INTERVAL', 60 * 1000)), | ||
sgvLimit: parseInt(readEnv('CARELINK_SGV_LIMIT', 24)) | ||
}; | ||
|
||
var client = carelink.Client({username: config.username, password: config.password}); | ||
|
||
var endpoint = (config.nsBaseUrl ? config.nsBaseUrl : 'https://' + config.nsHost) + '/api/v1/entries.json'; | ||
|
||
(function requestLoop() { | ||
client.fetch(function(data) { | ||
var entries = nightscout.transform(data, config.PUMP_TIMEZONE, config.NUM_RECORDS_TO_SUBMIT); | ||
nightscout.upload(entries, endpoint, secret, function(response) { | ||
setTimeout(requestLoop, config.CARELINK_REQUEST_INTERVAL); | ||
var entries = nightscout.transform(data, config.pumpTimezone, config.sgvLimit); | ||
nightscout.upload(entries, endpoint, config.nsSecret, function(response) { | ||
setTimeout(requestLoop, config.interval); | ||
}); | ||
}); | ||
})(); |