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

Dev #44

Open
wants to merge 18 commits into
base: dev
Choose a base branch
from
Open

Dev #44

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
53 changes: 53 additions & 0 deletions bin/send-device-status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env node

/*
Send Temporary Basal to Azure

Copyright (c) 2015 OpenAPS Contributors

Released under MIT license. See the accompanying LICENSE.txt file for
full terms and conditions

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

*/
var http = require('https');
var reason = process.argv.slice(2, 3).pop()

var data = JSON.stringify({
"DeviceName": "Medtronics 512",
"TimeStamp": new Date(),
"Reason": reason }
);

var options = {
host: 'openapsdata.azurewebsites.net',
port: '443',
path: '/api/devicestatus',
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8',
'Content-Length': data.length
}
};

var req = http.request(options, function (res) {
var msg = '';

res.setEncoding('utf8');
res.on('data', function (chunk) {
msg += chunk;
});
res.on('end', function () {
console.log(JSON.parse(msg));
});
});

req.write(data);
req.end();
43 changes: 30 additions & 13 deletions bin/send-tempbasal-Azure.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ if (!module.parent) {
var enacted_temps_input = process.argv.slice(3, 4).pop()
var glucose_input = process.argv.slice(4, 5).pop()
var webapi = process.argv.slice(5, 6).pop()
var requested_temp_input = process.argv.slice(6, 7).pop()
var battery_input = process.argv.slice(7, 8).pop()

if (!iob_input || !enacted_temps_input || !glucose_input || !webapi) {
console.log('usage: ', process.argv.slice(0, 2), '<iob.json> <enactedBasal.json> <bgreading.json> <[your_webapi].azurewebsites.net>');
console.log('usage: ', process.argv.slice(0, 2), '<iob.json> <enactedBasal.json> <glucose.json> <[your_webapi].azurewebsites.net> optional: <requestedtemp.json> <battery.json>');
process.exit(1);
}
}
Expand All @@ -37,17 +40,31 @@ var iob_data = require(cwd + '/' + iob_input);



var data = JSON.stringify({
"Id": 3,
"temp": enacted_temps.temp,
"rate": enacted_temps.rate,
"duration": enacted_temps.duration,
"bg": glucose_data[0].glucose,
"iob": iob_data.iob,
"timestamp": enacted_temps.timestamp,
"received": enacted_temps.recieved
var data = {
bg: glucose_data[0].glucose,
iob: iob_data.iob,
temp:enacted_temps.temp,
rate: enacted_temps.rate,
duration: enacted_temps.duration,
timestamp: enacted_temps.timestamp,
received: enacted_temps.recieved
}

if (requested_temp_input){
var requested_temp = require(cwd + '/' + requested_temp_input);
data.tick= requested_temp.tick;
data.eventualBG = requested_temp.eventualBG;
data.snoozeBG = requested_temp.snoozeBG;
data.reason = requested_temp.reason;
}

if (battery_input)
{
var battery_data = require(cwd +'/' + battery_input);
data.battery = battery_data.status+" Voltage:"+battery_data.voltage;
}
);

var payload=JSON.stringify(data);

var options = {
host: webapi,
Expand All @@ -56,7 +73,7 @@ var options = {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8',
'Content-Length': data.length
'Content-Length': payload.length
}
};

Expand All @@ -72,5 +89,5 @@ var req = http.request(options, function (res) {
});
});

req.write(data);
req.write(payload);
req.end();
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"oref0-calculate-iob": "./bin/oref0-calculate-iob.js",
"oref0-determine-basal": "./bin/oref0-determine-basal.js",
"send-tempbasal-Azure": "./bin/send-tempbasal-Azure.js",
"send-device-status":"./bin/send-device-status.js",
"oref0-get-profile": "./bin/oref0-get-profile.js",
"oref0-ifttt-notify": "./bin/oref0-ifttt-notify",
"oref0-reset-usb": "bin/reset-usb.sh",
Expand Down