Fix bugs in generated firealarm plugin

application-manager-new
charitha 9 years ago
parent 6d530d684e
commit 5a463e4194

@ -218,7 +218,6 @@ d <exclude name="**/shindig.properties" /
<exclude name="**/digitaldisplay/**" />
<exclude name="**/doormanager/**" />
<exclude name="**/droneanalyzer/**" />
<exclude name="**/firealarm/**" />
<exclude name="**/installer/**" />
</fileset>
</copy>

@ -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;

@ -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"},

@ -22,7 +22,6 @@
<dependency artifact="humidity_stream" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
<dependency artifact="humidity_store" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
<dependency artifact="humidity_receiver" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
<dependency artifact="humidity_publisher" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
<dependency artifact="humidity_script" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
</artifact>
</artifacts>

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<artifact name="humidity_publisher" version="1.0.0" type="event/publisher" serverRole="DataAnalyticsServer">
<file>humidity_publisher.xml</file>
</artifact>

@ -1,25 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ WSO2 Inc. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<eventPublisher name="humidity_publisher" statistics="disable" trace="disable" xmlns="http://wso2.org/carbon/eventpublisher">
<from streamName="org.wso2.iot.devices.humidity" version="1.0.0"/>
<mapping customMapping="disable" type="wso2event"/>
<to eventAdapterType="iot-ui"/>
</eventPublisher>

@ -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<SortByField> sortByFields = new ArrayList<>();
SortByField sortByField = new SortByField("meta_time", SORT.ASC, false);
SortByField sortByField = new SortByField("time", SORT.ASC, false);
sortByFields.add(sortByField);
List<SensorRecord> sensorRecords = APIUtil.getAllEventsForDevice(sensorTableName, query, sortByFields);
return Response.status(Response.Status.OK.getStatusCode()).entity(sensorRecords).build();

@ -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";

@ -15,10 +15,10 @@
specific language governing permissions and limitations
under the License.
}}
<span id="humidity-details" data-devices="{{devices}}" data-devicename="{{device.name}}"
<span id="firealarm-details" data-devices="{{devices}}" data-devicename="{{device.name}}"
data-deviceid="{{device.deviceIdentifier}}"
data-appcontext="{{@app.context}}"></span>
<div id="humidity-div-chart" data-backend-api-url= {{backendApiUrl}}>
<div id="firealarm-div-chart" data-backend-api-url= {{backendApiUrl}}>
<div class="chartWrapper" id="chartWrapper-temperature">
<span id="span-title">Temperature</span>
<div id="y_axis-temperature" class="custom_y_axis"></div>

@ -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!");

@ -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();
});
}

@ -22,20 +22,12 @@
<div id="div-chart" data-websocketurl="{{websocketEndpoint}}">
<div id="chartWrapper-temperature" class="chartWrapper">
<div id="y_axis-temperature" class="custom_y_axis" style="margin-top: -20px;">Temperature</div>
<div class="legend_container-temperature">
<div id="smoother-temperature" title="Smoothing"></div>
<div id="legend-temperature"></div>
</div>
<div id="chart-temperature" class="custom_rickshaw_graph"></div>
<div class="custom_x_axis">Time</div>
</div>
<div id="chartWrapper-humidity" class="chartWrapper">
<div id="y_axis-humidity" class="custom_y_axis" style="margin-top: -20px;">Humidity</div>
<div class="legend_container-humidity">
<div id="smoother-humidity" title="Smoothing"></div>
<div id="legend-humidity"></div>
</div>
<div id="chart-humidity" class="custom_rickshaw_graph"></div>
<div class="custom_x_axis">Time</div>
</div>

@ -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 = '<span class="date">' + moment(x * 1000).format('Do MMM YYYY h:mm:ss a') + '</span>';
var swatch = '<span class="detail_swatch" style="background-color: ' + series.color + '"></span>';
return swatch + series.name + ": " + parseInt(y) + '<br>' + date;
}
});
new Rickshaw.Graph.HoverDetail({
graph: graph,
formatter: function (series, x, y) {
var date = '<span class="date">' + moment(x * 1000).format('Do MMM YYYY h:mm:ss a') + '</span>';
var swatch = '<span class="detail_swatch" style="background-color: ' + series.color + '"></span>';
return swatch + series.name + ": " + parseInt(y) + '<br>' + 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();

@ -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)

Loading…
Cancel
Save