diff --git a/modules/samples/currentsensor/component/analytics/build.xml b/modules/samples/currentsensor/component/analytics/build.xml
index 797d7cf9..4a78c8fd 100644
--- a/modules/samples/currentsensor/component/analytics/build.xml
+++ b/modules/samples/currentsensor/component/analytics/build.xml
@@ -25,6 +25,7 @@
+
@@ -38,6 +39,9 @@
+
+
+
diff --git a/modules/samples/currentsensor/component/analytics/src/main/resources/carbonapps/Flow_Sensor/Eventreceiver_flowrate_1.0.0/EventReceiver_flowrate.xml b/modules/samples/currentsensor/component/analytics/src/main/resources/carbonapps/Flow_Sensor/Eventreceiver_flowrate_1.0.0/EventReceiver_flowrate.xml
new file mode 100644
index 00000000..754874a7
--- /dev/null
+++ b/modules/samples/currentsensor/component/analytics/src/main/resources/carbonapps/Flow_Sensor/Eventreceiver_flowrate_1.0.0/EventReceiver_flowrate.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+ false
+
+
+
+
diff --git a/modules/samples/currentsensor/component/analytics/src/main/resources/carbonapps/Flow_Sensor/Eventreceiver_flowrate_1.0.0/artifact.xml b/modules/samples/currentsensor/component/analytics/src/main/resources/carbonapps/Flow_Sensor/Eventreceiver_flowrate_1.0.0/artifact.xml
new file mode 100644
index 00000000..833d2898
--- /dev/null
+++ b/modules/samples/currentsensor/component/analytics/src/main/resources/carbonapps/Flow_Sensor/Eventreceiver_flowrate_1.0.0/artifact.xml
@@ -0,0 +1,22 @@
+
+
+
+
+ EventReceiver_flowrate.xml
+
diff --git a/modules/samples/currentsensor/component/analytics/src/main/resources/carbonapps/Flow_Sensor/Eventstore_flowrate_1.0.0/artifact.xml b/modules/samples/currentsensor/component/analytics/src/main/resources/carbonapps/Flow_Sensor/Eventstore_flowrate_1.0.0/artifact.xml
new file mode 100644
index 00000000..70d0abf2
--- /dev/null
+++ b/modules/samples/currentsensor/component/analytics/src/main/resources/carbonapps/Flow_Sensor/Eventstore_flowrate_1.0.0/artifact.xml
@@ -0,0 +1,22 @@
+
+
+
+
+ org_wso2_iot_devices_flowrate.xml
+
diff --git a/modules/samples/currentsensor/component/analytics/src/main/resources/carbonapps/Flow_Sensor/Eventstore_flowrate_1.0.0/org_wso2_iot_devices_flowrate.xml b/modules/samples/currentsensor/component/analytics/src/main/resources/carbonapps/Flow_Sensor/Eventstore_flowrate_1.0.0/org_wso2_iot_devices_flowrate.xml
new file mode 100644
index 00000000..f0677697
--- /dev/null
+++ b/modules/samples/currentsensor/component/analytics/src/main/resources/carbonapps/Flow_Sensor/Eventstore_flowrate_1.0.0/org_wso2_iot_devices_flowrate.xml
@@ -0,0 +1,62 @@
+
+
+
+
+
+ org.wso2.iot.devices.flowrate:1.0.0
+
+ EVENT_STORE
+
+
+ meta_owner
+ true
+ true
+ false
+ STRING
+
+
+ meta_deviceType
+ true
+ true
+ false
+ STRING
+
+
+ meta_deviceId
+ true
+ true
+ false
+ STRING
+
+
+ meta_time
+ true
+ true
+ false
+ LONG
+
+
+ flowrate
+ false
+ false
+ false
+ FLOAT
+
+
+
diff --git a/modules/samples/currentsensor/component/analytics/src/main/resources/carbonapps/Flow_Sensor/Eventstream_flowrate_1.0.0/artifact.xml b/modules/samples/currentsensor/component/analytics/src/main/resources/carbonapps/Flow_Sensor/Eventstream_flowrate_1.0.0/artifact.xml
new file mode 100644
index 00000000..aa7e8e65
--- /dev/null
+++ b/modules/samples/currentsensor/component/analytics/src/main/resources/carbonapps/Flow_Sensor/Eventstream_flowrate_1.0.0/artifact.xml
@@ -0,0 +1,22 @@
+
+
+
+
+ org.wso2.iot.devices.flowrate_1.0.0.json
+
diff --git a/modules/samples/currentsensor/component/analytics/src/main/resources/carbonapps/Flow_Sensor/Eventstream_flowrate_1.0.0/org.wso2.iot.devices.flowrate_1.0.0.json b/modules/samples/currentsensor/component/analytics/src/main/resources/carbonapps/Flow_Sensor/Eventstream_flowrate_1.0.0/org.wso2.iot.devices.flowrate_1.0.0.json
new file mode 100644
index 00000000..9b905ec8
--- /dev/null
+++ b/modules/samples/currentsensor/component/analytics/src/main/resources/carbonapps/Flow_Sensor/Eventstream_flowrate_1.0.0/org.wso2.iot.devices.flowrate_1.0.0.json
@@ -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"
+ }
+ ]
+}
diff --git a/modules/samples/currentsensor/component/analytics/src/main/resources/carbonapps/Flow_Sensor/Sparkscripts_1.0.0/Flow_Sensor_Script.xml b/modules/samples/currentsensor/component/analytics/src/main/resources/carbonapps/Flow_Sensor/Sparkscripts_1.0.0/Flow_Sensor_Script.xml
new file mode 100644
index 00000000..4ea204a3
--- /dev/null
+++ b/modules/samples/currentsensor/component/analytics/src/main/resources/carbonapps/Flow_Sensor/Sparkscripts_1.0.0/Flow_Sensor_Script.xml
@@ -0,0 +1,38 @@
+
+
+
+
+ Flow_Sensor_Script
+
+ 0 * * * * ?
+
diff --git a/modules/samples/currentsensor/component/analytics/src/main/resources/carbonapps/Flow_Sensor/Sparkscripts_1.0.0/artifact.xml b/modules/samples/currentsensor/component/analytics/src/main/resources/carbonapps/Flow_Sensor/Sparkscripts_1.0.0/artifact.xml
new file mode 100644
index 00000000..a9001aa1
--- /dev/null
+++ b/modules/samples/currentsensor/component/analytics/src/main/resources/carbonapps/Flow_Sensor/Sparkscripts_1.0.0/artifact.xml
@@ -0,0 +1,22 @@
+
+
+
+
+ Flow_Sensor_Script.xml
+
diff --git a/modules/samples/currentsensor/component/analytics/src/main/resources/carbonapps/Flow_Sensor/artifacts.xml b/modules/samples/currentsensor/component/analytics/src/main/resources/carbonapps/Flow_Sensor/artifacts.xml
new file mode 100644
index 00000000..5e872098
--- /dev/null
+++ b/modules/samples/currentsensor/component/analytics/src/main/resources/carbonapps/Flow_Sensor/artifacts.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/modules/samples/currentsensor/component/controller/src/main/java/org/homeautomation/currentsensor/manager/api/CurrentSensorControllerService.java b/modules/samples/currentsensor/component/controller/src/main/java/org/homeautomation/currentsensor/manager/api/CurrentSensorControllerService.java
index d7ef9044..1df110f1 100644
--- a/modules/samples/currentsensor/component/controller/src/main/java/org/homeautomation/currentsensor/manager/api/CurrentSensorControllerService.java
+++ b/modules/samples/currentsensor/component/controller/src/main/java/org/homeautomation/currentsensor/manager/api/CurrentSensorControllerService.java
@@ -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 + "]");
+ }
+
+ }
+
}
diff --git a/modules/samples/currentsensor/component/controller/src/main/java/org/homeautomation/currentsensor/manager/api/util/CurrentSensorServiceUtils.java b/modules/samples/currentsensor/component/controller/src/main/java/org/homeautomation/currentsensor/manager/api/util/CurrentSensorServiceUtils.java
index 33920045..6c098a1d 100644
--- a/modules/samples/currentsensor/component/controller/src/main/java/org/homeautomation/currentsensor/manager/api/util/CurrentSensorServiceUtils.java
+++ b/modules/samples/currentsensor/component/controller/src/main/java/org/homeautomation/currentsensor/manager/api/util/CurrentSensorServiceUtils.java
@@ -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;
+ }
+
}
diff --git a/modules/samples/currentsensor/component/plugin/src/main/java/org/homeautomation/currentsensor/plugin/constants/CurrentSensorConstants.java b/modules/samples/currentsensor/component/plugin/src/main/java/org/homeautomation/currentsensor/plugin/constants/CurrentSensorConstants.java
index 890bdb23..73571075 100644
--- a/modules/samples/currentsensor/component/plugin/src/main/java/org/homeautomation/currentsensor/plugin/constants/CurrentSensorConstants.java
+++ b/modules/samples/currentsensor/component/plugin/src/main/java/org/homeautomation/currentsensor/plugin/constants/CurrentSensorConstants.java
@@ -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";
}
diff --git a/modules/samples/currentsensor/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.currentsensor.device-view/public/images/current-sensor.png b/modules/samples/currentsensor/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.currentsensor.device-view/public/images/current-sensor.png
index 6a505849..b1ce4901 100644
Binary files a/modules/samples/currentsensor/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.currentsensor.device-view/public/images/current-sensor.png and b/modules/samples/currentsensor/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.currentsensor.device-view/public/images/current-sensor.png differ
diff --git a/modules/samples/currentsensor/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.currentsensor.type-view/public/images/current-sensor.png b/modules/samples/currentsensor/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.currentsensor.type-view/public/images/current-sensor.png
index 6a505849..b1ce4901 100644
Binary files a/modules/samples/currentsensor/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.currentsensor.type-view/public/images/current-sensor.png and b/modules/samples/currentsensor/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.currentsensor.type-view/public/images/current-sensor.png differ
diff --git a/modules/samples/currentsensor/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.currentsensor.type-view/public/images/display-icon.png b/modules/samples/currentsensor/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.currentsensor.type-view/public/images/display-icon.png
deleted file mode 100644
index 90342742..00000000
Binary files a/modules/samples/currentsensor/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.currentsensor.type-view/public/images/display-icon.png and /dev/null differ
diff --git a/modules/samples/currentsensor/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.currentsensor.type-view/public/images/schematicsGuide.png b/modules/samples/currentsensor/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.currentsensor.type-view/public/images/schematicsGuide.png
index aec732f5..b5d05861 100644
Binary files a/modules/samples/currentsensor/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.currentsensor.type-view/public/images/schematicsGuide.png and b/modules/samples/currentsensor/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.currentsensor.type-view/public/images/schematicsGuide.png differ
diff --git a/modules/samples/currentsensor/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.currentsensor.type-view/public/images/thumb.png b/modules/samples/currentsensor/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.currentsensor.type-view/public/images/thumb.png
index 6a505849..b1ce4901 100644
Binary files a/modules/samples/currentsensor/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.currentsensor.type-view/public/images/thumb.png and b/modules/samples/currentsensor/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.currentsensor.type-view/public/images/thumb.png differ
diff --git a/modules/samples/currentsensor/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.currentsensor.type-view/type-view.hbs b/modules/samples/currentsensor/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.currentsensor.type-view/type-view.hbs
index 78e7c455..b072d1d1 100644
--- a/modules/samples/currentsensor/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.currentsensor.type-view/type-view.hbs
+++ b/modules/samples/currentsensor/component/ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.currentsensor.type-view/type-view.hbs
@@ -16,21 +16,28 @@
What it Does
- Connect a Current Sensor to WSO2 IoT Server and manage
- it.
+ Connect a Current Sensor and Flow Sensor to WSO2 IoT Server and visualize sensor
+ data.
What You Need
- ITEM 01 Raspberry
- Pi with SD Card(Internet
- Enabled [Wifi or Ethernet]).
+ ITEM 01 Arduino board with wifi
+ shield.
- ITEM 02 A Digital Display with HDMI
- Cable.
+ ITEM 02 Non-Invasive Current
+ Sensor - 30A.
- STEP 03 Proceed
+ ITEM 02 Flow sensor.
+
+ ITEM 03 A 100 ohm resister.
+
+ ITEM 04 Two 10 kohm resisters.
+
+ ITEM 05 A 100uf capacitor.
+
+ STEP 06 Proceed
to [Prepare] section.
@@ -60,7 +67,6 @@
@@ -175,20 +181,38 @@
Prepare
- 01 Connect a monitor to your
- RaspberryPi via HDMI cable.
+ 01 Make a circuit shown in
+ schematic view and connect analog out put to arduino.(analog input pin 0)
- 02 Configure
- RaspberryPi to connect
- to the Internet.
+ 02 Connect flow sensor to arduino.
+ (analog input pin 1)
03 Go ahead and [Download Agent] the
- Digital Display Agent.
+ Current sensor Agent.
04 Unzip downloaded agent.
- 05 Start Agent by running
- installpackages.sh followed by wso2Agent.sh
+ 05 Create a folder called
+ "CurrentSensor" and move all source files inside.
+
+ 06 Open CurrentSensor.h and
+ provide appropriate values for [WLAN_SSID],[WLAN_PASS],[SERVICE_PORT],[server] and [deviceIP] variables
+ according to your network.
+
+
+
+
+
+
+
+ Arduino will publish Current sensor reading to WSO2-IoT-Server.
+
+
+
+
+
+
+ Arduino will publish Flow sensor reading to WSO2-IoT-Server.
diff --git a/modules/samples/currentsensor/feature/feature/src/main/resources/agent/CurrentSensor.ino b/modules/samples/currentsensor/feature/feature/src/main/resources/agent/CurrentSensor.ino
index 5b1dc46a..d09c712a 100644
--- a/modules/samples/currentsensor/feature/feature/src/main/resources/agent/CurrentSensor.ino
+++ b/modules/samples/currentsensor/feature/feature/src/main/resources/agent/CurrentSensor.ino
@@ -51,8 +51,8 @@ void loop()
}
if(millis() - pushTimestamp > PUSH_INTERVAL){
- while (!client.connected()) {
- setupClient();
+ if (!client.connected()) {
+ wdt_reset();
}
pushData();
diff --git a/modules/samples/currentsensor/feature/feature/src/main/resources/configs/currentsensor.json b/modules/samples/currentsensor/feature/feature/src/main/resources/configs/currentsensor.json
index cdc1fdf5..ad8dcf71 100644
--- a/modules/samples/currentsensor/feature/feature/src/main/resources/configs/currentsensor.json
+++ b/modules/samples/currentsensor/feature/feature/src/main/resources/configs/currentsensor.json
@@ -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"}}
+ ]
+ }
}
]
}
\ No newline at end of file