Merge pull request #85 from NuwanSameera/master

Add flow sensor to currentsensor device type and modify device view page
application-manager-new
Charitha Goonetilleke 9 years ago
commit 95b3396a66

@ -25,6 +25,7 @@
<property name="Current_dir" value="Current"/>
<property name="Power_Sensor_dir" value="Power_Sensor"/>
<property name="Flow_Sensor_dir" value="Flow_Sensor"/>
<target name="clean">
<delete dir="${target-dir}" />
@ -38,6 +39,9 @@
<zip destfile="${target-dir}/${Power_Sensor_dir}.car">
<zipfileset dir="${src-dir}/${Power_Sensor_dir}"/>
</zip>
<zip destfile="${target-dir}/${Flow_Sensor_dir}.car">
<zipfileset dir="${src-dir}/${Flow_Sensor_dir}"/>
</zip>
</target>
</project>

@ -0,0 +1,27 @@
<?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.
-->
<eventReceiver name="EventReceiver_flowrate" statistics="disable" trace="disable"
xmlns="http://wso2.org/carbon/eventreceiver">
<from eventAdapterType="wso2event">
<property name="events.duplicated.in.cluster">false</property>
</from>
<mapping customMapping="disable" type="wso2event"/>
<to streamName="org.wso2.iot.devices.flowrate" version="1.0.0"/>
</eventReceiver>

@ -0,0 +1,22 @@
<?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="Eventreceiver_flowrate" version="1.0.0" type="event/receiver" serverRole="DataAnalyticsServer">
<file>EventReceiver_flowrate.xml</file>
</artifact>

@ -0,0 +1,22 @@
<?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="Eventstore_flowrate" version="1.0.0" type="analytics/eventstore" serverRole="DataAnalyticsServer">
<file>org_wso2_iot_devices_flowrate.xml</file>
</artifact>

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
~ 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.
-->
<EventStoreConfiguration>
<Source>
<StreamId>org.wso2.iot.devices.flowrate:1.0.0</StreamId>
</Source>
<RecordStoreName>EVENT_STORE</RecordStoreName>
<TableSchema>
<ColumnDefinition>
<Name>meta_owner</Name>
<EnableIndexing>true</EnableIndexing>
<IsPrimaryKey>true</IsPrimaryKey>
<EnableScoreParam>false</EnableScoreParam>
<Type>STRING</Type>
</ColumnDefinition>
<ColumnDefinition>
<Name>meta_deviceType</Name>
<EnableIndexing>true</EnableIndexing>
<IsPrimaryKey>true</IsPrimaryKey>
<EnableScoreParam>false</EnableScoreParam>
<Type>STRING</Type>
</ColumnDefinition>
<ColumnDefinition>
<Name>meta_deviceId</Name>
<EnableIndexing>true</EnableIndexing>
<IsPrimaryKey>true</IsPrimaryKey>
<EnableScoreParam>false</EnableScoreParam>
<Type>STRING</Type>
</ColumnDefinition>
<ColumnDefinition>
<Name>meta_time</Name>
<EnableIndexing>true</EnableIndexing>
<IsPrimaryKey>true</IsPrimaryKey>
<EnableScoreParam>false</EnableScoreParam>
<Type>LONG</Type>
</ColumnDefinition>
<ColumnDefinition>
<Name>flowrate</Name>
<EnableIndexing>false</EnableIndexing>
<IsPrimaryKey>false</IsPrimaryKey>
<EnableScoreParam>false</EnableScoreParam>
<Type>FLOAT</Type>
</ColumnDefinition>
</TableSchema>
</EventStoreConfiguration>

@ -0,0 +1,22 @@
<?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="Eventstream_flowrate" version="1.0.0" type="event/stream" serverRole="DataAnalyticsServer">
<file>org.wso2.iot.devices.flowrate_1.0.0.json</file>
</artifact>

@ -0,0 +1,17 @@
{
"name": "org.wso2.iot.devices.flowrate",
"version": "1.0.0",
"nickName": "Flow Rate Data",
"description": "Flow Rate data received from the Device",
"metaData": [
{"name":"owner","type":"STRING"},
{"name":"deviceType","type":"STRING"},
{"name":"deviceId","type":"STRING"},
{"name":"time","type":"LONG"}
],
"payloadData": [
{
"name": "flowrate","type": "FLOAT"
}
]
}

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
~ 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.
-->
<Analytics>
<Name>Flow_Sensor_Script</Name>
<Script>
CREATE TEMPORARY TABLE DeviceFlowRateData USING CarbonAnalytics OPTIONS(tableName
"ORG_WSO2_IOT_DEVICES_FLOWRATE");
CREATE TEMPORARY TABLE DeviceFlowRateSummaryData USING CarbonAnalytics OPTIONS (tableName
"DEVICE_FLOWRATE_SUMMARY", schema "flowrate FLOAT, deviceType STRING -i, deviceId STRING -i, owner
STRING -i,
time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
insert overwrite table DeviceFlowRateSummaryData select flowrate, meta_deviceType as deviceType,
meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from
DeviceFlowRateData group by flowrate, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as
BIGINT);
</Script>
<CronExpression>0 * * * * ?</CronExpression>
</Analytics>

@ -0,0 +1,22 @@
<?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="Sparkscripts" version="1.0.0" type="analytics/spark" serverRole="DataAnalyticsServer">
<file>Flow_Sensor_Script.xml</file>
</artifact>

@ -0,0 +1,30 @@
<?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.
-->
<artifacts>
<artifact name="Flow_Rate_CAPP" version="1.0.0" type="carbon/application">
<dependency artifact="Eventstream_flowrate" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
<dependency artifact="Eventstore_flowrate" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
<dependency artifact="Eventreceiver_flowrate" version="1.0.0" include="true"
serverRole="DataAnalyticsServer"/>
<dependency artifact="Sparkscripts" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
</artifact>
</artifacts>

@ -116,6 +116,36 @@ public class CurrentSensorControllerService {
return sensorRecord;
}
/**
* @param owner
* @param deviceId
* @param protocol
* @param response
* @return
*/
@Path("controller/read-flowrate")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Feature( code="read-flowrate", name="Flow Rate x100", type="monitor",
description="Request flow rate reading from Arduino agent")
public SensorRecord requestFlowRate(@HeaderParam("owner") String owner,
@HeaderParam("deviceId") String deviceId,
@HeaderParam("protocol") String protocol,
@Context HttpServletResponse response) {
SensorRecord sensorRecord = null;
try {
sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId,
CurrentSensorConstants.SENSOR_FLOWRATE);
} catch ( DeviceControllerException e) {
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
response.setStatus(Response.Status.OK.getStatusCode());
return sensorRecord;
}
/**
* @param dataMsg
* @param response
@ -150,4 +180,29 @@ public class CurrentSensorControllerService {
}
}
/**
* @param dataMsg
* @param response
*/
@Path("controller/pushflowrate")
@POST
@Consumes(MediaType.APPLICATION_JSON)
public void pushFlowRate(final DeviceJSON dataMsg, @Context HttpServletResponse response) {
String owner = dataMsg.owner;
String deviceId = dataMsg.deviceId;
float pinData = dataMsg.value / 100;
SensorDataManager.getInstance().setSensorRecord(deviceId, CurrentSensorConstants.SENSOR_FLOWRATE,
String.valueOf(pinData),
Calendar.getInstance().getTimeInMillis());
if (!CurrentSensorServiceUtils.publishToDASFlowRate(dataMsg.owner, dataMsg.deviceId, pinData)) {
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
log.warn("An error occured whilst trying to publish pin data of Current Sensor Data with ID [" + deviceId +
"] of owner [" + owner + "]");
}
}
}

@ -32,6 +32,7 @@ public class CurrentSensorServiceUtils {
private static final String SUPER_TENANT = "carbon.super";
private static final String CURRENT_STREAM_DEFINITION = "org.wso2.iot.devices.current";
private static final String POWER_STREAM_DEFINITION = "org.wso2.iot.devices.power";
private static final String FLOWRATE_STREAM_DEFINITION = "org.wso2.iot.devices.flowrate";
public static boolean publishToDASCurrent(String owner, String deviceId, float current) {
PrivilegedCarbonContext.startTenantFlow();
@ -70,4 +71,24 @@ public class CurrentSensorServiceUtils {
}
return true;
}
public static boolean publishToDASFlowRate(String owner, String deviceId, float flowRate) {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
ctx.setTenantDomain(SUPER_TENANT, true);
DeviceAnalyticsService deviceAnalyticsService = (DeviceAnalyticsService) ctx.getOSGiService(
DeviceAnalyticsService.class, null);
Object metdaData[] = {owner, CurrentSensorConstants.DEVICE_TYPE, deviceId, System.currentTimeMillis()};
Object payload[] = {flowRate};
try {
deviceAnalyticsService.publishEvent(FLOWRATE_STREAM_DEFINITION, "1.0.0", metdaData, new Object[0], payload);
} catch (DataPublisherConfigurationException e) {
return false;
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
return true;
}
}

@ -25,5 +25,6 @@ public class CurrentSensorConstants {
public final static String DEVICE_PLUGIN_DEVICE_ID = "CURRENT_SENSOR_DEVICE_ID";
public final static String SENSOR_CURRENT = "current";
public final static String SENSOR_POWER = "power";
public final static String SENSOR_FLOWRATE = "flowrate";
public static final String DATA_SOURCE_NAME = "jdbc/currentsensorDM_DB";
}

@ -16,21 +16,28 @@
<h3 class="uppercase">What it Does</h3>
<hr>
<p class="grey margin-top">Connect a Current Sensor to WSO2 IoT Server and manage
it.</p>
<p class="grey margin-top">Connect a Current Sensor and Flow Sensor to WSO2 IoT Server and visualize sensor
data.</p>
<br>
<h3 class="uppercase">What You Need</h3>
<hr>
<ul class="list-unstyled">
<li class="padding-top-double"><span class="circle">ITEM 01</span>&nbsp;&nbsp;&nbsp;Raspberry
Pi with SD Card(Internet
Enabled [Wifi or Ethernet]).
<li class="padding-top-double"><span class="circle">ITEM 01</span>&nbsp;&nbsp;&nbsp;Arduino board with wifi
shield.
</li>
<li class="padding-top-double"><span class="circle">ITEM 02</span>&nbsp;&nbsp;&nbsp;A Digital Display with HDMI
Cable.
<li class="padding-top-double"><span class="circle">ITEM 02</span>&nbsp;&nbsp;&nbsp;Non-Invasive Current
Sensor - 30A.
</li>
<li class="padding-top-double"><span class="circle">STEP 03</span>&nbsp;&nbsp;&nbsp;Proceed
<li class="padding-top-double"><span class="circle">ITEM 02</span>&nbsp;&nbsp;&nbsp;Flow sensor.
</li>
<li class="padding-top-double"><span class="circle">ITEM 03</span>&nbsp;&nbsp;&nbsp;A 100 ohm resister.
</li>
<li class="padding-top-double"><span class="circle">ITEM 04</span>&nbsp;&nbsp;&nbsp;Two 10 kohm resisters.
</li>
<li class="padding-top-double"><span class="circle">ITEM 05</span>&nbsp;&nbsp;&nbsp;A 100uf capacitor.
</li>
<li class="padding-top-double"><span class="circle">STEP 06</span>&nbsp;&nbsp;&nbsp;Proceed
to [Prepare] section.
</ul>
<br>
@ -60,7 +67,6 @@
</div>
<div class="buttons" style="padding-bottom: 0px">
<a class="btn btn-operations" onclick="downloadAgent()">Download Now</a> &nbsp;&nbsp;
<a href="#" id="download-device-download-link" class="btn btn-operations"> Copy Link </a>
&nbsp;&nbsp;
</div>
</form>
@ -175,20 +181,38 @@
<h3 class="uppercase">Prepare</h3>
<hr>
<ul class="list-unstyled">
<li class="padding-top-double"><span class="circle">01</span>&nbsp;&nbsp;&nbsp;Connect a monitor to your
RaspberryPi via HDMI cable.
<li class="padding-top-double"><span class="circle">01</span>&nbsp;&nbsp;&nbsp;Make a circuit shown in
schematic view and connect analog out put to arduino.(analog input pin 0)
</li>
<li class="padding-top-double"><span class="circle">02</span>&nbsp;&nbsp;&nbsp;Configure
RaspberryPi to connect
to the Internet.
<li class="padding-top-double"><span class="circle">02</span>&nbsp;&nbsp;&nbsp;Connect flow sensor to arduino.
(analog input pin 1)
</li>
<li class="padding-top-double"><span class="circle">03</span>&nbsp;&nbsp;&nbsp;Go ahead and [Download Agent] the
Digital Display Agent.
Current sensor Agent.
</li>
<li class="padding-top-double"><span class="circle">04</span>&nbsp;&nbsp;&nbsp;Unzip downloaded agent.
</li>
<li class="padding-top-double"><span class="circle">05</span>&nbsp;&nbsp;&nbsp;Start Agent by running
installpackages.sh followed by wso2Agent.sh
<li class="padding-top-double"><span class="circle">05</span>&nbsp;&nbsp;&nbsp;Create a folder called
"CurrentSensor" and move all source files inside.
</li>
<li class="padding-top-double"><span class="circle">06</span>&nbsp;&nbsp;&nbsp;Open CurrentSensor.h and
provide appropriate values for [WLAN_SSID],[WLAN_PASS],[SERVICE_PORT],[server] and [deviceIP] variables
according to your network.
</li>
<li class="padding-top-double">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span class="fw-stack fw-lg margin-right">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-right-arrow fw-stack-1x"></i>
</span>
&nbsp;&nbsp;&nbsp;Arduino will publish Current sensor reading to WSO2-IoT-Server.
<br/><br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span class="fw-stack fw-lg margin-right">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-right-arrow fw-stack-1x"></i>
</span>
&nbsp;&nbsp;&nbsp;Arduino will publish Flow sensor reading to WSO2-IoT-Server.
</li>
</ul>
<br>

@ -51,8 +51,8 @@ void loop()
}
if(millis() - pushTimestamp > PUSH_INTERVAL){
while (!client.connected()) {
setupClient();
if (!client.connected()) {
wdt_reset();
}
pushData();

@ -25,6 +25,17 @@
{"column": {"name":"POWER", "label":"power", "ui-mapping":"y-axis"}}
]
}
},
{
"name": "Flow Rate x100",
"table": "DEVICE_FLOWRATE_SUMMARY",
"ui_unit": {
"name": "cdmf.unit.analytics.line-chart",
"data":[
{"column": {"name":"TIME", "label":"time", "ui-mapping":"x-axis"}},
{"column": {"name":"FlowRate", "label":"flowrate", "ui-mapping":"y-axis"}}
]
}
}
]
}
Loading…
Cancel
Save