diff --git a/modules/distribution/src/repository/jaggeryapps/iot/api/device-api.jag b/modules/distribution/src/repository/jaggeryapps/iot/api/device-api.jag index 00bea457..e8a48ea0 100644 --- a/modules/distribution/src/repository/jaggeryapps/iot/api/device-api.jag +++ b/modules/distribution/src/repository/jaggeryapps/iot/api/device-api.jag @@ -24,8 +24,10 @@ var log = new Log("api/device-api.jag"); var constants = require("/modules/constants.js"); var dcProps = require('/config/dc-props.js').config(); -var downloadModule = require("/modules/download.js").downloadModule; -var utility = require("/modules/utility.js").utility; + +var carbon = require('carbon'); +var carbonHttpServletTransport = carbon.server.address('http'); +var carbonHttpsServletTransport = carbon.server.address('https'); var result; @@ -39,12 +41,33 @@ if (uriMatcher.match("/{context}/api/device/sketch/")) { exit(); } - fireAlarmManagerService = "http://localhost:9763/iotdevices/FireAlarmManager"; + fireAlarmManagerService = carbonHttpsServletTransport + "/iotdevices/FireAlarmManager"; sketchDownloadEndPoint = fireAlarmManagerService + "/downloadSketch"; response.sendRedirect(sketchDownloadEndPoint + "?type="+sketchType+"&owner="+user.username); exit(); } +if (uriMatcher.match("/{context}/api/devices/")) { + + var constants = require("/modules/constants.js"); + + var user = session.get(constants.USER_SESSION_KEY); + if(!user){ + response.sendRedirect(dcProps.appContext + "login?#login-required"); + exit(); + } + + devicesManagerService = carbonHttpsServletTransport + "/iotdevices/DevicesManager"; + listAllDevicesEndPoint = devicesManagerService + "/getDevices"; + + var data = {}; + //XMLHTTPRequest's GET + result = get(listAllDevicesEndPoint+"?username="+user.username, data ,"json"); + + //response.sendRedirect(listAllDevicesEndPoint + "?username="+user.username); + //exit(); +} + // returning the result. if (result) { print(result); diff --git a/modules/distribution/src/repository/jaggeryapps/iot/api/stats-api.jag b/modules/distribution/src/repository/jaggeryapps/iot/api/stats-api.jag index 984946fd..3b97d5dc 100644 --- a/modules/distribution/src/repository/jaggeryapps/iot/api/stats-api.jag +++ b/modules/distribution/src/repository/jaggeryapps/iot/api/stats-api.jag @@ -80,11 +80,14 @@ function getBulbStatusData(user, deviceId, from, to) { var bulbStatusData = []; - for (var i = 0; i < fetchedData.size(); i++) { - bulbStatusData.push({ - time: fetchedData.get(i).getTime(), - value: fetchedData.get(i).getValue() - }); + if(fetchedData != null) { + + for (var i = 0; i < fetchedData.size(); i++) { + bulbStatusData.push({ + time: fetchedData.get(i).getTime(), + value: fetchedData.get(i).getValue() + }); + } } return bulbStatusData; @@ -97,11 +100,15 @@ function getFanStatusData(user, deviceId, from, to) { var fanStatusData = []; - for (var i = 0; i < fetchedData.size(); i++) { - fanStatusData.push({ - time: fetchedData.get(i).getTime(), - value: fetchedData.get(i).getValue() - }); + if(fetchedData != null) { + + for (var i = 0; i < fetchedData.size(); i++) { + fanStatusData.push({ + time: fetchedData.get(i).getTime(), + value: fetchedData.get(i).getValue() + }); + + } } return fanStatusData; @@ -113,13 +120,16 @@ function getTemperatureData(user, deviceId, from, to) { var temperatureData = []; - for (var i = 0; i < fetchedData.size(); i++) { - temperatureData.push({ - time: fetchedData.get(i).getTime(), - value: fetchedData.get(i).getValue() - }); - } + if(fetchedData != null) { + + for (var i = 0; i < fetchedData.size(); i++) { + temperatureData.push({ + time: fetchedData.get(i).getTime(), + value: fetchedData.get(i).getValue() + }); + } + } return temperatureData; } diff --git a/modules/distribution/src/repository/jaggeryapps/iot/jaggery.conf b/modules/distribution/src/repository/jaggeryapps/iot/jaggery.conf index 04c29bf3..9d723c35 100644 --- a/modules/distribution/src/repository/jaggeryapps/iot/jaggery.conf +++ b/modules/distribution/src/repository/jaggeryapps/iot/jaggery.conf @@ -11,6 +11,10 @@ "url": "/api/device/*", "path": "/api/device-api.jag" }, + { + "url": "/api/devices/*", + "path": "/api/device-api.jag" + }, { "url": "/api/user/*", "path": "/api/user-api.jag" diff --git a/modules/distribution/src/repository/jaggeryapps/iot/units/alldevices/alldevices.hbs b/modules/distribution/src/repository/jaggeryapps/iot/units/alldevices/alldevices.hbs index 78eda2be..0887dd0f 100644 --- a/modules/distribution/src/repository/jaggeryapps/iot/units/alldevices/alldevices.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iot/units/alldevices/alldevices.hbs @@ -10,7 +10,8 @@
"+deviceIdentifier+" | "+ + ""+deviceName+" | "+ + ""+ + ""+ + ""+ + ""+ + " |
---|