From 9c7a194fb33420ad9d0d9aae9852a19067f8f536 Mon Sep 17 00:00:00 2001 From: amazaheri Date: Sun, 18 Oct 2015 09:46:59 -0700 Subject: [PATCH 01/10] Slight Changes to send-tempbasal-azure.js --- bin/send-tempbasal-Azure.js | 41 +++++++++++++++++++++++-------------- package.json | 2 +- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/bin/send-tempbasal-Azure.js b/bin/send-tempbasal-Azure.js index 32b6038..7b7dde9 100644 --- a/bin/send-tempbasal-Azure.js +++ b/bin/send-tempbasal-Azure.js @@ -23,9 +23,11 @@ if (!module.parent) { var iob_input = process.argv.slice(2, 3).pop() 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() - if (!iob_input || !enacted_temps_input || !glucose_input || !webapi) { - console.log('usage: ', process.argv.slice(0, 2), ' <[your_webapi].azurewebsites.net>'); + var requested_temp_input = process.argv.slice(5, 6).pop() + var battery_input = process.argv.slice(6, 7).pop() + var webapi = process.argv.slice(7, 8).pop() + if (!iob_input || !enacted_temps_input || !glucose_input || !requested_temp_input || !battery_input || !webapi) { + console.log('usage: ', process.argv.slice(0, 2), ' <[your_webapi].azurewebsites.net>'); process.exit(1); } } @@ -34,20 +36,29 @@ var cwd = process.cwd(); var glucose_data = require(cwd + '/' + glucose_input); var enacted_temps = require(cwd + '/' + enacted_temps_input); var iob_data = require(cwd + '/' + iob_input); +var requested_temp = require(cwd + '/' + requested_temp_input); +var battery_data = require(cwd +'/' + battery_input); +var data = { + bg: glucose_data[0].glucose, + iob: iob_data.iob, + tick: requested_temp.tick, + eventualBG: requested_temp.eventualBG, + snoozeBG: requested_temp.snoozeBG, + reason: requested_temp.reason, + battery: battery_data.status+" Voltage:"+battery_data.voltage } -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 +if (!requested_temp.rate && !requested_temp.duration && enacted_temps.recieved) +{ +data.temp = enacted_temps.temp; +data.rate = enacted_temps.rate; +data.duration = enacted_temps.duration; +data.timestamp = enacted_temps.timestamp; +data.received": enacted_temps.recieved; } -); + +var payload=JSON.stringify(data); var options = { host: webapi, @@ -56,7 +67,7 @@ var options = { method: 'POST', headers: { 'Content-Type': 'application/json; charset=utf-8', - 'Content-Length': data.length + 'Content-Length': payload.length } }; @@ -72,5 +83,5 @@ var req = http.request(options, function (res) { }); }); -req.write(data); +req.write(payload); req.end(); diff --git a/package.json b/package.json index d224738..028045e 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,8 @@ "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-iftt-notify": "./bin/oref0-iftt-notify", "reset-wifi-dongle": "bin/reset-wifi-dongle.sh", "mm-format-ns-glucose": "./bin/mm-format-ns-glucose.sh", "mm-format-ns-pump-history": "./bin/mm-format-ns-pump-history.sh", From 02b822e5ec425fd8fb3c4b7161c7f0fea9e4b4cc Mon Sep 17 00:00:00 2001 From: amazaheri Date: Sun, 18 Oct 2015 09:59:09 -0700 Subject: [PATCH 02/10] Slight changes --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bfbba89..807e9cd 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "send-device-status":"./bin/send-device-status.js", "oref0-get-profile": "./bin/oref0-get-profile.js", "oref0-ifttt-notify": "./bin/oref0-ifttt-notify", - "reset-wifi-dongle": "bin/reset-wifi-dongle.sh", + "reset-usb": "bin/reset-usb.sh", "mm-format-ns-glucose": "./bin/mm-format-ns-glucose.sh", "mm-format-ns-pump-history": "./bin/mm-format-ns-pump-history.sh", "oref0": "./bin/oref0.sh", From f9856888ff7570336edb3812b509b80922161be7 Mon Sep 17 00:00:00 2001 From: Ali Mazaheri Date: Sun, 18 Oct 2015 10:45:30 -0700 Subject: [PATCH 03/10] Update send-tempbasal-Azure.js --- bin/send-tempbasal-Azure.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/send-tempbasal-Azure.js b/bin/send-tempbasal-Azure.js index 7b7dde9..76abb33 100644 --- a/bin/send-tempbasal-Azure.js +++ b/bin/send-tempbasal-Azure.js @@ -27,7 +27,7 @@ if (!module.parent) { var battery_input = process.argv.slice(6, 7).pop() var webapi = process.argv.slice(7, 8).pop() if (!iob_input || !enacted_temps_input || !glucose_input || !requested_temp_input || !battery_input || !webapi) { - console.log('usage: ', process.argv.slice(0, 2), ' <[your_webapi].azurewebsites.net>'); + console.log('usage: ', process.argv.slice(0, 2), ' <[your_webapi].azurewebsites.net> '); process.exit(1); } } @@ -55,7 +55,7 @@ data.temp = enacted_temps.temp; data.rate = enacted_temps.rate; data.duration = enacted_temps.duration; data.timestamp = enacted_temps.timestamp; -data.received": enacted_temps.recieved; +data.received = enacted_temps.recieved; } var payload=JSON.stringify(data); From 9a3d204db27522fe027cd545b37e6ef6b3636893 Mon Sep 17 00:00:00 2001 From: Ali Mazaheri Date: Sun, 18 Oct 2015 11:05:15 -0700 Subject: [PATCH 04/10] Update send-tempbasal-Azure.js --- bin/send-tempbasal-Azure.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/bin/send-tempbasal-Azure.js b/bin/send-tempbasal-Azure.js index 76abb33..3f2e3e1 100644 --- a/bin/send-tempbasal-Azure.js +++ b/bin/send-tempbasal-Azure.js @@ -26,8 +26,8 @@ if (!module.parent) { var requested_temp_input = process.argv.slice(5, 6).pop() var battery_input = process.argv.slice(6, 7).pop() var webapi = process.argv.slice(7, 8).pop() - if (!iob_input || !enacted_temps_input || !glucose_input || !requested_temp_input || !battery_input || !webapi) { - console.log('usage: ', process.argv.slice(0, 2), ' <[your_webapi].azurewebsites.net> '); + if (!iob_input || !enacted_temps_input || !glucose_input || !requested_temp_input || !webapi) { + console.log('usage: ', process.argv.slice(0, 2), ' <[your_webapi].azurewebsites.net> '); process.exit(1); } } @@ -37,7 +37,7 @@ var glucose_data = require(cwd + '/' + glucose_input); var enacted_temps = require(cwd + '/' + enacted_temps_input); var iob_data = require(cwd + '/' + iob_input); var requested_temp = require(cwd + '/' + requested_temp_input); -var battery_data = require(cwd +'/' + battery_input); + var data = { bg: glucose_data[0].glucose, @@ -45,9 +45,14 @@ var data = { tick: requested_temp.tick, eventualBG: requested_temp.eventualBG, snoozeBG: requested_temp.snoozeBG, - reason: requested_temp.reason, - battery: battery_data.status+" Voltage:"+battery_data.voltage } + reason: requested_temp.reason + } +if (battery_input) +{ + var battery_data = require(cwd +'/' + battery_input); + data.battery = battery_data.status+" Voltage:"+battery_data.voltage; +} if (!requested_temp.rate && !requested_temp.duration && enacted_temps.recieved) { From 5a1592817c02670266b71eb2c86aa0602996be66 Mon Sep 17 00:00:00 2001 From: amazaheri Date: Sun, 18 Oct 2015 11:13:02 -0700 Subject: [PATCH 05/10] Latest --- bin/send-tempbasal-Azure.js | 18 ++++++++++++------ package.json | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/bin/send-tempbasal-Azure.js b/bin/send-tempbasal-Azure.js index 7b7dde9..f1af3d4 100644 --- a/bin/send-tempbasal-Azure.js +++ b/bin/send-tempbasal-Azure.js @@ -26,8 +26,8 @@ if (!module.parent) { var requested_temp_input = process.argv.slice(5, 6).pop() var battery_input = process.argv.slice(6, 7).pop() var webapi = process.argv.slice(7, 8).pop() - if (!iob_input || !enacted_temps_input || !glucose_input || !requested_temp_input || !battery_input || !webapi) { - console.log('usage: ', process.argv.slice(0, 2), ' <[your_webapi].azurewebsites.net>'); + if (!iob_input || !enacted_temps_input || !glucose_input || !requested_temp_input || !webapi) { + console.log('usage: ', process.argv.slice(0, 2), ' <[your_webapi].azurewebsites.net> '); process.exit(1); } } @@ -37,7 +37,7 @@ var glucose_data = require(cwd + '/' + glucose_input); var enacted_temps = require(cwd + '/' + enacted_temps_input); var iob_data = require(cwd + '/' + iob_input); var requested_temp = require(cwd + '/' + requested_temp_input); -var battery_data = require(cwd +'/' + battery_input); + var data = { bg: glucose_data[0].glucose, @@ -45,9 +45,14 @@ var data = { tick: requested_temp.tick, eventualBG: requested_temp.eventualBG, snoozeBG: requested_temp.snoozeBG, - reason: requested_temp.reason, - battery: battery_data.status+" Voltage:"+battery_data.voltage } + reason: requested_temp.reason + } +if (battery_input) +{ + var battery_data = require(cwd +'/' + battery_input); + data.battery = battery_data.status+" Voltage:"+battery_data.voltage; +} if (!requested_temp.rate && !requested_temp.duration && enacted_temps.recieved) { @@ -55,7 +60,7 @@ data.temp = enacted_temps.temp; data.rate = enacted_temps.rate; data.duration = enacted_temps.duration; data.timestamp = enacted_temps.timestamp; -data.received": enacted_temps.recieved; +data.received = enacted_temps.recieved; } var payload=JSON.stringify(data); @@ -85,3 +90,4 @@ var req = http.request(options, function (res) { req.write(payload); req.end(); + diff --git a/package.json b/package.json index 807e9cd..7276631 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "send-device-status":"./bin/send-device-status.js", "oref0-get-profile": "./bin/oref0-get-profile.js", "oref0-ifttt-notify": "./bin/oref0-ifttt-notify", - "reset-usb": "bin/reset-usb.sh", + "reset-usb": "./bin/reset-usb.sh", "mm-format-ns-glucose": "./bin/mm-format-ns-glucose.sh", "mm-format-ns-pump-history": "./bin/mm-format-ns-pump-history.sh", "oref0": "./bin/oref0.sh", From e9e826ebd39bba6e94263f511db6022870f6143c Mon Sep 17 00:00:00 2001 From: amazaheri Date: Sun, 18 Oct 2015 11:14:50 -0700 Subject: [PATCH 06/10] send-device-status --- bin/send-device-status.js | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 bin/send-device-status.js diff --git a/bin/send-device-status.js b/bin/send-device-status.js new file mode 100644 index 0000000..58de7e7 --- /dev/null +++ b/bin/send-device-status.js @@ -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(); \ No newline at end of file From f73781ed8904b093b91c75d42dfbfa6719a1c9ca Mon Sep 17 00:00:00 2001 From: Ali Mazaheri Date: Sun, 18 Oct 2015 11:41:55 -0700 Subject: [PATCH 07/10] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7276631..c465abb 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "send-device-status":"./bin/send-device-status.js", "oref0-get-profile": "./bin/oref0-get-profile.js", "oref0-ifttt-notify": "./bin/oref0-ifttt-notify", - "reset-usb": "./bin/reset-usb.sh", + "oref0-reset-usb": "./bin/reset-usb.sh", "mm-format-ns-glucose": "./bin/mm-format-ns-glucose.sh", "mm-format-ns-pump-history": "./bin/mm-format-ns-pump-history.sh", "oref0": "./bin/oref0.sh", From 5ae7b0bbf4991ca94ef82dccb3e7ce7e4d259a9c Mon Sep 17 00:00:00 2001 From: Ali Mazaheri Date: Sun, 18 Oct 2015 11:44:00 -0700 Subject: [PATCH 08/10] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c465abb..8ff0fbc 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "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", + "oref0-reset-usb": "bin/reset-usb.sh", "mm-format-ns-glucose": "./bin/mm-format-ns-glucose.sh", "mm-format-ns-pump-history": "./bin/mm-format-ns-pump-history.sh", "oref0": "./bin/oref0.sh", From 4cbd75817a01baafe9c1af4221819487807c0c71 Mon Sep 17 00:00:00 2001 From: amazaheri Date: Sun, 18 Oct 2015 17:34:56 -0700 Subject: [PATCH 09/10] Fixed a bug and add requested_temp.json and battery.json as optional --- bin/send-tempbasal-Azure.js | 50 ++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/bin/send-tempbasal-Azure.js b/bin/send-tempbasal-Azure.js index f1af3d4..e2ad695 100755 --- a/bin/send-tempbasal-Azure.js +++ b/bin/send-tempbasal-Azure.js @@ -23,11 +23,12 @@ if (!module.parent) { var iob_input = process.argv.slice(2, 3).pop() var enacted_temps_input = process.argv.slice(3, 4).pop() var glucose_input = process.argv.slice(4, 5).pop() - var requested_temp_input = process.argv.slice(5, 6).pop() - var battery_input = process.argv.slice(6, 7).pop() - var webapi = process.argv.slice(7, 8).pop() - if (!iob_input || !enacted_temps_input || !glucose_input || !requested_temp_input || !webapi) { - console.log('usage: ', process.argv.slice(0, 2), ' <[your_webapi].azurewebsites.net> '); + 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), ' <[your_webapi].azurewebsites.net> optional: '); process.exit(1); } } @@ -36,31 +37,35 @@ var cwd = process.cwd(); var glucose_data = require(cwd + '/' + glucose_input); var enacted_temps = require(cwd + '/' + enacted_temps_input); var iob_data = require(cwd + '/' + iob_input); -var requested_temp = require(cwd + '/' + requested_temp_input); + var data = { bg: glucose_data[0].glucose, - iob: iob_data.iob, - tick: requested_temp.tick, - eventualBG: requested_temp.eventualBG, - snoozeBG: requested_temp.snoozeBG, - reason: requested_temp.reason - } + iob: iob_data.iob +} -if (battery_input) +if (enacted_temps.rate && enacted_temps.duration && enacted_temps.recieved) { - var battery_data = require(cwd +'/' + battery_input); - data.battery = battery_data.status+" Voltage:"+battery_data.voltage; + data.temp = enacted_temps.temp; + data.rate = enacted_temps.rate; + data.duration = enacted_temps.duration; + data.timestamp = enacted_temps.timestamp; + data.received = enacted_temps.recieved; } -if (!requested_temp.rate && !requested_temp.duration && 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) { -data.temp = enacted_temps.temp; -data.rate = enacted_temps.rate; -data.duration = enacted_temps.duration; -data.timestamp = enacted_temps.timestamp; -data.received = enacted_temps.recieved; + var battery_data = require(cwd +'/' + battery_input); + data.battery = battery_data.status+" Voltage:"+battery_data.voltage; } var payload=JSON.stringify(data); @@ -89,5 +94,4 @@ var req = http.request(options, function (res) { }); req.write(payload); -req.end(); - +req.end(); \ No newline at end of file From 563136c80742869ed257c7bb3465cb5585cc52df Mon Sep 17 00:00:00 2001 From: Ali Mazaheri Date: Mon, 19 Oct 2015 22:51:06 -0700 Subject: [PATCH 10/10] Update send-tempbasal-Azure.js --- bin/send-tempbasal-Azure.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/bin/send-tempbasal-Azure.js b/bin/send-tempbasal-Azure.js index e2ad695..8ea8b64 100755 --- a/bin/send-tempbasal-Azure.js +++ b/bin/send-tempbasal-Azure.js @@ -42,16 +42,12 @@ var iob_data = require(cwd + '/' + iob_input); var data = { bg: glucose_data[0].glucose, - iob: iob_data.iob -} - -if (enacted_temps.rate && enacted_temps.duration && enacted_temps.recieved) -{ - data.temp = enacted_temps.temp; - data.rate = enacted_temps.rate; - data.duration = enacted_temps.duration; - data.timestamp = enacted_temps.timestamp; - data.received = enacted_temps.recieved; + 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){ @@ -94,4 +90,4 @@ var req = http.request(options, function (res) { }); req.write(payload); -req.end(); \ No newline at end of file +req.end();