mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
Merge pull request #707 from Savidude/master
Restructuring RaspberryPi analytics
This commit is contained in:
commit
314ae343f0
@ -20,5 +20,8 @@
|
||||
<artifacts>
|
||||
<artifact name="raspberrypi" version="1.0.0" type="carbon/application">
|
||||
<dependency artifact="raspberrypi_execution" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
|
||||
<dependency artifact="raspberrypi_temperature_publisher" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
|
||||
<dependency artifact="raspberrypi_temperature_store" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
|
||||
<dependency artifact="raspberrypi_temperature_stream" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
|
||||
</artifact>
|
||||
</artifacts>
|
||||
|
||||
@ -6,10 +6,10 @@
|
||||
|
||||
/* define streams/tables and write queries here ... */
|
||||
|
||||
@Import('org.wso2.iot.raspberrypi:1.0.0')
|
||||
@Import('iot.per.device.stream.raspberrypi:1.0.0')
|
||||
define stream raspberrypi (meta_owner string, meta_deviceId string, meta_time long, temperature float);
|
||||
|
||||
@Export('org.wso2.iot.devices.temperature:1.0.0')
|
||||
@Export('iot.per.device.stream.raspberrypi.temperature:1.0.0')
|
||||
define stream temperature (meta_owner string, meta_deviceType string, meta_deviceId string, meta_time long, temperature float);
|
||||
|
||||
from raspberrypi
|
||||
|
||||
@ -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="raspberrypi_temperature_publisher" version="1.0.0" type="event/publisher" serverRole="DataAnalyticsServer">
|
||||
<file>temperature_publisher.xml</file>
|
||||
</artifact>
|
||||
@ -0,0 +1,25 @@
|
||||
<?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="publisher" statistics="disable" trace="disable" xmlns="http://wso2.org/carbon/eventpublisher">
|
||||
<from streamName="iot.per.device.stream.raspberrypi.temperature" version="1.0.0"/>
|
||||
<mapping customMapping="disable" type="wso2event"/>
|
||||
<to eventAdapterType="secured-websocket"/>
|
||||
</eventPublisher>
|
||||
|
||||
@ -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="raspberrypi_temperature_store" version="1.0.0" type="analytics/eventstore" serverRole="DataAnalyticsServer">
|
||||
<file>iot_per_device_stream_raspberrypi_temperature.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>iot.per.device.stream.raspberrypi.temperature: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>temperature</Name>
|
||||
<EnableIndexing>false</EnableIndexing>
|
||||
<IsPrimaryKey>false</IsPrimaryKey>
|
||||
<EnableScoreParam>false</EnableScoreParam>
|
||||
<Type>FLOAT</Type>
|
||||
</ColumnDefinition>
|
||||
</TableSchema>
|
||||
</EventStoreConfiguration>
|
||||
@ -0,0 +1,23 @@
|
||||
<?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="raspberrypi_temperature_stream" version="1.0.0" type="event/stream" serverRole="DataAnalyticsServer">
|
||||
<file>iot.per.device.stream.raspberrypi.temperature_1.0.0.json</file>
|
||||
</artifact>
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "iot.per.device.stream.raspberrypi.temperature",
|
||||
"version": "1.0.0",
|
||||
"nickName": "Temperature Data",
|
||||
"description": "Temperature data received from the Device",
|
||||
"metaData": [
|
||||
{"name":"owner","type":"STRING"},
|
||||
{"name":"deviceType","type":"STRING"},
|
||||
{"name":"deviceId","type":"STRING"},
|
||||
{"name":"time","type":"LONG"}
|
||||
],
|
||||
"payloadData": [
|
||||
{
|
||||
"name": "temperature","type": "FLOAT"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -112,8 +112,8 @@ public class RaspberryPiServiceImpl implements RaspberryPiService {
|
||||
@QueryParam("from") long from, @QueryParam("to") long to) {
|
||||
String fromDate = String.valueOf(from);
|
||||
String toDate = String.valueOf(to);
|
||||
String query = "deviceId:" + deviceId + " AND deviceType:" +
|
||||
RaspberrypiConstants.DEVICE_TYPE + " AND time : [" + fromDate + " TO " + toDate + "]";
|
||||
String query = "meta_deviceId:" + deviceId + " AND meta_deviceType:" +
|
||||
RaspberrypiConstants.DEVICE_TYPE + " AND meta_time : [" + fromDate + " TO " + toDate + "]";
|
||||
String sensorTableName = RaspberrypiConstants.TEMPERATURE_EVENT_TABLE;
|
||||
try {
|
||||
if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(new DeviceIdentifier(deviceId,
|
||||
|
||||
@ -26,7 +26,7 @@ public class RaspberrypiConstants {
|
||||
|
||||
public static final String BULB_CONTEXT = "BULB";
|
||||
//sensor events summerized table name
|
||||
public static final String TEMPERATURE_EVENT_TABLE = "DEVICE_TEMPERATURE_SUMMARY";
|
||||
public static final String TEMPERATURE_EVENT_TABLE = "IOT_PER_DEVICE_STREAM_RASPBERRYPI_TEMPERATURE";
|
||||
|
||||
//mqtt tranport related constants
|
||||
public static final String MQTT_ADAPTER_TOPIC_PROPERTY_NAME = "mqtt.adapter.topic";
|
||||
|
||||
@ -42,7 +42,7 @@ function onRequest(context) {
|
||||
if (tokenPair) {
|
||||
token = tokenPair.accessToken;
|
||||
}
|
||||
websocketEndpoint = websocketEndpoint + "/secured-websocket/org.wso2.iot.devices.temperature/1.0.0?"
|
||||
websocketEndpoint = websocketEndpoint + "/secured-websocket/iot.per.device.stream.raspberrypi.temperature/1.0.0?"
|
||||
+ "deviceId=" + device.deviceIdentifier + "&deviceType=" + device.type + "&websocketToken=" + token;
|
||||
} else {
|
||||
var tokenPair = jwtClient.getAccessToken(resp[0], resp[1], context.user.username + "@" + user.domain
|
||||
@ -50,7 +50,7 @@ function onRequest(context) {
|
||||
if (tokenPair) {
|
||||
token = tokenPair.accessToken;
|
||||
}
|
||||
websocketEndpoint = websocketEndpoint + "/secured-websocket/t/" + user.domain + "/org.wso2.iot.devices.temperature/1.0.0?"
|
||||
websocketEndpoint = websocketEndpoint + "/secured-websocket/t/" + user.domain + "/iot.per.device.stream.raspberrypi.temperature/1.0.0?"
|
||||
+ "deviceId=" + device.deviceIdentifier + "&deviceType=" + device.type + "&websocketToken=" + token;
|
||||
}
|
||||
|
||||
|
||||
@ -21,5 +21,5 @@
|
||||
<property name="topic">carbon.super/raspberrypi/+/temperature</property>
|
||||
</from>
|
||||
<mapping customMapping="disable" type="json"/>
|
||||
<to streamName="org.wso2.iot.raspberrypi" version="1.0.0"/>
|
||||
<to streamName="iot.per.device.stream.raspberrypi" version="1.0.0"/>
|
||||
</eventReceiver>
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "org.wso2.iot.raspberrypi",
|
||||
"name": "iot.per.device.stream.raspberrypi",
|
||||
"version": "1.0.0",
|
||||
"nickName": "raspberrypi",
|
||||
"description": "Temperature data received from the raspberrypi",
|
||||
@ -101,7 +101,7 @@ def main():
|
||||
print ("MQTT_LISTENER: MQTT_TOPIC is " + TOPIC_TO_SUBSCRIBE)
|
||||
|
||||
global mqttClient
|
||||
mqttClient = mqtt.Client()
|
||||
mqttClient = mqtt.Client(client_id="RaspberryPi Agent")
|
||||
mqttClient.on_connect = on_connect
|
||||
mqttClient.on_message = on_message
|
||||
mqttClient.on_publish = on_publish
|
||||
|
||||
@ -40,10 +40,15 @@ sudo apt-get install python-pip
|
||||
sudo pip install paho-mqtt
|
||||
|
||||
# installing ada
|
||||
echo ===Installing ADA libraries
|
||||
sudo apt-get install build-essential python-dev
|
||||
unzip Adafruit_Python_DHT
|
||||
sudo python Adafruit_Python_DHT/setup.py install
|
||||
cd Adafruit_Python_DHT
|
||||
sudo python setup.py install
|
||||
cd ..
|
||||
|
||||
# moving files to start the agent as Daemon
|
||||
echo ===Moving files to start agent as Daemon
|
||||
sudo cp $currentDir/deviceConfig.properties $currentDir/src
|
||||
sudo cp -r $currentDir/src $destination
|
||||
sudo chmod 755 $destination/src/RaspberryAgent.py
|
||||
|
||||
Loading…
Reference in New Issue
Block a user