diff --git a/modules/distribution/pom.xml b/modules/distribution/pom.xml index 8ab050fc..f6cefcfb 100644 --- a/modules/distribution/pom.xml +++ b/modules/distribution/pom.xml @@ -218,7 +218,6 @@ d - diff --git a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_execution/firealarm_execution.siddhiql b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_execution/firealarm_execution.siddhiql index 5ae92acf..4f677bb4 100644 --- a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_execution/firealarm_execution.siddhiql +++ b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_execution/firealarm_execution.siddhiql @@ -6,19 +6,19 @@ /* define streams/tables and write queries here ... */ +@Import('org.wso2.iot.firealarm:1.0.0') +define stream firealarm (meta_owner string, meta_deviceId string, temperature float, humidity float); + @Export('org.wso2.iot.devices.temperature:1.0.0') define stream temperature (meta_owner string, meta_deviceType string, meta_deviceId string, meta_time long, temperature float); @Export('org.wso2.iot.devices.humidity:1.0.0') define stream humidity (meta_owner string, meta_deviceType string, meta_deviceId string, meta_time long, humidity float); -@Import('org.wso2.iot.firealarm:1.0.0') -define stream firealarm (meta_owner string, meta_deviceId string, meta_type string, temperature float, humidity float); - -from firealarm[meta_type == 'temperature'] +from firealarm select meta_owner, 'firealarm' as meta_deviceType, meta_deviceId, time:timestampInMilliseconds() as meta_time, temperature insert into temperature; -from firealarm[meta_type == 'humidity'] +from firealarm select meta_owner, 'firealarm' as meta_deviceType, meta_deviceId, time:timestampInMilliseconds() as meta_time, humidity -insert into humidity; +insert into humidity; \ No newline at end of file diff --git a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_stream/org.wso2.iot.firealarm_1.0.0.json b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_stream/org.wso2.iot.firealarm_1.0.0.json index 643d4d8e..3ed80873 100644 --- a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_stream/org.wso2.iot.firealarm_1.0.0.json +++ b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/firealarm/firealarm_stream/org.wso2.iot.firealarm_1.0.0.json @@ -5,8 +5,7 @@ "description": "This hold the device type stream of firealarm", "metaData": [ {"name": "owner", "type": "STRING"}, - {"name": "deviceId", "type": "STRING"}, - {"name": "type", "type": "STRING"} + {"name": "deviceId", "type": "STRING"} ], "payloadData": [ {"name": "temperature", "type": "FLOAT"}, diff --git a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/humidity_sensor/artifacts.xml b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/humidity_sensor/artifacts.xml index 6f582eb6..b02295df 100644 --- a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/humidity_sensor/artifacts.xml +++ b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/humidity_sensor/artifacts.xml @@ -22,7 +22,6 @@ - diff --git a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/humidity_sensor/humidity_publisher/artifact.xml b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/humidity_sensor/humidity_publisher/artifact.xml deleted file mode 100644 index a2183a4a..00000000 --- a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/humidity_sensor/humidity_publisher/artifact.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - humidity_publisher.xml - diff --git a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/humidity_sensor/humidity_publisher/humidity_publisher.xml b/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/humidity_sensor/humidity_publisher/humidity_publisher.xml deleted file mode 100644 index 7ae12b16..00000000 --- a/modules/samples/firealarm/component/analytics/src/main/resources/carbonapps/humidity_sensor/humidity_publisher/humidity_publisher.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - diff --git a/modules/samples/firealarm/component/api/src/main/java/org/homeautomation/firealarm/api/DeviceTypeServiceImpl.java b/modules/samples/firealarm/component/api/src/main/java/org/homeautomation/firealarm/api/DeviceTypeServiceImpl.java index b3e53c7f..37498bc8 100644 --- a/modules/samples/firealarm/component/api/src/main/java/org/homeautomation/firealarm/api/DeviceTypeServiceImpl.java +++ b/modules/samples/firealarm/component/api/src/main/java/org/homeautomation/firealarm/api/DeviceTypeServiceImpl.java @@ -159,16 +159,27 @@ public class DeviceTypeServiceImpl implements DeviceTypeService { @QueryParam("from") long from, @QueryParam("to") long to) { String fromDate = String.valueOf(from); String toDate = String.valueOf(to); - String query = "meta_deviceId:" + deviceId + " AND meta_deviceType:" + - DeviceTypeConstants.DEVICE_TYPE + " AND meta_time : [" + fromDate + " TO " + toDate + "]"; - String sensorTableName = DeviceTypeConstants.SENSOR_EVENT_TABLE_PREFIX + sensorName; + String query = "deviceId:" + deviceId + " AND deviceType:" + + DeviceTypeConstants.DEVICE_TYPE + " AND time : [" + fromDate + " TO " + toDate + "]"; + String sensorTableName; + switch (sensorName) { + case DeviceTypeConstants.STREAM_TEMPERATURE: + sensorTableName = DeviceTypeConstants.TEMPERATURE_EVENT_TABLE; + break; + case DeviceTypeConstants.STREAM_HUMIDITY: + sensorTableName = DeviceTypeConstants.HUMIDITY_EVENT_TABLE; + break; + default: + return Response.status(Response.Status.BAD_REQUEST).entity("Invalid event stream").build(); + } + try { if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(new DeviceIdentifier(deviceId, DeviceTypeConstants.DEVICE_TYPE))) { return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build(); } List sortByFields = new ArrayList<>(); - SortByField sortByField = new SortByField("meta_time", SORT.ASC, false); + SortByField sortByField = new SortByField("time", SORT.ASC, false); sortByFields.add(sortByField); List sensorRecords = APIUtil.getAllEventsForDevice(sensorTableName, query, sortByFields); return Response.status(Response.Status.OK.getStatusCode()).entity(sensorRecords).build(); diff --git a/modules/samples/firealarm/component/plugin/src/main/java/org/homeautomation/firealarm/plugin/constants/DeviceTypeConstants.java b/modules/samples/firealarm/component/plugin/src/main/java/org/homeautomation/firealarm/plugin/constants/DeviceTypeConstants.java index 1d7d1f24..00c3361a 100644 --- a/modules/samples/firealarm/component/plugin/src/main/java/org/homeautomation/firealarm/plugin/constants/DeviceTypeConstants.java +++ b/modules/samples/firealarm/component/plugin/src/main/java/org/homeautomation/firealarm/plugin/constants/DeviceTypeConstants.java @@ -29,7 +29,11 @@ public class DeviceTypeConstants { public final static String STATE_OFF = "OFF"; //sensor events summerized table name - public static final String SENSOR_EVENT_TABLE_PREFIX = "ORG_WSO2_IOT_DEVICES_"; + public final static String STREAM_TEMPERATURE = "temperature"; + public final static String STREAM_HUMIDITY = "humidity"; + public final static String TEMPERATURE_EVENT_TABLE = "DEVICE_TEMPERATURE_SUMMARY"; + public final static String HUMIDITY_EVENT_TABLE = "DEVICE_HUMIDITY_SUMMARY"; + public static final String DATA_SOURCE_NAME = "jdbc/firealarmDM_DB"; public final static String DEVICE_TYPE_PROVIDER_DOMAIN = "carbon.super"; diff --git a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.analytics-view/analytics-view.hbs b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.analytics-view/analytics-view.hbs index 971893e8..91af2442 100644 --- a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.analytics-view/analytics-view.hbs +++ b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.analytics-view/analytics-view.hbs @@ -15,10 +15,10 @@ specific language governing permissions and limitations under the License. }} - -
+
Temperature
diff --git a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.analytics-view/analytics-view.js b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.analytics-view/analytics-view.js index cc651dad..299a5b13 100644 --- a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.analytics-view/analytics-view.js +++ b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.analytics-view/analytics-view.js @@ -24,7 +24,7 @@ function onRequest(context) { if (devices) { return { "devices": stringify(devices), - "backendApiUri": devicemgtProps["httpsURL"] + "/firealarm/stats/" + "backendApiUri": devicemgtProps["httpsURL"] + "/firealarm/device/stats/" }; } else if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) { var deviceModule = require("/app/modules/device.js").deviceModule; @@ -32,7 +32,7 @@ function onRequest(context) { if (device && device.status != "error") { return { "device": device, - "backendApiUrl": devicemgtProps["httpsURL"] + "/firealarm/stats/" + deviceId + "/sensors/" + "backendApiUrl": devicemgtProps["httpsURL"] + "/firealarm/device/stats/" + deviceId + "/sensors/" }; } else { response.sendError(404, "Device Id " + deviceId + " of type " + deviceType + " cannot be found!"); diff --git a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.analytics-view/public/js/firealarm.js b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.analytics-view/public/js/firealarm.js index 7e643c31..af8e0c4c 100644 --- a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.analytics-view/public/js/firealarm.js +++ b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.analytics-view/public/js/firealarm.js @@ -26,6 +26,7 @@ function drawGraph_firealarm(from, to) { var streamIndex = 0; var streams = ["temperature", "humidity"]; + populateGraph(); function populateGraph() { retrieveDataAndDrawLineGraph(streams[streamIndex], from, to); @@ -167,7 +168,6 @@ function drawGraph_firealarm(from, to) { }; invokerUtil.get(backendApiUrl, successCallback, function (message) { console.log(message); - populateGraph(); }); } diff --git a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.realtime.analytics-view/analytics-view.hbs b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.realtime.analytics-view/analytics-view.hbs index 94422646..2967d0cf 100644 --- a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.realtime.analytics-view/analytics-view.hbs +++ b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.realtime.analytics-view/analytics-view.hbs @@ -22,20 +22,12 @@
Temperature
-
-
-
-
Time
Humidity
-
-
-
-
Time
diff --git a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.realtime.analytics-view/public/js/device-stats.js b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.realtime.analytics-view/public/js/device-stats.js index 29ad42cf..d7299ad9 100644 --- a/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.realtime.analytics-view/public/js/device-stats.js +++ b/modules/samples/firealarm/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.firealarm.realtime.analytics-view/public/js/device-stats.js @@ -58,7 +58,7 @@ function lineGraph(type, chartData) { series: [{ 'color': palette.color(), 'data': chartData, - 'name': type + 'name': type && type[0].toUpperCase() + type.slice(1) }] }); @@ -75,22 +75,17 @@ function lineGraph(type, chartData) { orientation: 'left', height: 300, tickFormat: Rickshaw.Fixtures.Number.formatKMBT, - element: document.getElementById('y_axis') + element: document.getElementById('y_axis-' + type) }); - new Rickshaw.Graph.Legend({ - graph: graph, - element: document.getElementById('legend-' + type) - }); - - new Rickshaw.Graph.HoverDetail({ - graph: graph, - formatter: function (series, x, y) { - var date = '' + moment(x * 1000).format('Do MMM YYYY h:mm:ss a') + ''; - var swatch = ''; - return swatch + series.name + ": " + parseInt(y) + '
' + date; - } - }); + new Rickshaw.Graph.HoverDetail({ + graph: graph, + formatter: function (series, x, y) { + var date = '' + moment(x * 1000).format('Do MMM YYYY h:mm:ss a') + ''; + var swatch = ''; + return swatch + series.name + ": " + parseInt(y) + '
' + date; + } + }); return graph; } @@ -108,9 +103,9 @@ function connect(target) { ws.onmessage = function (event) { var dataPoint = JSON.parse(event.data); if (dataPoint) { - var time = parseInt(dataPoint[4]) / 1000; - graphUpdate(temperatureData, time, dataPoint[5], temperature); - graphUpdate(humidityData, time, dataPoint[6], humidity); + var time = parseInt(dataPoint[0]) / 1000; + graphUpdate(temperatureData, time, dataPoint[3], temperature); + graphUpdate(humidityData, time, dataPoint[4], humidity); } }; } @@ -125,15 +120,6 @@ function graphUpdate(chartData, xValue, yValue, graph) { graph.update(); } -function dataUpdate(chartData, xValue, yValue) { - chartData.push({ - x: parseInt(xValue), - y: parseFloat(yValue) - }); - chartData.shift(); -} - - function disconnect() { if (ws != null) { ws.close(); diff --git a/modules/samples/firealarm/feature/feature/src/main/resources/agent/read-sensor.lua b/modules/samples/firealarm/feature/feature/src/main/resources/agent/read-sensor.lua index 1cea5351..d039bc93 100644 --- a/modules/samples/firealarm/feature/feature/src/main/resources/agent/read-sensor.lua +++ b/modules/samples/firealarm/feature/feature/src/main/resources/agent/read-sensor.lua @@ -16,7 +16,7 @@ tmr.alarm(0, 10000, 1, function() print("Error reading from DHTxx") else if (client_connected) then - local payload = "{event:{metaData:{owner:\"${DEVICE_OWNER}\",type:\"firealarm\",deviceId:\"${DEVICE_ID}\"},payloadData:{temperature:" .. t .. ", humidity:" .. h .. "}}}" + local payload = "{event:{metaData:{owner:\"${DEVICE_OWNER}\",deviceId:\"${DEVICE_ID}\"},payloadData:{temperature:" .. t .. ", humidity:" .. h .. "}}}" m:publish("carbon.super/firealarm/${DEVICE_ID}/data", payload, 0, 0, function(client) print("Published> Temperature: " .. t .. "C Humidity: " .. h .. "%") end)