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 diff --git a/bin/send-tempbasal-Azure.js b/bin/send-tempbasal-Azure.js index 32b6038..8ea8b64 100755 --- a/bin/send-tempbasal-Azure.js +++ b/bin/send-tempbasal-Azure.js @@ -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), ' <[your_webapi].azurewebsites.net>'); + console.log('usage: ', process.argv.slice(0, 2), ' <[your_webapi].azurewebsites.net> optional: '); process.exit(1); } } @@ -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, @@ -56,7 +73,7 @@ var options = { method: 'POST', headers: { 'Content-Type': 'application/json; charset=utf-8', - 'Content-Length': data.length + 'Content-Length': payload.length } }; @@ -72,5 +89,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 8a42f86..879edef 100644 --- a/package.json +++ b/package.json @@ -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",