hasuniea 9 years ago
commit 05d252e61d

@ -23,6 +23,7 @@ import android.util.Log;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject;
import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.AndroidSenseMQTTHandler; import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.AndroidSenseMQTTHandler;
import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.transport.MQTTTransportHandler; import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.transport.MQTTTransportHandler;
import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.transport.TransportHandlerException; import org.wso2.carbon.iot.android.sense.data.publisher.mqtt.transport.TransportHandlerException;
@ -149,7 +150,7 @@ public class DataPublisherService extends Service {
for (Event event : events) { for (Event event : events) {
event.setOwner(user); event.setOwner(user);
event.setDeviceId(deviceId); event.setDeviceId(deviceId);
jsonArray.put(event.getEvent()); jsonArray.put(new JSONObject().put("event", event.getEvent()));
} }
MQTTTransportHandler mqttTransportHandler = AndroidSenseMQTTHandler.getInstance(context); MQTTTransportHandler mqttTransportHandler = AndroidSenseMQTTHandler.getInstance(context);
if (!mqttTransportHandler.isConnected()) { if (!mqttTransportHandler.isConnected()) {

@ -11,7 +11,7 @@ public class Event {
private String owner; private String owner;
private String deviceId; private String deviceId;
private String type; private String type;
private float battery; private int battery;
private double gps[]; //lat,long private double gps[]; //lat,long
private float accelerometer[]; //x,y,z private float accelerometer[]; //x,y,z
private float magnetic[]; //x,y,z private float magnetic[]; //x,y,z
@ -26,11 +26,11 @@ public class Event {
private String wordStatus; private String wordStatus;
private long timestamp; private long timestamp;
private float getBattery() { private int getBattery() {
return battery; return battery;
} }
public void setBattery(float battery) { public void setBattery(int battery) {
this.type = "battery"; this.type = "battery";
this.battery = battery; this.battery = battery;
} }

@ -104,7 +104,6 @@ public class AndroidSenseMQTTHandler extends MQTTTransportHandler {
}; };
Thread connectorThread = new Thread(connector); Thread connectorThread = new Thread(connector);
connectorThread.setDaemon(true);
connectorThread.start(); connectorThread.start();
} }
@ -207,7 +206,6 @@ public class AndroidSenseMQTTHandler extends MQTTTransportHandler {
}; };
Thread terminatorThread = new Thread(stopConnection); Thread terminatorThread = new Thread(stopConnection);
terminatorThread.setDaemon(true);
terminatorThread.start(); terminatorThread.start();
} }

@ -81,8 +81,8 @@ public abstract class MQTTTransportHandler implements MqttCallback, TransportHan
this.clientWillTopic = DISCONNECTION_WILL_TOPIC_PREFIX + SenseConstants.DEVICE_TYPE; this.clientWillTopic = DISCONNECTION_WILL_TOPIC_PREFIX + SenseConstants.DEVICE_TYPE;
this.mqttBrokerEndPoint = "tcp://" + LocalRegistry.getServerHost(context) + ":" + LocalRegistry.getMqttPort(context); this.mqttBrokerEndPoint = "tcp://" + LocalRegistry.getServerHost(context) + ":" + LocalRegistry.getMqttPort(context);
this.timeoutInterval = DEFAULT_TIMEOUT_INTERVAL; this.timeoutInterval = DEFAULT_TIMEOUT_INTERVAL;
setUsernameAndPassword(LocalRegistry.getAccessToken(context), "");
this.initMQTTClient(); this.initMQTTClient();
setUsernameAndPassword(LocalRegistry.getAccessToken(context), "");
} }
/** /**
@ -308,7 +308,6 @@ public abstract class MQTTTransportHandler implements MqttCallback, TransportHan
connect(); connect();
} }
}; };
reconnectThread.setDaemon(true);
reconnectThread.start(); reconnectThread.start();
} }
@ -333,7 +332,6 @@ public abstract class MQTTTransportHandler implements MqttCallback, TransportHan
} }
} }
}; };
messageProcessorThread.setDaemon(true);
messageProcessorThread.start(); messageProcessorThread.start();
} }

@ -180,6 +180,9 @@ public class ActivitySelectSensor extends AppCompatActivity
LocalRegistry.removeUsername(getApplicationContext()); LocalRegistry.removeUsername(getApplicationContext());
LocalRegistry.removeDeviceId(getApplicationContext()); LocalRegistry.removeDeviceId(getApplicationContext());
LocalRegistry.removeServerURL(getApplicationContext()); LocalRegistry.removeServerURL(getApplicationContext());
LocalRegistry.removeAccessToken(getApplicationContext());
LocalRegistry.removeRefreshToken(getApplicationContext());
LocalRegistry.removeMqttPort(getApplicationContext());
LocalRegistry.setExist(false); LocalRegistry.setExist(false);
//Stop the current running background services. //Stop the current running background services.
stopService(new Intent(this, SenseService.class)); //Stop sensor reading service stopService(new Intent(this, SenseService.class)); //Stop sensor reading service

@ -95,6 +95,7 @@ public class SenseClientAsyncExecutor extends AsyncTask<String, Void, Map<String
String endpoint = parameters[3]; String endpoint = parameters[3];
Map<String, String> responseMap = new HashMap<>(); Map<String, String> responseMap = new HashMap<>();
responseMap.put(STATUS, "200"); responseMap.put(STATUS, "200");
AccessTokenInfo accessTokenInfo = null;
try { try {
//DynamicClientRegistraiton. //DynamicClientRegistraiton.
DynamicClientRegistrationService dynamicClientRegistrationService = Feign.builder() DynamicClientRegistrationService dynamicClientRegistrationService = Feign.builder()
@ -116,7 +117,7 @@ public class SenseClientAsyncExecutor extends AsyncTask<String, Void, Map<String
new BasicAuthRequestInterceptor(oAuthApplicationInfo.getClient_id(), oAuthApplicationInfo.getClient_secret())) new BasicAuthRequestInterceptor(oAuthApplicationInfo.getClient_id(), oAuthApplicationInfo.getClient_secret()))
.contract(new JAXRSContract()).encoder(new JacksonEncoder()).decoder(new JacksonDecoder()) .contract(new JAXRSContract()).encoder(new JacksonEncoder()).decoder(new JacksonDecoder())
.target(TokenIssuerService.class, endpoint + SenseConstants.TOKEN_ISSUER_CONTEXT); .target(TokenIssuerService.class, endpoint + SenseConstants.TOKEN_ISSUER_CONTEXT);
AccessTokenInfo accessTokenInfo = tokenIssuerService.getToken("password", username, password); accessTokenInfo = tokenIssuerService.getToken("password", username, password);
//ApiApplicationRegistration //ApiApplicationRegistration
ApiApplicationRegistrationService apiApplicationRegistrationService = Feign.builder().client(disableHostnameVerification) ApiApplicationRegistrationService apiApplicationRegistrationService = Feign.builder().client(disableHostnameVerification)
@ -145,6 +146,10 @@ public class SenseClientAsyncExecutor extends AsyncTask<String, Void, Map<String
return responseMap; return responseMap;
} catch (FeignException e) { } catch (FeignException e) {
responseMap.put(STATUS, "" + e.status()); responseMap.put(STATUS, "" + e.status());
if (e.status() == 409) {
LocalRegistry.addAccessToken(context, accessTokenInfo.getAccess_token());
LocalRegistry.addRefreshToken(context, accessTokenInfo.getRefresh_token());
}
return responseMap; return responseMap;
} }
} }

@ -4,7 +4,8 @@
android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" tools:context="org.wso2.carbon.iot.android.sense.RegisterActivity"> android:paddingTop="@dimen/activity_vertical_margin" tools:context="org.wso2.carbon.iot.android.sense.RegisterActivity"
android:weightSum="1">
<!-- Login progress --> <!-- Login progress -->
@ -14,7 +15,8 @@
<ScrollView android:id="@+id/login_form" android:layout_width="match_parent" <ScrollView android:id="@+id/login_form" android:layout_width="match_parent"
android:layout_height="211dp" android:layout_height="211dp"
android:fillViewport="false"> android:fillViewport="false"
android:layout_weight="0.07">
<LinearLayout android:id="@+id/email_login_form" android:layout_width="match_parent" <LinearLayout android:id="@+id/email_login_form" android:layout_width="match_parent"
android:layout_height="wrap_content" android:orientation="vertical"> android:layout_height="wrap_content" android:orientation="vertical">
@ -37,43 +39,36 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="@string/hostname" android:layout_height="wrap_content" android:hint="@string/hostname"
android:id="@+id/hostname" android:id="@+id/hostname"
android:text="https://localhost:9443" android:text="https://10.10.10.149:9443"
android:inputType="text" android:inputType="text"
android:maxLines="1" android:singleLine="true"/> android:maxLines="1" android:singleLine="true"/>
<Button android:id="@+id/device_register_button" style="?android:textAppearanceSmall" <TextView
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_marginTop="16dp" android:text="@string/action_sign_in" android:layout_height="wrap_content"
android:textStyle="bold" /> android:textAppearance="?android:attr/textAppearanceMedium"
android:text="MQTT Port"
android:id="@+id/textView4"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hostname"
android:id="@+id/mqttPort"
android:text="1883"
android:inputType="text"
android:maxLines="1"
android:singleLine="true"
/>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
<ImageView <Button android:id="@+id/device_register_button" style="?android:textAppearanceSmall"
android:layout_width="wrap_content" android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:layout_marginTop="16dp" android:text="@string/action_sign_in"
android:id="@+id/imageView" /> android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="MQTT Port"
android:id="@+id/textView4"
android:layout_gravity="center_horizontal"/>
<EditText
android:layout_width="350dp"
android:layout_height="wrap_content"
android:hint="@string/hostname"
android:id="@+id/mqttPort"
android:text="1883"
android:inputType="text"
android:maxLines="1"
android:singleLine="true"
android:layout_gravity="right"/>
</LinearLayout> </LinearLayout>

@ -23,17 +23,7 @@
<property name="target-dir" value="target/carbonapps"/> <property name="target-dir" value="target/carbonapps"/>
<property name="src-dir" value="src/main/resources/carbonapps"/> <property name="src-dir" value="src/main/resources/carbonapps"/>
<property name="GPS_dir" value="GPS"/> <property name="Android_Sense_dir" value="Android_Sense"/>
<property name="Light_dir" value="Light"/>
<property name="Battery_dir" value="Battery"/>
<property name="Magnetic_dir" value="Magnetic"/>
<property name="Accelerometer_dir" value="Accelerometer"/>
<property name="Gravity_dir" value="Gravity"/>
<property name="Gyroscope_dir" value="Gyroscope"/>
<property name="Proximity_dir" value="Proximity"/>
<property name="Pressure_dir" value="Pressure"/>
<property name="Rotation_dir" value="Rotation"/>
<property name="Wordcounter_dir" value="WordCount"/>
<target name="clean"> <target name="clean">
<delete dir="${target-dir}" /> <delete dir="${target-dir}" />
@ -41,38 +31,8 @@
<target name="zip" depends="clean"> <target name="zip" depends="clean">
<mkdir dir="${target-dir}"/> <mkdir dir="${target-dir}"/>
<zip destfile="${target-dir}/${GPS_dir}.car"> <zip destfile="${target-dir}/${Android_Sense_dir}.car">
<zipfileset dir="${src-dir}/${GPS_dir}"/> <zipfileset dir="${src-dir}/${Android_Sense_dir}"/>
</zip>
<zip destfile="${target-dir}/${Light_dir}.car">
<zipfileset dir="${src-dir}/${Light_dir}"/>
</zip>
<zip destfile="${target-dir}/${Battery_dir}.car">
<zipfileset dir="${src-dir}/${Battery_dir}"/>
</zip>
<zip destfile="${target-dir}/${Magnetic_dir}.car">
<zipfileset dir="${src-dir}/${Magnetic_dir}"/>
</zip>
<zip destfile="${target-dir}/${Accelerometer_dir}.car">
<zipfileset dir="${src-dir}/${Accelerometer_dir}"/>
</zip>
<zip destfile="${target-dir}/${Gravity_dir}.car">
<zipfileset dir="${src-dir}/${Gravity_dir}"/>
</zip>
<zip destfile="${target-dir}/${Gyroscope_dir}.car">
<zipfileset dir="${src-dir}/${Gyroscope_dir}"/>
</zip>
<zip destfile="${target-dir}/${Pressure_dir}.car">
<zipfileset dir="${src-dir}/${Pressure_dir}"/>
</zip>
<zip destfile="${target-dir}/${Rotation_dir}.car">
<zipfileset dir="${src-dir}/${Rotation_dir}"/>
</zip>
<zip destfile="${target-dir}/${Proximity_dir}.car">
<zipfileset dir="${src-dir}/${Proximity_dir}"/>
</zip>
<zip destfile="${target-dir}/${Wordcounter_dir}.car">
<zipfileset dir="${src-dir}/${Wordcounter_dir}"/>
</zip> </zip>
</target> </target>
</project> </project>

@ -0,0 +1,87 @@
/* Enter a unique ExecutionPlan */
@Plan:name('android_sense_execution')
/* Enter a unique description for ExecutionPlan */
-- @Plan:description('ExecutionPlan')
/* define streams/tables and write queries here ... */
@Export('org.wso2.iot.devices.wordcount:1.0.0')
define stream words (meta_owner string, meta_deviceType string, meta_deviceId string, meta_time long, sessionId string, word string, status string);
@Export('org.wso2.iot.devices.rotation:1.0.0')
define stream rotation (meta_owner string, meta_deviceType string, meta_deviceId string, meta_time long, x float, y float, z float);
@Export('org.wso2.iot.devices.proximity:1.0.0')
define stream proximity (meta_owner string, meta_deviceType string, meta_deviceId string, meta_time long, proximity float);
@Export('org.wso2.iot.devices.pressure:1.0.0')
define stream pressure (meta_owner string, meta_deviceType string, meta_deviceId string, meta_time long, pressure float);
@Export('org.wso2.iot.devices.magnetic:1.0.0')
define stream magnetic (meta_owner string, meta_deviceType string, meta_deviceId string, meta_time long, x float, y float, z float);
@Export('org.wso2.iot.devices.light:1.0.0')
define stream light (meta_owner string, meta_deviceType string, meta_deviceId string, meta_time long, light float);
@Export('org.wso2.iot.devices.gyroscope:1.0.0')
define stream gyroscope (meta_owner string, meta_deviceType string, meta_deviceId string, meta_time long, x float, y float, z float);
@Export('org.wso2.iot.devices.gravity:1.0.0')
define stream gravity (meta_owner string, meta_deviceType string, meta_deviceId string, meta_time long, x float, y float, z float);
@Export('org.wso2.iot.devices.gps:1.0.0')
define stream gps (meta_owner string, meta_deviceType string, meta_deviceId string, meta_time long, latitude double, longitude double);
@Export('org.wso2.iot.devices.battery:1.0.0')
define stream battery (meta_owner string, meta_deviceType string, meta_deviceId string, meta_time long, level int);
@Export('org.wso2.iot.devices.accelerometer:1.0.0')
define stream accelerometer (meta_owner string, meta_deviceType string, meta_deviceId string, meta_time long, x float, y float, z float);
@Import('org.wso2.iot.android.sense:1.0.0')
define stream androidsense (meta_owner string, meta_deviceId string, meta_type string, meta_timestamp long, battery int, gps_lat double, gps_long double, accelerometer_x float, accelerometer_y float, accelerometer_z float, magnetic_x float, magnetic_y float, magnetic_z float, gyroscope_x float, gyroscope_y float, gyroscope_z float, light float, pressure float, proximity float, gravity_x float, gravity_y float, gravity_z float, rotation_x float, rotation_y float, rotation_z float, word string, word_sessionId string, word_status string);
from androidsense[meta_type == 'accelerometer']
select meta_owner, 'android_sense' as meta_deviceType, meta_deviceId, meta_timestamp as meta_time, accelerometer_x as x, accelerometer_y as y, accelerometer_z as z
insert into accelerometer;
from androidsense[meta_type == 'battery']
select meta_owner, 'android_sense' as meta_deviceType, meta_deviceId, meta_timestamp as meta_time, battery as level
insert into battery;
from androidsense[meta_type == 'gps']
select meta_owner, 'android_sense' as meta_deviceType, meta_deviceId, meta_timestamp as meta_time, gps_lat as latitude, gps_long as longitude
insert into gps;
from androidsense[meta_type == 'gravity']
select meta_owner, 'android_sense' as meta_deviceType, meta_deviceId, meta_timestamp as meta_time, gravity_x as x, gravity_y as y, gravity_z as z
insert into gravity;
from androidsense[meta_type == 'gyroscope']
select meta_owner, 'android_sense' as meta_deviceType, meta_deviceId, meta_timestamp as meta_time, gyroscope_x as x, gyroscope_y as y, gyroscope_z as z
insert into gyroscope;
from androidsense[meta_type == 'light']
select meta_owner, 'android_sense' as meta_deviceType, meta_deviceId, meta_timestamp as meta_time, light
insert into light;
from androidsense[meta_type == 'magnetic']
select meta_owner, 'android_sense' as meta_deviceType, meta_deviceId, meta_timestamp as meta_time, magnetic_x as x, magnetic_y as y, magnetic_z as z
insert into magnetic;
from androidsense[meta_type == 'pressure']
select meta_owner, 'android_sense' as meta_deviceType, meta_deviceId, meta_timestamp as meta_time, pressure
insert into pressure;
from androidsense[meta_type == 'proximity']
select meta_owner, 'android_sense' as meta_deviceType, meta_deviceId, meta_timestamp as meta_time, proximity
insert into proximity;
from androidsense[meta_type == 'rotation']
select meta_owner, 'android_sense' as meta_deviceType, meta_deviceId, meta_timestamp as meta_time, rotation_x as x, rotation_y as y, rotation_z as z
insert into rotation;
from androidsense[meta_type == 'word']
select meta_owner, 'android_sense' as meta_deviceType, meta_deviceId, meta_timestamp as meta_time, word_sessionId as sessionId, word as word, word_status as status
insert into words;

@ -17,7 +17,7 @@
~ under the License. ~ under the License.
--> -->
<artifact name="Eventstream_temperature" version="1.0.0" type="event/stream" serverRole="DataAnalyticsServer"> <artifact name="EventExecution_AndroidSense" version="1.0.0" type="event/execution-plan" serverRole="DataAnalyticsServer">
<file>org.wso2.iot.devices.temperature_1.0.0.json</file> <file>EventExecution_AndroidSense.siddhiql</file>
</artifact> </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="EventPublisher_AndroidSense" statistics="disable" trace="disable" xmlns="http://wso2.org/carbon/eventpublisher">
<from streamName="org.wso2.iot.android.sense" version="1.0.0"/>
<mapping customMapping="disable" type="wso2event"/>
<to eventAdapterType="iot-ui"/>
</eventPublisher>

@ -17,6 +17,6 @@
~ under the License. ~ under the License.
--> -->
<artifact name="Sparkscripts" version="1.0.0" type="analytics/spark" serverRole="DataAnalyticsServer"> <artifact name="EventPublisher_AndroidSense" version="1.0.0" type="event/publisher" serverRole="DataAnalyticsServer">
<file>Temperature_Sensor_Script.xml</file> <file>EventPublisher_AndroidSense.xml</file>
</artifact> </artifact>

@ -0,0 +1,33 @@
<?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_AndroidSense" statistics="disable" trace="disable" xmlns="http://wso2.org/carbon/eventreceiver">
<from eventAdapterType="oauth-mqtt">
<property name="topic">wso2/android_sense/#</property>
<property name="username">admin</property>
<property name="contentValidationParams">device_id_json_path:event.metaData.deviceId,device_id_topic_hierarchy_index:2</property>
<property name="contentValidation">default</property>
<property name="dcrUrl">https://localhost:9443/dynamic-client-web/register</property>
<property name="url">tcp://localhost:1883</property>
<property name="cleanSession">false</property>
</from>
<mapping customMapping="disable" type="json"/>
<to streamName="org.wso2.iot.android.sense" version="1.0.0"/>
</eventReceiver>

@ -17,6 +17,6 @@
~ under the License. ~ under the License.
--> -->
<artifact name="Eventreceiver_temperature" version="1.0.0" type="event/receiver" serverRole="DataAnalyticsServer"> <artifact name="EventReceiver_AndroidSense" version="1.0.0" type="event/receiver" serverRole="DataAnalyticsServer">
<file>EventReceiver_temperature.xml</file> <file>EventReceiver_AndroidSense.xml</file>
</artifact> </artifact>

@ -17,6 +17,7 @@
~ under the License. ~ under the License.
--> -->
<artifact name="Eventreceiver_temperature" version="1.0.0" type="event/receiver" serverRole="DataAnalyticsServer"> <artifact name="EventStream_AndroidSense" version="1.0.0" type="event/stream" serverRole="DataAnalyticsServer">
<file>EventReceiver_temperature.xml</file> <file>org.wso2.iot.android.sense_1.0.0.json</file>
</artifact> </artifact>

@ -0,0 +1,38 @@
{
"name": "org.wso2.iot.android.sense",
"version": "1.0.0",
"nickName": "android_sense_stream",
"description": "This hold the device type stream of android sense",
"metaData": [
{"name": "owner", "type": "STRING"},
{"name": "deviceId", "type": "STRING"},
{"name": "type", "type": "STRING"},
{"name": "timestamp", "type": "LONG"}
],
"payloadData": [
{"name": "battery", "type": "INT"},
{"name": "gps_lat", "type": "DOUBLE"},
{"name": "gps_long", "type": "DOUBLE"},
{"name": "accelerometer_x", "type": "FLOAT"},
{"name": "accelerometer_y", "type": "FLOAT"},
{"name": "accelerometer_z", "type": "FLOAT"},
{"name": "magnetic_x", "type": "FLOAT"},
{"name": "magnetic_y", "type": "FLOAT"},
{"name": "magnetic_z", "type": "FLOAT"},
{"name": "gyroscope_x", "type": "FLOAT"},
{"name": "gyroscope_y", "type": "FLOAT"},
{"name": "gyroscope_z", "type": "FLOAT"},
{"name": "light", "type": "FLOAT"},
{"name": "pressure", "type": "FLOAT"},
{"name": "proximity", "type": "FLOAT"},
{"name": "gravity_x", "type": "FLOAT"},
{"name": "gravity_y", "type": "FLOAT"},
{"name": "gravity_z", "type": "FLOAT"},
{"name": "rotation_x", "type": "FLOAT"},
{"name": "rotation_y", "type": "FLOAT"},
{"name": "rotation_z", "type": "FLOAT"},
{"name": "word", "type": "STRING"},
{"name": "word_sessionId", "type": "STRING"},
{"name": "word_status", "type": "STRING"}
]
}

@ -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.
-->
<artifacts>
<artifact name="AndroidSense_CAPP" version="1.0.0" type="carbon/application">
<dependency artifact="EventStream_AndroidSense" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
<dependency artifact="EventReceiver_AndroidSense" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
<dependency artifact="EventPublisher_AndroidSense" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
<dependency artifact="EventExecution_AndroidSense" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
</artifact>
</artifacts>

@ -80,3 +80,4 @@ public interface AndroidSenseControllerService {
@QueryParam("from") long from, @QueryParam("to") long to); @QueryParam("from") long from, @QueryParam("to") long to);
} }

@ -24,18 +24,11 @@ import org.wso2.carbon.analytics.dataservice.commons.SORT;
import org.wso2.carbon.analytics.dataservice.commons.SortByField; import org.wso2.carbon.analytics.dataservice.commons.SortByField;
import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException; import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException;
import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherService;
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature;
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.transport.AndroidSenseMQTTConnector; import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.transport.AndroidSenseMQTTConnector;
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.APIUtil; import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.APIUtil;
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.DeviceData;
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.SensorData;
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.SensorRecord; import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.SensorRecord;
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants; import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants;
import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager;
import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener; import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener;
import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException; import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;
@ -64,8 +57,7 @@ public class AndroidSenseControllerServiceImpl implements AndroidSenseController
@POST @POST
public Response sendKeyWords(@PathParam("deviceId") String deviceId, @FormParam("keywords") String keywords) { public Response sendKeyWords(@PathParam("deviceId") String deviceId, @FormParam("keywords") String keywords) {
try { try {
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); androidSenseMQTTConnector.publishDeviceData(deviceId, "add", keywords);
androidSenseMQTTConnector.publishDeviceData(username, deviceId, "add", keywords);
return Response.ok().build(); return Response.ok().build();
} catch (TransportHandlerException e) { } catch (TransportHandlerException e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
@ -76,8 +68,7 @@ public class AndroidSenseControllerServiceImpl implements AndroidSenseController
@POST @POST
public Response sendThreshold(@PathParam("deviceId") String deviceId, @FormParam("threshold") String threshold) { public Response sendThreshold(@PathParam("deviceId") String deviceId, @FormParam("threshold") String threshold) {
try { try {
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); androidSenseMQTTConnector.publishDeviceData(deviceId, "threshold", threshold);
androidSenseMQTTConnector.publishDeviceData(username, deviceId, "threshold", threshold);
return Response.ok().build(); return Response.ok().build();
} catch (TransportHandlerException e) { } catch (TransportHandlerException e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
@ -86,10 +77,9 @@ public class AndroidSenseControllerServiceImpl implements AndroidSenseController
@Path("device/{deviceId}/words") @Path("device/{deviceId}/words")
@DELETE @DELETE
public Response removeKeyWords(@PathParam("deviceId") String deviceId, @QueryParam("words") String words) { public Response removeKeyWords(@PathParam("deviceId") String deviceId, @FormParam("words") String words) {
try { try {
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); androidSenseMQTTConnector.publishDeviceData(deviceId, "remove", words);
androidSenseMQTTConnector.publishDeviceData(username, deviceId, "remove", words);
return Response.ok().build(); return Response.ok().build();
} catch (TransportHandlerException e) { } catch (TransportHandlerException e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
@ -198,7 +188,7 @@ public class AndroidSenseControllerServiceImpl implements AndroidSenseController
if (waitForServerStartup()) { if (waitForServerStartup()) {
return; return;
} }
//The delay is added till the server starts up. //The delay is added for the server to starts up.
try { try {
Thread.sleep(5000); Thread.sleep(5000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -215,7 +205,6 @@ public class AndroidSenseControllerServiceImpl implements AndroidSenseController
} }
}; };
Thread connectorThread = new Thread(connector); Thread connectorThread = new Thread(connector);
connectorThread.setDaemon(true);
connectorThread.start(); connectorThread.start();
} }

@ -101,7 +101,6 @@ public class AndroidSenseMQTTConnector extends MQTTTransportHandler {
} }
}; };
Thread connectorThread = new Thread(connector); Thread connectorThread = new Thread(connector);
connectorThread.setDaemon(true);
connectorThread.start(); connectorThread.start();
} }
@ -195,7 +194,6 @@ public class AndroidSenseMQTTConnector extends MQTTTransportHandler {
} }
}; };
Thread terminatorThread = new Thread(stopConnection); Thread terminatorThread = new Thread(stopConnection);
terminatorThread.setDaemon(true);
terminatorThread.start(); terminatorThread.start();
} }
} }

@ -14,7 +14,7 @@
Operations Operations
</div> </div>
<div class="add-margin-top-4x"> <div class="add-margin-top-4x">
{{unit "iot.unit.device.operation-bar" device=device}} {{unit "iot.unit.device.operation-bar" device=device backendApiUri=backendApiUri}}
</div> </div>
{{/zone}} {{/zone}}

@ -20,13 +20,14 @@ function onRequest(context) {
var log = new Log("device-view.js"); var log = new Log("device-view.js");
var deviceType = context.uriParams.deviceType; var deviceType = context.uriParams.deviceType;
var deviceId = request.getParameter("id"); var deviceId = request.getParameter("id");
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) { if (deviceType && deviceId) {
var deviceModule = require("/app/modules/device.js").deviceModule; var deviceModule = require("/app/modules/device.js").deviceModule;
var device = deviceModule.viewDevice(deviceType, deviceId); var device = deviceModule.viewDevice(deviceType, deviceId);
if (device && device.status != "error") { if (device && device.status != "error") {
return {"device": device}; return {"device": device, "backendApiUri" : devicemgtProps["httpsURL"] + "/android_sense/"};
} else { } else {
response.sendError(404, "Device Id " + deviceId + "of type " + deviceType + " cannot be found!"); response.sendError(404, "Device Id " + deviceId + "of type " + deviceType + " cannot be found!");
exit(); exit();

@ -1,38 +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.
-->
<project name="create-sample-sensor-capps" default="zip" basedir=".">
<property name="project-name" value="${ant.project.name}"/>
<property name="target-dir" value="target/carbonapps"/>
<property name="src-dir" value="src/main/resources/carbonapps"/>
<property name="Temperature_Sensor_dir" value="Temperature_Sensor"/>
<target name="clean">
<delete dir="${target-dir}" />
</target>
<target name="zip" depends="clean">
<mkdir dir="${target-dir}"/>
<zip destfile="${target-dir}/${Temperature_Sensor_dir}.car">
<zipfileset dir="${src-dir}/${Temperature_Sensor_dir}"/>
</zip>
</target>
</project>

@ -1,31 +0,0 @@
<?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>IoTServer_Sensor_Script</Name>
<Script>
CREATE TEMPORARY TABLE DeviceTemperatureData USING CarbonAnalytics OPTIONS(tableName "ORG_WSO2_IOT_DEVICES_TEMPERATURE");
CREATE TEMPORARY TABLE DeviceTemperatureSummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_TEMPERATURE_SUMMARY", schema "temperature FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
insert overwrite table DeviceTemperatureSummaryData select temperature, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceTemperatureData group by temperature, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
</Script>
<CronExpression>0 * * * * ?</CronExpression>
</Analytics>

@ -50,14 +50,6 @@ public interface ArduinoControllerService {
Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol, Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol,
@FormParam("state") String state); @FormParam("state") String state);
@Path("device/{deviceId}/temperature")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Feature(code = "temperature", name = "Temperature", type = "monitor", description = "Request temperature reading " +
"from Arduino agent")
Response requestTemperature(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol);
@Path("device/sensor") @Path("device/sensor")
@POST @POST
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)

@ -29,12 +29,19 @@ import org.wso2.carbon.device.mgt.iot.arduino.service.impl.dto.SensorRecord;
import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.APIUtil; import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.APIUtil;
import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.ArduinoServiceUtils; import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.ArduinoServiceUtils;
import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants; import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants;
import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -49,7 +56,10 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService {
private ConcurrentHashMap<String, String> deviceToIpMap = new ConcurrentHashMap<>(); private ConcurrentHashMap<String, String> deviceToIpMap = new ConcurrentHashMap<>();
@Override @Override
public Response registerDeviceIP(String deviceId, String deviceIP, String devicePort, HttpServletRequest request) { @Path("device/register/{deviceId}/{ip}/{port}")
@POST
public Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP,
@PathParam("port") String devicePort, @Context HttpServletRequest request) {
String result; String result;
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId + " of owner: "); log.debug("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId + " of owner: ");
@ -64,7 +74,10 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService {
} }
@Override @Override
public Response switchBulb(String deviceId, String protocol, String state) { @Path("device/{deviceId}/bulb")
@POST
public Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol,
@FormParam("state") String state) {
LinkedList<String> deviceControlList = internalControlsQueue.get(deviceId); LinkedList<String> deviceControlList = internalControlsQueue.get(deviceId);
String operation = "BULB:" + state.toUpperCase(); String operation = "BULB:" + state.toUpperCase();
@ -80,24 +93,13 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService {
} }
@Override @Override
public Response requestTemperature(String deviceId, String protocol) { @Path("device/sensor")
try { @POST
org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord sensorRecord = @Consumes(MediaType.APPLICATION_JSON)
SensorDataManager.getInstance().getSensorRecord(deviceId, ArduinoConstants.SENSOR_TEMPERATURE);
return Response.status(Response.Status.OK.getStatusCode()).entity(sensorRecord).build();
} catch (DeviceControllerException e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
}
}
@Override
public Response pushData(DeviceData dataMsg) { public Response pushData(DeviceData dataMsg) {
String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
String deviceId = dataMsg.deviceId; String deviceId = dataMsg.deviceId;
float pinData = dataMsg.value; float pinData = dataMsg.value;
SensorDataManager.getInstance().setSensorRecord(deviceId, ArduinoConstants.SENSOR_TEMPERATURE,
String.valueOf(pinData),
Calendar.getInstance().getTimeInMillis());
if (!ArduinoServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) { if (!ArduinoServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) {
log.warn("An error occured whilst trying to publish pin data of Arduino with ID [" + log.warn("An error occured whilst trying to publish pin data of Arduino with ID [" +
deviceId + "] of owner [" + owner + "]"); deviceId + "] of owner [" + owner + "]");
@ -107,7 +109,9 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService {
} }
@Override @Override
public Response readControls(String deviceId, String protocol) { @Path("device/{deviceId}/controls")
@GET
public Response readControls(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol) {
String result; String result;
LinkedList<String> deviceControlList = internalControlsQueue.get(deviceId); LinkedList<String> deviceControlList = internalControlsQueue.get(deviceId);
String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
@ -135,13 +139,13 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService {
} }
@Override @Override
public Response pushTemperatureData(final DeviceData dataMsg, HttpServletRequest request) { @Path("device/temperature")
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response pushTemperatureData(final DeviceData dataMsg, @Context HttpServletRequest request) {
String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
String deviceId = dataMsg.deviceId; String deviceId = dataMsg.deviceId;
float temperature = dataMsg.value; float temperature = dataMsg.value;
SensorDataManager.getInstance().setSensorRecord(deviceId, ArduinoConstants.SENSOR_TEMPERATURE,
String.valueOf(temperature),
Calendar.getInstance().getTimeInMillis());
if (!ArduinoServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) { if (!ArduinoServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) {
log.warn("An error occured whilst trying to publish temperature data of Arduino with ID [" + deviceId + log.warn("An error occured whilst trying to publish temperature data of Arduino with ID [" + deviceId +
"] of owner [" + owner + "]"); "] of owner [" + owner + "]");
@ -151,7 +155,12 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService {
} }
@Override @Override
public Response getArduinoTemperatureStats(String deviceId, long from, long to) { @Path("device/stats/{deviceId}/sensors/temperature")
@GET
@Consumes("application/json")
@Produces("application/json")
public Response getArduinoTemperatureStats(@PathParam("deviceId") String deviceId, @QueryParam("from") long from,
@QueryParam("to") long to) {
String fromDate = String.valueOf(from); String fromDate = String.valueOf(from);
String toDate = String.valueOf(to); String toDate = String.valueOf(to);
String query = "deviceId:" + deviceId + " AND deviceType:" + String query = "deviceId:" + deviceId + " AND deviceType:" +

@ -32,6 +32,7 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
@Path("enrollment")
@API(name = "arduino_mgt", version = "1.0.0", context = "/arduino_mgt", tags = {"arduino"}) @API(name = "arduino_mgt", version = "1.0.0", context = "/arduino_mgt", tags = {"arduino"})
@DeviceType(value = "arduino") @DeviceType(value = "arduino")
public interface ArduinoManagerService { public interface ArduinoManagerService {

@ -18,7 +18,6 @@
package org.wso2.carbon.device.mgt.iot.arduino.service.impl; package org.wso2.carbon.device.mgt.iot.arduino.service.impl;
import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService; import org.wso2.carbon.apimgt.application.extension.APIManagementProviderService;
import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey; import org.wso2.carbon.apimgt.application.extension.dto.ApiApplicationKey;
import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException; import org.wso2.carbon.apimgt.application.extension.exception.APIManagerException;
@ -27,7 +26,6 @@ import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType;
import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.APIUtil; import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.APIUtil;
import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants; import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants;
import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
@ -37,6 +35,16 @@ import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo; import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException; import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreException;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -45,13 +53,16 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@Path("enrollment")
public class ArduinoManagerServiceImpl implements ArduinoManagerService { public class ArduinoManagerServiceImpl implements ArduinoManagerService {
private static final String KEY_TYPE = "PRODUCTION"; private static final String KEY_TYPE = "PRODUCTION";
private static ApiApplicationKey apiApplicationKey; private static ApiApplicationKey apiApplicationKey;
@Override @Override
public Response removeDevice(String deviceId) { @Path("devices/{device_id}")
@DELETE
public Response removeDevice(@PathParam("device_id") String deviceId) {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(deviceId); deviceIdentifier.setId(deviceId);
deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE); deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE);
@ -68,7 +79,9 @@ public class ArduinoManagerServiceImpl implements ArduinoManagerService {
} }
@Override @Override
public Response updateDevice(String deviceId, String name) { @Path("devices/{device_id}")
@PUT
public Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name) {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(deviceId); deviceIdentifier.setId(deviceId);
deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE); deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE);
@ -90,7 +103,11 @@ public class ArduinoManagerServiceImpl implements ArduinoManagerService {
} }
@Override @Override
public Response getDevice(String deviceId) { @Path("devices/{device_id}")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response getDevice(@PathParam("device_id") String deviceId) {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(deviceId); deviceIdentifier.setId(deviceId);
deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE); deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE);
@ -103,6 +120,10 @@ public class ArduinoManagerServiceImpl implements ArduinoManagerService {
} }
@Override @Override
@Path("devices")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response getArduinoDevices() { public Response getArduinoDevices() {
try { try {
List<Device> userDevices = APIUtil.getDeviceManagementService().getDevicesOfUser( List<Device> userDevices = APIUtil.getDeviceManagementService().getDevicesOfUser(
@ -122,7 +143,10 @@ public class ArduinoManagerServiceImpl implements ArduinoManagerService {
} }
@Override @Override
public Response downloadSketch(String customDeviceName) { @Path("devices/download")
@GET
@Produces("application/octet-stream")
public Response downloadSketch(@QueryParam("deviceName") String customDeviceName) {
try { try {
ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), customDeviceName); ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), customDeviceName);
Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile()); Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile());
@ -144,7 +168,9 @@ public class ArduinoManagerServiceImpl implements ArduinoManagerService {
} }
@Override @Override
public Response generateSketchLink(String deviceName) { @Path("devices/generate_link")
@GET
public Response generateSketchLink(@QueryParam("deviceName") String deviceName) {
try { try {
ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName); ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName);
Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId()); Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId());

@ -7,56 +7,40 @@
<display-name>Arduino</display-name> <display-name>Arduino</display-name>
<description>Arduino</description> <description>Arduino</description>
<servlet> <servlet>
<servlet-name>CXFServlet</servlet-name> <servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup> <load-on-startup>1</load-on-startup>
</servlet> </servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<servlet-mapping> <url-pattern>/*</url-pattern>
<servlet-name>CXFServlet</servlet-name> </servlet-mapping>
<url-pattern>/*</url-pattern> <context-param>
</servlet-mapping> <param-name>isAdminService</param-name>
<param-value>false</param-value>
<context-param> </context-param>
<param-name>isAdminService</param-name> <context-param>
<param-value>false</param-value> <param-name>doAuthentication</param-name>
</context-param> <param-value>true</param-value>
<context-param> </context-param>
<param-name>doAuthentication</param-name> <context-param>
<param-value>false</param-value> <param-name>isSharedWithAllTenants</param-name>
</context-param> <param-value>true</param-value>
<context-param> </context-param>
<param-name>isSharedWithAllTenants</param-name> <context-param>
<param-value>true</param-value> <param-name>providerTenantDomain</param-name>
</context-param> <param-value>carbon.super</param-value>
<context-param> </context-param>
<param-name>providerTenantDomain</param-name>
<param-value>carbon.super</param-value>
</context-param>
<!--publish to apim-->
<context-param>
<param-name>managed-api-enabled</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>managed-api-owner</param-name>
<param-value>admin</param-value>
</context-param>
<context-param>
<param-name>managed-api-context-template</param-name>
<param-value>/arduino/{version}</param-value>
</context-param>
<context-param>
<param-name>managed-api-application</param-name>
<param-value>arduino</param-value>
</context-param>
<context-param>
<param-name>managed-api-isSecured</param-name>
<param-value>true</param-value>
</context-param>
<!--publish to apim-->
<context-param>
<param-name>managed-api-enabled</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>managed-api-owner</param-name>
<param-value>admin</param-value>
</context-param>
</web-app> </web-app>

@ -34,7 +34,6 @@
<url>http://wso2.org</url> <url>http://wso2.org</url>
<modules> <modules>
<module>org.wso2.carbon.device.mgt.iot.arduino.analytics</module>
<module>org.wso2.carbon.device.mgt.iot.arduino.api</module> <module>org.wso2.carbon.device.mgt.iot.arduino.api</module>
<module>org.wso2.carbon.device.mgt.iot.arduino.plugin</module> <module>org.wso2.carbon.device.mgt.iot.arduino.plugin</module>
<module>org.wso2.carbon.device.mgt.iot.arduino.ui</module> <module>org.wso2.carbon.device.mgt.iot.arduino.ui</module>

@ -21,11 +21,11 @@ package org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl;
import org.wso2.carbon.apimgt.annotations.api.API; import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType; import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType;
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature; import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature;
import javax.websocket.server.PathParam;
import javax.ws.rs.FormParam; import javax.ws.rs.FormParam;
import javax.ws.rs.HeaderParam; import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
@API(name = "digital_display", version = "1.0.0", context = "/digital_display", tags = {"digital_display"}) @API(name = "digital_display", version = "1.0.0", context = "/digital_display", tags = {"digital_display"})
@ -54,7 +54,7 @@ public interface DigitalDisplayControllerService {
@POST @POST
@Feature(code = "terminate-display", name = "Terminate Display", type = "operation", @Feature(code = "terminate-display", name = "Terminate Display", type = "operation",
description = "Terminate all running process in Digital Display") description = "Terminate all running process in Digital Display")
Response terminateDisplay(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") String sessionId); Response terminateDisplay(@HeaderParam("sessionId") String sessionId, @PathParam("deviceId") String deviceId);
/** /**
* Reboot running digital display * Reboot running digital display

@ -20,10 +20,8 @@ package org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType;
import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature; import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature;
import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig; import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
import org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl.exception.DigitalDisplayException; import org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl.exception.DigitalDisplayException;
@ -32,13 +30,11 @@ import org.wso2.carbon.device.mgt.iot.digitaldisplay.plugin.constants.DigitalDis
import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener; import org.wso2.carbon.device.mgt.iot.service.IoTServerStartupListener;
import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException; import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;
import javax.servlet.http.HttpServletResponse;
import javax.websocket.server.PathParam;
import javax.ws.rs.FormParam; import javax.ws.rs.FormParam;
import javax.ws.rs.HeaderParam; import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.core.Context; import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
public class DigitalDisplayControllerServiceImpl implements DigitalDisplayControllerService { public class DigitalDisplayControllerServiceImpl implements DigitalDisplayControllerService {
@ -46,51 +42,9 @@ public class DigitalDisplayControllerServiceImpl implements DigitalDisplayContro
private static Log log = LogFactory.getLog(DigitalDisplayControllerServiceImpl.class); private static Log log = LogFactory.getLog(DigitalDisplayControllerServiceImpl.class);
private static DigitalDisplayMQTTConnector digitalDisplayMQTTConnector; private static DigitalDisplayMQTTConnector digitalDisplayMQTTConnector;
private boolean waitForServerStartup() { @Path("device/{deviceId}/restart-browser")
while (!IoTServerStartupListener.isServerReady()) { @POST
try { public Response restartBrowser(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") String sessionId) {
Thread.sleep(1000);
} catch (InterruptedException e) {
return true;
}
}
return false;
}
public DigitalDisplayMQTTConnector getDigitalDisplayMQTTConnector() {
return DigitalDisplayControllerServiceImpl.digitalDisplayMQTTConnector;
}
public void setDigitalDisplayMQTTConnector(final
DigitalDisplayMQTTConnector digitalDisplayMQTTConnector) {
Runnable connector = new Runnable() {
public void run() {
if (waitForServerStartup()) {
return;
}
DigitalDisplayControllerServiceImpl.digitalDisplayMQTTConnector = digitalDisplayMQTTConnector;
//The delay is added for the server starts up.
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
if (MqttConfig.getInstance().isEnabled()) {
synchronized (digitalDisplayMQTTConnector) {
digitalDisplayMQTTConnector.connect();
}
} else {
log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, not started.");
}
}
};
Thread connectorThread = new Thread(connector);
connectorThread.setDaemon(true);
connectorThread.start();
}
public Response restartBrowser(String deviceId, String sessionId) {
try { try {
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.RESTART_BROWSER_CONSTANT + "::", ""); sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.RESTART_BROWSER_CONSTANT + "::", "");
return Response.ok().build(); return Response.ok().build();
@ -101,7 +55,10 @@ public class DigitalDisplayControllerServiceImpl implements DigitalDisplayContro
} }
} }
public Response terminateDisplay(String deviceId, String sessionId) { @Path("device/{deviceId}/terminate-display")
@POST
public Response terminateDisplay(@HeaderParam("sessionId") String sessionId,
@PathParam("deviceId") String deviceId) {
try { try {
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.TERMINATE_DISPLAY_CONSTANT + "::", ""); sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.TERMINATE_DISPLAY_CONSTANT + "::", "");
return Response.ok().build(); return Response.ok().build();
@ -110,10 +67,11 @@ public class DigitalDisplayControllerServiceImpl implements DigitalDisplayContro
} catch (DigitalDisplayException e) { } catch (DigitalDisplayException e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
} }
} }
public Response restartDisplay(String deviceId, String sessionId) { @Path("device/{deviceId}/restart-display")
@POST
public Response restartDisplay(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") String sessionId) {
try { try {
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.RESTART_DISPLAY_CONSTANT + "::", ""); sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.RESTART_DISPLAY_CONSTANT + "::", "");
return Response.ok().build(); return Response.ok().build();
@ -124,7 +82,11 @@ public class DigitalDisplayControllerServiceImpl implements DigitalDisplayContro
} }
} }
public Response editSequence(String deviceId, String name, String attribute, String newValue, String sessionId) { @Path("device/{deviceId}/edit-sequence")
@POST
public Response editSequence(@PathParam("deviceId") String deviceId, @FormParam("name") String name,
@FormParam("attribute") String attribute, @FormParam("new-value") String newValue,
@HeaderParam("sessionId") String sessionId) {
try { try {
String params = name + "|" + attribute + "|" + newValue; String params = name + "|" + attribute + "|" + newValue;
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.EDIT_SEQUENCE_CONSTANT + "::", params); sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.EDIT_SEQUENCE_CONSTANT + "::", params);
@ -136,7 +98,12 @@ public class DigitalDisplayControllerServiceImpl implements DigitalDisplayContro
} }
} }
public Response uploadContent(String deviceId, String remotePath, String screenName, String sessionId) {
@Path("device/{deviceId}/upload-content")
@POST
public Response uploadContent(@PathParam("deviceId") String deviceId, @FormParam("remote-path") String remotePath,
@FormParam("screen-name") String screenName,
@HeaderParam("sessionId") String sessionId) {
try { try {
String params = remotePath + "|" + screenName; String params = remotePath + "|" + screenName;
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.UPLOAD_CONTENT_CONSTANT + "::", sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.UPLOAD_CONTENT_CONSTANT + "::",
@ -149,8 +116,12 @@ public class DigitalDisplayControllerServiceImpl implements DigitalDisplayContro
} }
} }
public Response addNewResource(String deviceId, String type, String time, String path, String name, String position, @Path("device/{deviceId}/add-resource")
String sessionId) { @POST
public Response addNewResource(@PathParam("deviceId") String deviceId, @FormParam("type") String type,
@FormParam("time") String time, @FormParam("path") String path,
@FormParam("name") String name, @FormParam("position") String position,
@HeaderParam("sessionId") String sessionId) {
String params; String params;
try { try {
if (position.isEmpty()) { if (position.isEmpty()) {
@ -168,7 +139,10 @@ public class DigitalDisplayControllerServiceImpl implements DigitalDisplayContro
} }
} }
public Response removeResource(String deviceId, String name, String sessionId) { @Path("device/{deviceId}/remove-resource")
@POST
public Response removeResource(@PathParam("deviceId") String deviceId, @FormParam("name") String name,
@HeaderParam("sessionId") String sessionId) {
try { try {
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.REMOVE_RESOURCE_CONSTANT + "::", name); sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.REMOVE_RESOURCE_CONSTANT + "::", name);
return Response.ok().build(); return Response.ok().build();
@ -179,7 +153,9 @@ public class DigitalDisplayControllerServiceImpl implements DigitalDisplayContro
} }
} }
public Response restartServer(String deviceId, String sessionId) { @Path("device/{deviceId}/restart-server")
@POST
public Response restartServer(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") String sessionId) {
try { try {
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.RESTART_SERVER_CONSTANT + "::", ""); sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.RESTART_SERVER_CONSTANT + "::", "");
return Response.ok().build(); return Response.ok().build();
@ -190,7 +166,10 @@ public class DigitalDisplayControllerServiceImpl implements DigitalDisplayContro
} }
} }
public Response showScreenshot(String deviceId, String sessionId) {
@Path("device/{deviceId}/screenshot")
@POST
public Response showScreenshot(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") String sessionId) {
try { try {
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.SCREENSHOT_CONSTANT + "::", ""); sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.SCREENSHOT_CONSTANT + "::", "");
return Response.ok().build(); return Response.ok().build();
@ -201,7 +180,10 @@ public class DigitalDisplayControllerServiceImpl implements DigitalDisplayContro
} }
} }
public Response getDevicestatus(String deviceId, String sessionId) { @Path("device/{deviceId}/get-device-status")
@POST
public Response getDevicestatus(@PathParam("deviceId") String deviceId,
@HeaderParam("sessionId") String sessionId) {
try { try {
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.GET_DEVICE_STATUS_CONSTANT + "::", ""); sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.GET_DEVICE_STATUS_CONSTANT + "::", "");
return Response.ok().build(); return Response.ok().build();
@ -212,7 +194,9 @@ public class DigitalDisplayControllerServiceImpl implements DigitalDisplayContro
} }
} }
public Response getResources(String deviceId, String sessionId) { @Path("device/{deviceId}/get-content-list")
@POST
public Response getResources(@PathParam("deviceId") String deviceId, @HeaderParam("sessionId") String sessionId) {
try { try {
sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.GET_CONTENTLIST_CONSTANT + "::", ""); sendCommandViaMQTT(deviceId, sessionId + "::" + DigitalDisplayConstants.GET_CONTENTLIST_CONSTANT + "::", "");
return Response.ok().build(); return Response.ok().build();
@ -246,4 +230,46 @@ public class DigitalDisplayControllerServiceImpl implements DigitalDisplayContro
} }
} }
private boolean waitForServerStartup() {
while (!IoTServerStartupListener.isServerReady()) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
return true;
}
}
return false;
}
public DigitalDisplayMQTTConnector getDigitalDisplayMQTTConnector() {
return DigitalDisplayControllerServiceImpl.digitalDisplayMQTTConnector;
}
public void setDigitalDisplayMQTTConnector(final
DigitalDisplayMQTTConnector digitalDisplayMQTTConnector) {
Runnable connector = new Runnable() {
public void run() {
if (waitForServerStartup()) {
return;
}
//The delay is added for the server to starts up.
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
DigitalDisplayControllerServiceImpl.digitalDisplayMQTTConnector = digitalDisplayMQTTConnector;
if (MqttConfig.getInstance().isEnabled()) {
digitalDisplayMQTTConnector.connect();
} else {
log.warn("MQTT disabled in 'devicemgt-config.xml'. " +
"Hence, DigitalDisplayMQTTConnector not started.");
}
}
};
Thread connectorThread = new Thread(connector);
connectorThread.start();
}
} }

@ -24,7 +24,6 @@ import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT; import javax.ws.rs.PUT;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
@ -33,6 +32,7 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
@Path("enrollment")
@API(name = "digital_display_mgt", version = "1.0.0", context = "/digital_display_mgt", tags = {"digital_display"}) @API(name = "digital_display_mgt", version = "1.0.0", context = "/digital_display_mgt", tags = {"digital_display"})
@DeviceType(value = "digital_display") @DeviceType(value = "digital_display")
public interface DigitalDisplayManagerService { public interface DigitalDisplayManagerService {

@ -39,6 +39,15 @@ import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException; import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreException;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -46,38 +55,16 @@ import java.nio.charset.StandardCharsets;
import java.util.Date; import java.util.Date;
import java.util.UUID; import java.util.UUID;
@Path("enrollment")
public class DigitalDisplayManagerServiceImpl implements DigitalDisplayManagerService { public class DigitalDisplayManagerServiceImpl implements DigitalDisplayManagerService {
private static Log log = LogFactory.getLog(DigitalDisplayManagerServiceImpl.class); private static Log log = LogFactory.getLog(DigitalDisplayManagerServiceImpl.class);
private static final String KEY_TYPE = "PRODUCTION"; private static final String KEY_TYPE = "PRODUCTION";
private static ApiApplicationKey apiApplicationKey; private static ApiApplicationKey apiApplicationKey;
private boolean register(String deviceId, String name) { @Path("devices/{device_id}")
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); @DELETE
deviceIdentifier.setId(deviceId); public Response removeDevice(@PathParam("device_id") String deviceId) {
deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE);
try {
if (APIUtil.getDeviceManagementService().isEnrolled(deviceIdentifier)) {
return false;
}
Device device = new Device();
device.setDeviceIdentifier(deviceId);
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
enrolmentInfo.setDateOfEnrolment(new Date().getTime());
enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
device.setName(name);
device.setType(DigitalDisplayConstants.DEVICE_TYPE);
enrolmentInfo.setOwner(APIUtil.getAuthenticatedUser());
device.setEnrolmentInfo(enrolmentInfo);
boolean added = APIUtil.getDeviceManagementService().enrollDevice(device);
return added;
} catch (DeviceManagementException e) {
return false;
}
}
public Response removeDevice(String deviceId) {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(deviceId); deviceIdentifier.setId(deviceId);
deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE); deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE);
@ -94,7 +81,9 @@ public class DigitalDisplayManagerServiceImpl implements DigitalDisplayManagerSe
} }
} }
public Response updateDevice(String deviceId, String name) { @Path("devices/{device_id}")
@PUT
public Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name) {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(deviceId); deviceIdentifier.setId(deviceId);
deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE); deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE);
@ -114,8 +103,11 @@ public class DigitalDisplayManagerServiceImpl implements DigitalDisplayManagerSe
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
} }
} }
@Path("devices/{device_id}")
public Response getDevice(String deviceId) { @GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response getDevice(@PathParam("device_id") String deviceId) {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(deviceId); deviceIdentifier.setId(deviceId);
deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE); deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE);
@ -127,10 +119,12 @@ public class DigitalDisplayManagerServiceImpl implements DigitalDisplayManagerSe
return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).build();
} }
} }
@Path("devices/download")
public Response downloadSketch(String deviceName) { @GET
@Produces("application/octet-stream")
public Response downloadSketch(@QueryParam("deviceName") String customDeviceName) {
try { try {
ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName); ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), customDeviceName);
Response.ResponseBuilder response = Response.ok(FileUtils.readFileToByteArray(zipFile.getZipFile())); Response.ResponseBuilder response = Response.ok(FileUtils.readFileToByteArray(zipFile.getZipFile()));
response.type("application/zip"); response.type("application/zip");
response.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\""); response.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\"");
@ -152,6 +146,31 @@ public class DigitalDisplayManagerServiceImpl implements DigitalDisplayManagerSe
} }
} }
private boolean register(String deviceId, String name) {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(deviceId);
deviceIdentifier.setType(DigitalDisplayConstants.DEVICE_TYPE);
try {
if (APIUtil.getDeviceManagementService().isEnrolled(deviceIdentifier)) {
return false;
}
Device device = new Device();
device.setDeviceIdentifier(deviceId);
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
enrolmentInfo.setDateOfEnrolment(new Date().getTime());
enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
device.setName(name);
device.setType(DigitalDisplayConstants.DEVICE_TYPE);
enrolmentInfo.setOwner(APIUtil.getAuthenticatedUser());
device.setEnrolmentInfo(enrolmentInfo);
boolean added = APIUtil.getDeviceManagementService().enrollDevice(device);
return added;
} catch (DeviceManagementException e) {
return false;
}
}
private ZipArchive createDownloadFile(String owner, String deviceName) private ZipArchive createDownloadFile(String owner, String deviceName)
throws DeviceManagementException, JWTClientException, DeviceControllerException, APIManagerException, throws DeviceManagementException, JWTClientException, DeviceControllerException, APIManagerException,
UserStoreException { UserStoreException {

@ -96,7 +96,6 @@ public class DigitalDisplayMQTTConnector extends MQTTTransportHandler {
}; };
Thread connectorThread = new Thread(connector); Thread connectorThread = new Thread(connector);
connectorThread.setDaemon(true);
connectorThread.start(); connectorThread.start();
} }
@ -182,7 +181,6 @@ public class DigitalDisplayMQTTConnector extends MQTTTransportHandler {
}; };
Thread terminatorThread = new Thread(stopConnection); Thread terminatorThread = new Thread(stopConnection);
terminatorThread.setDaemon(true);
terminatorThread.start(); terminatorThread.start();
} }

@ -24,7 +24,7 @@
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd"> http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
<jaxrs:server id="DigitalDisplayController" address="/controller"> <jaxrs:server id="DigitalDisplay" address="/">
<jaxrs:serviceBeans> <jaxrs:serviceBeans>
<bean id="DigitalDisplayManagerControllerService" <bean id="DigitalDisplayManagerControllerService"
class="org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl.DigitalDisplayControllerServiceImpl"> class="org.wso2.carbon.device.mgt.iot.digitaldisplay.service.impl.DigitalDisplayControllerServiceImpl">

@ -21,28 +21,16 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5"> version="2.5">
<display-name>Digital-Display-Agent-Webapp</display-name> <display-name>Digital-Display-Agent-Webapp</display-name>
<servlet> <servlet>
<description>JAX-WS/JAX-RS MDM Android Endpoint</description>
<display-name>JAX-WS/JAX-RS Servlet</display-name>
<servlet-name>CXFServlet</servlet-name> <servlet-name>CXFServlet</servlet-name>
<servlet-class> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup> <load-on-startup>1</load-on-startup>
</servlet> </servlet>
<servlet-mapping> <servlet-mapping>
<servlet-name>CXFServlet</servlet-name> <servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern> <url-pattern>/*</url-pattern>
</servlet-mapping> </servlet-mapping>
<context-param>
<param-name>isSharedWithAllTenants</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>providerTenantDomain</param-name>
<param-value>carbon.super</param-value>
</context-param>
<context-param> <context-param>
<param-name>isAdminService</param-name> <param-name>isAdminService</param-name>
<param-value>false</param-value> <param-value>false</param-value>
@ -51,6 +39,14 @@
<param-name>doAuthentication</param-name> <param-name>doAuthentication</param-name>
<param-value>true</param-value> <param-value>true</param-value>
</context-param> </context-param>
<context-param>
<param-name>isSharedWithAllTenants</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>providerTenantDomain</param-name>
<param-value>carbon.super</param-value>
</context-param>
<!--publish to apim--> <!--publish to apim-->
<context-param> <context-param>
@ -61,17 +57,5 @@
<param-name>managed-api-owner</param-name> <param-name>managed-api-owner</param-name>
<param-value>admin</param-value> <param-value>admin</param-value>
</context-param> </context-param>
<context-param>
<param-name>managed-api-context-template</param-name>
<param-value>/digital_display/{version}</param-value>
</context-param>
<context-param>
<param-name>managed-api-application</param-name>
<param-value>digital_display</param-value>
</context-param>
<context-param>
<param-name>managed-api-isSecured</param-name>
<param-value>true</param-value>
</context-param>
</web-app> </web-app>

@ -38,7 +38,10 @@ public class DroneControllerServiceImpl implements DroneControllerService {
private ConcurrentHashMap<String, String> deviceToIpMap = new ConcurrentHashMap<>(); private ConcurrentHashMap<String, String> deviceToIpMap = new ConcurrentHashMap<>();
private DroneController droneController = new DroneControllerImpl(); private DroneController droneController = new DroneControllerImpl();
public Response registerDeviceIP(String deviceId, String deviceIP, String devicePort) { @Path("device/register/{deviceId}/{ip}/{port}")
@POST
public Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP,
@PathParam("port") String devicePort) {
String result; String result;
String deviceHttpEndpoint = deviceIP + ":" + devicePort; String deviceHttpEndpoint = deviceIP + ":" + devicePort;
deviceToIpMap.put(deviceId, deviceHttpEndpoint); deviceToIpMap.put(deviceId, deviceHttpEndpoint);
@ -49,7 +52,10 @@ public class DroneControllerServiceImpl implements DroneControllerService {
return Response.ok(Response.Status.OK.getStatusCode()).build(); return Response.ok(Response.Status.OK.getStatusCode()).build();
} }
public Response droneController(String deviceId, String action, String duration, String speed) { @Path("device/{deviceId}/send_command")
@POST
public Response droneController(@PathParam("deviceId") String deviceId, @FormParam("action") String action,
@FormParam("duration") String duration, @FormParam("speed") String speed) {
try { try {
DroneAnalyzerServiceUtils.sendControlCommand(droneController, deviceId, action, Double.valueOf(speed), DroneAnalyzerServiceUtils.sendControlCommand(droneController, deviceId, action, Double.valueOf(speed),
Double.valueOf(duration)); Double.valueOf(duration));

@ -31,6 +31,7 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
@Path("enrollment")
@API(name = "drone_analyzer_mgt", version = "1.0.0", context = "/drone_analyzer_mgt", tags = {"drone_analyzer"}) @API(name = "drone_analyzer_mgt", version = "1.0.0", context = "/drone_analyzer_mgt", tags = {"drone_analyzer"})
@DeviceType(value = "drone_analyzer") @DeviceType(value = "drone_analyzer")
public interface DroneManagerService { public interface DroneManagerService {

@ -39,6 +39,15 @@ import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo; import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException; import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException;
import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreException;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -47,39 +56,16 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@Path("enrollment")
public class DroneManagerServiceImpl implements DroneManagerService { public class DroneManagerServiceImpl implements DroneManagerService {
private static org.apache.commons.logging.Log log = LogFactory.getLog(DroneManagerServiceImpl.class); private static org.apache.commons.logging.Log log = LogFactory.getLog(DroneManagerServiceImpl.class);
private static final String KEY_TYPE = "PRODUCTION"; private static final String KEY_TYPE = "PRODUCTION";
private static ApiApplicationKey apiApplicationKey; private static ApiApplicationKey apiApplicationKey;
private boolean register(String deviceId, String name) { @Path("devices/{device_id}")
try { @DELETE
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); public Response removeDevice(@PathParam("device_id") String deviceId) {
deviceIdentifier.setId(deviceId);
deviceIdentifier.setType(DroneConstants.DEVICE_TYPE);
if (APIUtil.getDeviceManagementService().isEnrolled(deviceIdentifier)) {
return false;
}
Device device = new Device();
device.setDeviceIdentifier(deviceId);
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
enrolmentInfo.setDateOfEnrolment(new Date().getTime());
enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
device.setName(name);
device.setType(DroneConstants.DEVICE_TYPE);
enrolmentInfo.setOwner(APIUtil.getAuthenticatedUser());
device.setEnrolmentInfo(enrolmentInfo);
boolean added = APIUtil.getDeviceManagementService().enrollDevice(device);
return added;
} catch (DeviceManagementException e) {
return false;
}
}
public Response removeDevice(String deviceId) {
try { try {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(deviceId); deviceIdentifier.setId(deviceId);
@ -95,7 +81,10 @@ public class DroneManagerServiceImpl implements DroneManagerService {
} }
} }
public Response updateDevice(String deviceId, String name) {
@Path("devices/{device_id}")
@PUT
public Response updateDevice(@PathParam("device_id") String deviceId, @QueryParam("name") String name) {
try { try {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(deviceId); deviceIdentifier.setId(deviceId);
@ -116,7 +105,11 @@ public class DroneManagerServiceImpl implements DroneManagerService {
} }
} }
public Response getDevice(String deviceId) { @Path("devices/{device_id}")
@GET
@Consumes("application/json")
@Produces("application/json")
public Response getDevice(@PathParam("device_id") String deviceId) {
try { try {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(deviceId); deviceIdentifier.setId(deviceId);
@ -128,6 +121,10 @@ public class DroneManagerServiceImpl implements DroneManagerService {
} }
} }
@Path("devices")
@GET
@Consumes("application/json")
@Produces("application/json")
public Response getDroneDevices() { public Response getDroneDevices() {
try { try {
List<Device> userDevices = APIUtil.getDeviceManagementService().getDevicesOfUser(APIUtil.getAuthenticatedUser()); List<Device> userDevices = APIUtil.getDeviceManagementService().getDevicesOfUser(APIUtil.getAuthenticatedUser());
@ -146,7 +143,11 @@ public class DroneManagerServiceImpl implements DroneManagerService {
} }
} }
public Response downloadSketch(String deviceName, String sketchType) { @Path("devices/{sketch_type}/download")
@GET
@Produces("application/octet-stream")
public Response downloadSketch(@QueryParam("deviceName") String deviceName, @PathParam("sketch_type") String
sketchType) {
//create new device id //create new device id
String deviceId = shortUUID(); String deviceId = shortUUID();
@ -172,10 +173,12 @@ public class DroneManagerServiceImpl implements DroneManagerService {
Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile()); Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile());
rb.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\""); rb.header("Content-Disposition", "attachment; filename=\"" + zipFile.getFileName() + "\"");
return rb.build(); return rb.build();
} }
public Response generateSketchLink(String deviceName, String sketchType) { @Path("devices/{sketch_type}/generate_link")
@GET
public Response generateSketchLink(@QueryParam("deviceName") String deviceName,
@PathParam("sketch_type") String sketchType) {
try { try {
ZipArchive zipFile = createDownloadFile(deviceName, sketchType); ZipArchive zipFile = createDownloadFile(deviceName, sketchType);
Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId()); Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId());
@ -195,6 +198,32 @@ public class DroneManagerServiceImpl implements DroneManagerService {
} }
} }
private boolean register(String deviceId, String name) {
try {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(deviceId);
deviceIdentifier.setType(DroneConstants.DEVICE_TYPE);
if (APIUtil.getDeviceManagementService().isEnrolled(deviceIdentifier)) {
return false;
}
Device device = new Device();
device.setDeviceIdentifier(deviceId);
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
enrolmentInfo.setDateOfEnrolment(new Date().getTime());
enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
device.setName(name);
device.setType(DroneConstants.DEVICE_TYPE);
enrolmentInfo.setOwner(APIUtil.getAuthenticatedUser());
device.setEnrolmentInfo(enrolmentInfo);
boolean added = APIUtil.getDeviceManagementService().enrollDevice(device);
return added;
} catch (DeviceManagementException e) {
return false;
}
}
private ZipArchive createDownloadFile(String deviceName, String sketchType) private ZipArchive createDownloadFile(String deviceName, String sketchType)
throws DeviceManagementException, JWTClientException, APIManagerException, DeviceControllerException, throws DeviceManagementException, JWTClientException, APIManagerException, DeviceControllerException,
UserStoreException { UserStoreException {

@ -55,7 +55,6 @@ public class DroneRealTimeService {
} }
}; };
Thread connectorThread = new Thread(connector); Thread connectorThread = new Thread(connector);
connectorThread.setDaemon(true);
connectorThread.start(); connectorThread.start();
} }

@ -134,7 +134,6 @@ public class DroneAnalyzerXMPPConnector extends XMPPTransportHandler {
} }
}; };
Thread terminatorThread = new Thread(stopConnection); Thread terminatorThread = new Thread(stopConnection);
terminatorThread.setDaemon(true);
terminatorThread.start(); terminatorThread.start();
} }

@ -6,44 +6,41 @@
metadata-complete="true"> metadata-complete="true">
<display-name>WSO2 IoT Server</display-name> <display-name>WSO2 IoT Server</display-name>
<description>WSO2 IoT Server</description> <description>WSO2 IoT Server</description>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<context-param> <servlet>
<param-name>isAdminService</param-name> <servlet-name>CXFServlet</servlet-name>
<param-value>false</param-value> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</context-param> <load-on-startup>1</load-on-startup>
<context-param> </servlet>
<param-name>doAuthentication</param-name> <servlet-mapping>
<param-value>false</param-value> <servlet-name>CXFServlet</servlet-name>
</context-param> <url-pattern>/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>isAdminService</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>doAuthentication</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>isSharedWithAllTenants</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>providerTenantDomain</param-name>
<param-value>carbon.super</param-value>
</context-param>
<!--publish to apim-->
<context-param>
<param-name>managed-api-enabled</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>managed-api-owner</param-name>
<param-value>admin</param-value>
</context-param>
<!--publish to apim-->
<context-param>
<param-name>managed-api-enabled</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>managed-api-owner</param-name>
<param-value>admin</param-value>
</context-param>
<context-param>
<param-name>managed-api-context-template</param-name>
<param-value>/drone_analyzer/{version}</param-value>
</context-param>
<context-param>
<param-name>managed-api-application</param-name>
<param-value>drone_analyzer</param-value>
</context-param>
<context-param>
<param-name>managed-api-isSecured</param-name>
<param-value>true</param-value>
</context-param>
</web-app> </web-app>

@ -0,0 +1,82 @@
<?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.
-->
<project name="create-sample-sensor-capps" default="zip" basedir=".">
<property name="project-name" value="${ant.project.name}"/>
<property name="target-dir" value="target/carbonapps"/>
<property name="src-dir" value="src/main/resources/carbonapps"/>
<property name="GPS_dir" value="GPS"/>
<property name="Light_dir" value="Light"/>
<property name="Battery_dir" value="Battery"/>
<property name="Magnetic_dir" value="Magnetic"/>
<property name="Accelerometer_dir" value="Accelerometer"/>
<property name="Gravity_dir" value="Gravity"/>
<property name="Gyroscope_dir" value="Gyroscope"/>
<property name="Proximity_dir" value="Proximity"/>
<property name="Pressure_dir" value="Pressure"/>
<property name="Rotation_dir" value="Rotation"/>
<property name="Wordcounter_dir" value="WordCount"/>
<property name="Temperature_dir" value="Temperature"/>
<target name="clean">
<delete dir="${target-dir}" />
</target>
<target name="zip" depends="clean">
<mkdir dir="${target-dir}"/>
<zip destfile="${target-dir}/${GPS_dir}.car">
<zipfileset dir="${src-dir}/${GPS_dir}"/>
</zip>
<zip destfile="${target-dir}/${Light_dir}.car">
<zipfileset dir="${src-dir}/${Light_dir}"/>
</zip>
<zip destfile="${target-dir}/${Battery_dir}.car">
<zipfileset dir="${src-dir}/${Battery_dir}"/>
</zip>
<zip destfile="${target-dir}/${Magnetic_dir}.car">
<zipfileset dir="${src-dir}/${Magnetic_dir}"/>
</zip>
<zip destfile="${target-dir}/${Accelerometer_dir}.car">
<zipfileset dir="${src-dir}/${Accelerometer_dir}"/>
</zip>
<zip destfile="${target-dir}/${Gravity_dir}.car">
<zipfileset dir="${src-dir}/${Gravity_dir}"/>
</zip>
<zip destfile="${target-dir}/${Gyroscope_dir}.car">
<zipfileset dir="${src-dir}/${Gyroscope_dir}"/>
</zip>
<zip destfile="${target-dir}/${Pressure_dir}.car">
<zipfileset dir="${src-dir}/${Pressure_dir}"/>
</zip>
<zip destfile="${target-dir}/${Rotation_dir}.car">
<zipfileset dir="${src-dir}/${Rotation_dir}"/>
</zip>
<zip destfile="${target-dir}/${Proximity_dir}.car">
<zipfileset dir="${src-dir}/${Proximity_dir}"/>
</zip>
<zip destfile="${target-dir}/${Wordcounter_dir}.car">
<zipfileset dir="${src-dir}/${Wordcounter_dir}"/>
</zip>
<zip destfile="${target-dir}/${Temperature_dir}.car">
<zipfileset dir="${src-dir}/${Temperature_dir}"/>
</zip>
</target>
</project>

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- <!--
~ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. ~ Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~ ~
@ -22,15 +21,15 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent> <parent>
<artifactId>arduino-plugin</artifactId>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId> <groupId>org.wso2.carbon.devicemgt-plugins</groupId>
<artifactId>iot-analytics</artifactId>
<version>2.1.0-SNAPSHOT</version> <version>2.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.mgt.iot.arduino.analytics</artifactId> <artifactId>org.wso2.carbon.device.mgt.iot.analytics</artifactId>
<name>WSO2 Carbon - IoT Server Arduino Analytics capp</name> <name>WSO2 Carbon - IoT Server Analytics C-APP</name>
<packaging>pom</packaging> <packaging>pom</packaging>
<build> <build>

@ -52,7 +52,21 @@
<Type>LONG</Type> <Type>LONG</Type>
</ColumnDefinition> </ColumnDefinition>
<ColumnDefinition> <ColumnDefinition>
<Name>accelerometer</Name> <Name>x</Name>
<EnableIndexing>false</EnableIndexing>
<IsPrimaryKey>false</IsPrimaryKey>
<EnableScoreParam>false</EnableScoreParam>
<Type>FLOAT</Type>
</ColumnDefinition>
<ColumnDefinition>
<Name>y</Name>
<EnableIndexing>false</EnableIndexing>
<IsPrimaryKey>false</IsPrimaryKey>
<EnableScoreParam>false</EnableScoreParam>
<Type>FLOAT</Type>
</ColumnDefinition>
<ColumnDefinition>
<Name>z</Name>
<EnableIndexing>false</EnableIndexing> <EnableIndexing>false</EnableIndexing>
<IsPrimaryKey>false</IsPrimaryKey> <IsPrimaryKey>false</IsPrimaryKey>
<EnableScoreParam>false</EnableScoreParam> <EnableScoreParam>false</EnableScoreParam>

@ -17,7 +17,7 @@
~ under the License. ~ under the License.
--> -->
<artifact name="Eventstream_temperature" version="1.0.0" type="event/stream" serverRole="DataAnalyticsServer"> <artifact name="Eventstream_accelerometer" version="1.0.0" type="event/stream" serverRole="DataAnalyticsServer">
<file>org.wso2.iot.devices.temperature_1.0.0.json</file> <file>org.wso2.iot.devices.accelerometer_1.0.0.json</file>
</artifact> </artifact>

@ -22,10 +22,9 @@
<Script> <Script>
CREATE TEMPORARY TABLE DeviceAccelerometerData USING CarbonAnalytics OPTIONS(tableName "ORG_WSO2_IOT_DEVICES_ACCELEROMETER"); CREATE TEMPORARY TABLE DeviceAccelerometerData USING CarbonAnalytics OPTIONS(tableName "ORG_WSO2_IOT_DEVICES_ACCELEROMETER");
CREATE TEMPORARY TABLE DeviceAccelerometerSummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_ACCELEROMETER_SUMMARY", schema "accelerometer FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time"); CREATE TEMPORARY TABLE DeviceAccelerometerSummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_ACCELEROMETER_SUMMARY", schema "x FLOAT, y FLOAT, z FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
insert overwrite table DeviceAccelerometerSummaryData select x, y, z, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceAccelerometerData group by x, y, z, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
insert overwrite table DeviceAccelerometerSummaryData select accelerometer, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceAccelerometerData group by accelerometer, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
</Script> </Script>
<CronExpression>0 * * * * ?</CronExpression> <CronExpression>0 * * * * ?</CronExpression>
</Analytics> </Analytics>

@ -19,11 +19,9 @@
<artifacts> <artifacts>
<artifact name="Accelerometer_CAPP" version="1.0.0" type="carbon/application"> <artifact name="Accelerometer_CAPP" version="1.0.0" type="carbon/application">
<dependency artifact="Eventstream_accelerometer" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/> <dependency artifact="Eventstream_accelerometer" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
<dependency artifact="Eventstore_accelerometer" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/> <dependency artifact="Eventstore_accelerometer" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
<dependency artifact="Eventreceiver_accelerometer" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/> <dependency artifact="Eventreceiver_accelerometer" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
<dependency artifact="Sparkscripts" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/> <dependency artifact="Sparkscripts" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
</artifact> </artifact>
</artifacts> </artifacts>

@ -52,11 +52,11 @@
<Type>LONG</Type> <Type>LONG</Type>
</ColumnDefinition> </ColumnDefinition>
<ColumnDefinition> <ColumnDefinition>
<Name>battery</Name> <Name>level</Name>
<EnableIndexing>false</EnableIndexing> <EnableIndexing>false</EnableIndexing>
<IsPrimaryKey>false</IsPrimaryKey> <IsPrimaryKey>false</IsPrimaryKey>
<EnableScoreParam>false</EnableScoreParam> <EnableScoreParam>false</EnableScoreParam>
<Type>FLOAT</Type> <Type>INT</Type>
</ColumnDefinition> </ColumnDefinition>
</TableSchema> </TableSchema>
</EventStoreConfiguration> </EventStoreConfiguration>

@ -22,10 +22,9 @@
<Script> <Script>
CREATE TEMPORARY TABLE DeviceBatteryData USING CarbonAnalytics OPTIONS(tableName "ORG_WSO2_IOT_DEVICES_BATTERY"); CREATE TEMPORARY TABLE DeviceBatteryData USING CarbonAnalytics OPTIONS(tableName "ORG_WSO2_IOT_DEVICES_BATTERY");
CREATE TEMPORARY TABLE DeviceBatterySummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_BATTERY_SUMMARY", schema "battery FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time"); CREATE TEMPORARY TABLE DeviceBatterySummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_BATTERY_SUMMARY", schema "level INT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
insert overwrite table DeviceBatterySummaryData select level, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceBatteryData group by level, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
insert overwrite table DeviceBatterySummaryData select battery, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceBatteryData group by battery, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
</Script> </Script>
<CronExpression>0 * * * * ?</CronExpression> <CronExpression>0 * * * * ?</CronExpression>
</Analytics> </Analytics>

@ -56,14 +56,14 @@
<EnableIndexing>false</EnableIndexing> <EnableIndexing>false</EnableIndexing>
<IsPrimaryKey>false</IsPrimaryKey> <IsPrimaryKey>false</IsPrimaryKey>
<EnableScoreParam>false</EnableScoreParam> <EnableScoreParam>false</EnableScoreParam>
<Type>FLOAT</Type> <Type>DOUBLE</Type>
</ColumnDefinition> </ColumnDefinition>
<ColumnDefinition> <ColumnDefinition>
<Name>longitude</Name> <Name>longitude</Name>
<EnableIndexing>false</EnableIndexing> <EnableIndexing>false</EnableIndexing>
<IsPrimaryKey>false</IsPrimaryKey> <IsPrimaryKey>false</IsPrimaryKey>
<EnableScoreParam>false</EnableScoreParam> <EnableScoreParam>false</EnableScoreParam>
<Type>FLOAT</Type> <Type>DOUBLE</Type>
</ColumnDefinition> </ColumnDefinition>
</TableSchema> </TableSchema>
</EventStoreConfiguration> </EventStoreConfiguration>

@ -10,12 +10,8 @@
{"name":"time","type":"LONG"} {"name":"time","type":"LONG"}
], ],
"payloadData": [ "payloadData": [
{ {"name": "latitude","type": "DOUBLE"},
"name": "latitude","type": "FLOAT" {"name": "longitude","type": "DOUBLE"}
},
{
"name": "longitude","type": "FLOAT"
}
] ]
} }

@ -22,8 +22,7 @@
<Script> <Script>
CREATE TEMPORARY TABLE DeviceGPSData USING CarbonAnalytics OPTIONS(tableName "ORG_WSO2_IOT_DEVICES_GPS"); CREATE TEMPORARY TABLE DeviceGPSData USING CarbonAnalytics OPTIONS(tableName "ORG_WSO2_IOT_DEVICES_GPS");
CREATE TEMPORARY TABLE DeviceGPSSummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_GPS_SUMMARY", schema "latitude FLOAT,longitude FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time"); CREATE TEMPORARY TABLE DeviceGPSSummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_GPS_SUMMARY", schema "latitude DOUBLE,longitude DOUBLE, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
insert overwrite table DeviceGPSSummaryData select latitude, longitude, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceGPSData group by latitude, longitude, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT); insert overwrite table DeviceGPSSummaryData select latitude, longitude, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceGPSData group by latitude, longitude, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
</Script> </Script>

@ -19,11 +19,9 @@
<artifacts> <artifacts>
<artifact name="GPS_CAPP" version="1.0.0" type="carbon/application"> <artifact name="GPS_CAPP" version="1.0.0" type="carbon/application">
<dependency artifact="Eventstream_gps" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/> <dependency artifact="Eventstream_gps" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
<dependency artifact="Eventstore_gps" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/> <dependency artifact="Eventstore_gps" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
<dependency artifact="Eventreceiver_gps" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/> <dependency artifact="Eventreceiver_gps" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
<dependency artifact="Sparkscripts" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/> <dependency artifact="Sparkscripts" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
</artifact> </artifact>
</artifacts> </artifacts>

@ -52,7 +52,21 @@
<Type>LONG</Type> <Type>LONG</Type>
</ColumnDefinition> </ColumnDefinition>
<ColumnDefinition> <ColumnDefinition>
<Name>gravity</Name> <Name>x</Name>
<EnableIndexing>false</EnableIndexing>
<IsPrimaryKey>false</IsPrimaryKey>
<EnableScoreParam>false</EnableScoreParam>
<Type>FLOAT</Type>
</ColumnDefinition>
<ColumnDefinition>
<Name>y</Name>
<EnableIndexing>false</EnableIndexing>
<IsPrimaryKey>false</IsPrimaryKey>
<EnableScoreParam>false</EnableScoreParam>
<Type>FLOAT</Type>
</ColumnDefinition>
<ColumnDefinition>
<Name>z</Name>
<EnableIndexing>false</EnableIndexing> <EnableIndexing>false</EnableIndexing>
<IsPrimaryKey>false</IsPrimaryKey> <IsPrimaryKey>false</IsPrimaryKey>
<EnableScoreParam>false</EnableScoreParam> <EnableScoreParam>false</EnableScoreParam>

@ -22,10 +22,9 @@
<Script> <Script>
CREATE TEMPORARY TABLE DeviceGRAVITYData USING CarbonAnalytics OPTIONS(tableName "ORG_WSO2_IOT_DEVICES_GRAVITY"); CREATE TEMPORARY TABLE DeviceGRAVITYData USING CarbonAnalytics OPTIONS(tableName "ORG_WSO2_IOT_DEVICES_GRAVITY");
CREATE TEMPORARY TABLE DeviceGRAVITYSummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_GRAVITY_SUMMARY", schema "gravity FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time"); CREATE TEMPORARY TABLE DeviceGRAVITYSummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_GRAVITY_SUMMARY", schema "x FLOAT, y FLOAT,z FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
insert overwrite table DeviceGRAVITYSummaryData select x, y, z, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceGRAVITYData group by x, y, z, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
insert overwrite table DeviceGRAVITYSummaryData select gravity, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceGRAVITYData group by gravity, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
</Script> </Script>
<CronExpression>0 * * * * ?</CronExpression> <CronExpression>0 * * * * ?</CronExpression>
</Analytics> </Analytics>

@ -19,11 +19,9 @@
<artifacts> <artifacts>
<artifact name="GRAVITY_CAPP" version="1.0.0" type="carbon/application"> <artifact name="GRAVITY_CAPP" version="1.0.0" type="carbon/application">
<dependency artifact="Eventstream_gravity" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/> <dependency artifact="Eventstream_gravity" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
<dependency artifact="Eventstore_gravity" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/> <dependency artifact="Eventstore_gravity" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
<dependency artifact="Eventreceiver_gravity" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/> <dependency artifact="Eventreceiver_gravity" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
<dependency artifact="Sparkscripts" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/> <dependency artifact="Sparkscripts" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
</artifact> </artifact>
</artifacts> </artifacts>

@ -52,7 +52,21 @@
<Type>LONG</Type> <Type>LONG</Type>
</ColumnDefinition> </ColumnDefinition>
<ColumnDefinition> <ColumnDefinition>
<Name>gyroscope</Name> <Name>x</Name>
<EnableIndexing>false</EnableIndexing>
<IsPrimaryKey>false</IsPrimaryKey>
<EnableScoreParam>false</EnableScoreParam>
<Type>FLOAT</Type>
</ColumnDefinition>
<ColumnDefinition>
<Name>y</Name>
<EnableIndexing>false</EnableIndexing>
<IsPrimaryKey>false</IsPrimaryKey>
<EnableScoreParam>false</EnableScoreParam>
<Type>FLOAT</Type>
</ColumnDefinition>
<ColumnDefinition>
<Name>z</Name>
<EnableIndexing>false</EnableIndexing> <EnableIndexing>false</EnableIndexing>
<IsPrimaryKey>false</IsPrimaryKey> <IsPrimaryKey>false</IsPrimaryKey>
<EnableScoreParam>false</EnableScoreParam> <EnableScoreParam>false</EnableScoreParam>

@ -22,10 +22,9 @@
<Script> <Script>
CREATE TEMPORARY TABLE DeviceGYROSCOPEData USING CarbonAnalytics OPTIONS(tableName "ORG_WSO2_IOT_DEVICES_GYROSCOPE"); CREATE TEMPORARY TABLE DeviceGYROSCOPEData USING CarbonAnalytics OPTIONS(tableName "ORG_WSO2_IOT_DEVICES_GYROSCOPE");
CREATE TEMPORARY TABLE DeviceGYROSCOPESummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_GYROSCOPE_SUMMARY", schema "gyroscope FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time"); CREATE TEMPORARY TABLE DeviceGYROSCOPESummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_GYROSCOPE_SUMMARY", schema "x FLOAT, y FLOAT, z FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
insert overwrite table DeviceGYROSCOPESummaryData select x, y, z, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceGYROSCOPEData group by x, y, z, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
insert overwrite table DeviceGYROSCOPESummaryData select gyroscope, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceGYROSCOPEData group by gyroscope, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
</Script> </Script>
<CronExpression>0 * * * * ?</CronExpression> <CronExpression>0 * * * * ?</CronExpression>
</Analytics> </Analytics>

@ -24,7 +24,6 @@ CREATE TEMPORARY TABLE DeviceLightData USING CarbonAnalytics OPTIONS(tableName "
CREATE TEMPORARY TABLE DeviceLightSummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_LIGHT_SUMMARY", schema "light FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time"); CREATE TEMPORARY TABLE DeviceLightSummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_LIGHT_SUMMARY", schema "light FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");
insert overwrite table DeviceLightSummaryData select light, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceLightData group by light, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT); insert overwrite table DeviceLightSummaryData select light, meta_deviceType as deviceType, meta_deviceId as deviceId, meta_owner as owner, cast(meta_time/1000 as BIGINT)as time from DeviceLightData group by light, meta_deviceType, meta_deviceId, meta_owner, cast(meta_time/1000 as BIGINT);
</Script> </Script>
<CronExpression>0 * * * * ?</CronExpression> <CronExpression>0 * * * * ?</CronExpression>

@ -19,11 +19,9 @@
<artifacts> <artifacts>
<artifact name="Light_Sensors_CAPP" version="1.0.0" type="carbon/application"> <artifact name="Light_Sensors_CAPP" version="1.0.0" type="carbon/application">
<dependency artifact="Eventstream_light" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/> <dependency artifact="Eventstream_light" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
<dependency artifact="Eventstore_light" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/> <dependency artifact="Eventstore_light" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
<dependency artifact="Eventreceiver_light" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/> <dependency artifact="Eventreceiver_light" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
<dependency artifact="Sparkscripts" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/> <dependency artifact="Sparkscripts" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/>
</artifact> </artifact>
</artifacts> </artifacts>

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save