refactoring code

merge-requests/1/head
GPrathap 9 years ago
parent 70fcea507d
commit bd856c0b75

@ -1,59 +1,89 @@
# cdmf-devicetype-archetype # Install cdmf-devicetype-archetype
To install this maven archetype First you need to download this maven archetype. To download
go to this folder `cdmf-devicetype-archetype` git clone https://github.com/GPrathap/cdmf-devicetype-archetype.git
To install this maven archetype into your local system, inside the cdmf-devicetype-archetype
mvn clean install mvn clean install
To create new project # Create sample device type plugin using cdmf-devicetype-archetype
go to this folder `/wso2iots-1.0.0-SNAPSHOT/samples` First download WOS2 IoT Server and copy the downloaded file to a preferred location and unzip it. The unzipped folder rename as IOTS_HOME.
To create new project go to this folder: IOTS_HOME/samples
mvn archetype:generate -DarchetypeCatalog=local mvn archetype:generate -DarchetypeCatalog=local
Then select the `cdmf.devicetype:cdmf-devicetype-archetype` as new archetype. Then you need to provide groupId, artifactId, Then select the cdmf.devicetype:cdmf-devicetype-archetype as new archetype.
version, packaging, name of your device type and name for sensor as shown bellow.
jobs@jobs-ThinkPad-T530:~/wso2/IoT/m3/product/IOTS_HOME/samples$
mvn archetype:generate -DarchetypeCatalog=local
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.4:generate (default-cli) @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:2.4:generate (default-cli) @ standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:2.4:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)
Choose archetype:
1: local -> org.apache.synapse:synapse-package-archetype (This archetype can be used to create Maven projects that bundle a mediation
into a standalone distribution ready to be executed)
2: local -> org.wso2.mdm:mdm-android-agent-archetype (Creates a MDM-Android agent project)
3: local -> org.wso2.cdmf.devicetype:cdmf-devicetype-archetype (WSO2 CDMF Device Type Archetype)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 3 Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 3
Then you need to provide groupId, artifactId, version, packaging, name of your device type and name for sensor as shown below.
Define value for property 'groupId': : org.homeautomation Define value for property 'groupId': : org.homeautomation
Define value for property 'artifactId': : safeLocker Define value for property 'artifactId': : currentsensor
Define value for property 'version': 1.0-SNAPSHOT: : 1.0.0-SNAPSHOT Define value for property 'version': 1.0-SNAPSHOT: : 1.0.0-SNAPSHOT
Define value for property 'package': org.homeautomation: : Define value for property 'package': org.homeautomation: :
Define value for property 'deviceType': : safeLocker Define value for property 'deviceType': : currentsensor
Define value for property 'nameOfTheSensor': : lock Define value for property 'nameOfTheSensor': : current
Confirm properties configuration: Confirm properties configuration:
groupId: org.homeautomation groupId: org.homeautomation
artifactId: safeLocker artifactId: currentsensor
version: 1.0.0-SNAPSHOT version: 1.0.0-SNAPSHOT
package: org.homeautomation package: org.homeautomation
deviceType: safeLocker deviceType: currentsensor
nameOfTheSensor: lock nameOfTheSensor: current
To install sample app into IOTS
open `device-deployer.xml` which is located in wso2iots-1.0.0-SNAPSHOT directory
Under modules tag add name of sample which you created as module # Configure the device-deployer.xml file that is in the IoTS_HOME directory.
<module>samples/safeLocker</module> Add the new module under the <modules> tag.
Under featureArtifacts tag add feature artifact definition as below <modules>
<module>samples/currentsensor</module>
</modules>
<featureArtifactDef> Add the device type feature under the `<featureArtifacts>` tag.
org.homeautomation:org.homeautomation.safeLocker.feature:1.0.0-SNAPSHOT
<featureArtifactDef>org.homeautomation:org.homeautomation.currentsensor.feature:1.0.0-SNAPSHOT
</featureArtifactDef> </featureArtifactDef>
Under features tag add feature group definition as below
Add the device type feature group under the <features> tag.
<features>
<feature> <feature>
<id>org.homeautomation.safeLocker.feature.group</id> <id>org.homeautomation.currentsensor.feature.group</id>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
</feature> </feature>
</features>
Finally to deploy sample device type into IoT Server
To deploy sample device type into IoT Server
mvn clean install -f device-deployer.xml mvn clean install -f device-deployer.xml
Note: This command should be executed place where `device-deployer.xml` is located Note: This command should be executed place where `device-deployer.xml` is located

@ -1,3 +1,4 @@
<?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.
~ ~
@ -15,7 +16,6 @@
~ specific language governing permissions and limitations ~ specific language governing permissions and limitations
~ under the License. ~ under the License.
--> -->
<assembly <assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

@ -1,8 +1,8 @@
{ {
"name": "org.wso2.iot.devices.${nameOfTheSensor}", "name": "org.wso2.iot.devices.${nameOfTheSensor}",
"version": "1.0.0", "version": "1.0.0",
"nickName": "AC Current Data", "nickName": "${nameOfTheSensor}",
"description": "AC Current data received from the Device", "description": "${nameOfTheSensor} data received from the Device",
"metaData": [ "metaData": [
{"name":"owner","type":"STRING"}, {"name":"owner","type":"STRING"},
{"name":"deviceType","type":"STRING"}, {"name":"deviceType","type":"STRING"},

@ -18,7 +18,7 @@
--> -->
<Analytics> <Analytics>
<Name>IoTServer_Sensor_Script</Name> <Name>IoTServer_${nameOfTheSensor}_Script</Name>
<Script> <Script>
CREATE TEMPORARY TABLE Device${nameOfTheSensor}Data USING CarbonAnalytics OPTIONS(tableName "ORG_WSO2_IOT_DEVICES_${nameOfTheSensor}"); CREATE TEMPORARY TABLE Device${nameOfTheSensor}Data USING CarbonAnalytics OPTIONS(tableName "ORG_WSO2_IOT_DEVICES_${nameOfTheSensor}");
CREATE TEMPORARY TABLE Device${nameOfTheSensor}SummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_${nameOfTheSensor}_SUMMARY", schema "${nameOfTheSensor} FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time"); CREATE TEMPORARY TABLE Device${nameOfTheSensor}SummaryData USING CarbonAnalytics OPTIONS (tableName "DEVICE_${nameOfTheSensor}_SUMMARY", schema "${nameOfTheSensor} FLOAT, deviceType STRING -i, deviceId STRING -i, owner STRING -i, time LONG -i",primaryKeys "deviceType, deviceId, owner, time");

@ -1,4 +1,3 @@
package ${groupId}.${rootArtifactId}.controller.api;
/* /*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* *
@ -16,7 +15,9 @@ package ${groupId}.${rootArtifactId}.controller.api;
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
import java.util.Calendar;
package ${groupId}.${rootArtifactId}.controller.api;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -31,15 +32,23 @@ import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.device.DeviceType; import org.wso2.carbon.apimgt.annotations.device.DeviceType;
import org.wso2.carbon.apimgt.annotations.device.feature.Feature; import org.wso2.carbon.apimgt.annotations.device.feature.Feature;
import org.wso2.carbon.device.mgt.iot.DeviceManagement; import org.wso2.carbon.device.mgt.iot.DeviceManagement;
import org.wso2.carbon.device.mgt.iot.DeviceValidator;
import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; 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.sensormgt.SensorDataManager;
import org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord; import org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
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.context.CarbonContext;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.*; import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
@ -47,12 +56,14 @@ import javax.ws.rs.core.Response;
/** /**
* This is the controller API which is used to control agent side functionality * This is the controller API which is used to control agent side functionality
*/ */
@SuppressWarnings("NonJaxWsWebServices")
@API(name = "${deviceType}", version = "1.0.0", context = "/${deviceType}") @API(name = "${deviceType}", version = "1.0.0", context = "/${deviceType}")
@DeviceType(value = "${deviceType}") @DeviceType(value = "${deviceType}")
public class ControllerService { public class ControllerService {
private static Log log = LogFactory.getLog(ControllerService.class);
private MQTTConnector mqttConnector; private MQTTConnector mqttConnector;
private ConcurrentHashMap<String, DeviceJSON> deviceToIpMap = new ConcurrentHashMap<>(); private ConcurrentHashMap<String, DeviceJSON> deviceToIpMap = new ConcurrentHashMap<>();
private static Log log = LogFactory.getLog(ControllerService.class);
private boolean waitForServerStartup() { private boolean waitForServerStartup() {
while (!DeviceManagement.isServerReady()) { while (!DeviceManagement.isServerReady()) {
@ -100,10 +111,9 @@ public class ControllerService {
String deviceId = agentInfo.deviceId; String deviceId = agentInfo.deviceId;
if ((agentInfo.deviceId != null) && (agentInfo.owner != null)) { if ((agentInfo.deviceId != null) && (agentInfo.owner != null)) {
deviceToIpMap.put(deviceId, agentInfo); deviceToIpMap.put(deviceId, agentInfo);
return Response.status(Response.Status.OK).entity("Device has been registered successfully").build(); return Response.status(Response.Status.OK).build();
} }
return Response.status(Response.Status.NOT_ACCEPTABLE).entity("Message body not " + return Response.status(Response.Status.NOT_ACCEPTABLE).build();
"well-formed and still invalid").build();
} }
/** /**
@ -117,20 +127,22 @@ public class ControllerService {
@GET @GET
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Feature(code = "read-current-status", name = "Sensor", type = "monitor", @Feature(code = "read-current-status", name = "${nameOfTheSensor}", type = "monitor",
description = "Request current status of sensor from device") description = "Request current status of sensor from device")
public SensorRecord readCurrentStatus(@HeaderParam("owner") String owner, public SensorRecord readCurrentStatus(@HeaderParam("owner") String owner,
@HeaderParam("deviceId") String deviceId, @HeaderParam("deviceId") String deviceId,
@HeaderParam("protocol") String protocol, @HeaderParam("protocol") String protocol,
@Context HttpServletResponse response) { @Context HttpServletResponse response) {
SensorRecord sensorRecord = null; SensorRecord sensorRecord = null;
if(isPermitted(owner, deviceId, response)){
try { try {
sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId, sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId,
DeviceTypeConstants.SENSOR_READING); DeviceTypeConstants.SENSOR_READING);
response.setStatus(Response.Status.OK.getStatusCode());
} catch (DeviceControllerException e) { } catch (DeviceControllerException e) {
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
} }
response.setStatus(Response.Status.OK.getStatusCode()); }
return sensorRecord; return sensorRecord;
} }
@ -142,11 +154,17 @@ public class ControllerService {
@POST @POST
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public void pushData(final DeviceJSON agentInfo, @Context HttpServletResponse response) { public void pushData(final DeviceJSON agentInfo, @Context HttpServletResponse response) {
if(isPermitted(agentInfo.owner, agentInfo.deviceId, response)){
if (!ServiceUtils.publishToDASSensorValue(agentInfo.owner, agentInfo.deviceId, agentInfo.sensorValue)) { if (!ServiceUtils.publishToDASSensorValue(agentInfo.owner, agentInfo.deviceId, agentInfo.sensorValue)) {
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
log.warn("An error occurred whilst trying to publish pin data of go Data with ID [" + agentInfo.deviceId + log.warn("An error occurred whilst trying to publish pin data of go Data with ID [" +
"] of owner [" + agentInfo.owner + "]"); agentInfo.deviceId + "] of owner [" + agentInfo.owner + "]");
return;
} }
response.setStatus(Response.Status.OK.getStatusCode());
return;
}
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
} }
/** /**
@ -160,18 +178,48 @@ public class ControllerService {
@POST @POST
@Feature(code = "change-status", name = "Change status of sensor: on/off", type = "operation", @Feature(code = "change-status", name = "Change status of sensor: on/off", type = "operation",
description = "Change status of sensor: on/off") description = "Change status of sensor: on/off")
public void changeLockerState(@HeaderParam("owner") String owner, @HeaderParam("deviceId") String deviceId, public void changeStatus(@HeaderParam("owner") String owner, @HeaderParam("deviceId") String deviceId,
@HeaderParam("protocol") String protocol, @FormParam("state") String state, @HeaderParam("protocol") String protocol, @FormParam("state") String state,
@Context HttpServletResponse response) { @Context HttpServletResponse response) {
if(isPermitted(owner, deviceId, response)){
try { try {
mqttConnector.sendCommandViaMQTT(owner, deviceId, "Sensor:", state.toUpperCase()); mqttConnector.sendCommandViaMQTT(owner, deviceId, "Sensor:", state.toUpperCase());
response.setStatus(Response.Status.OK.getStatusCode()); response.setStatus(Response.Status.OK.getStatusCode());
return;
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
log.error(e); log.error(e);
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
return;
} catch (DeviceTypeException e) { } catch (DeviceTypeException e) {
log.error(e); log.error(e);
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
return;
}
}
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
}
/**
* Check whether user is permitted for given operation
*
* @param owner device owner
* @param deviceId unique identifier for given device type
* @param response if this true the user is allowed to related operation
* @return
*/
private boolean isPermitted(String owner, String deviceId, HttpServletResponse response) {
DeviceValidator deviceValidator = new DeviceValidator();
try {
String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
if (!deviceValidator.isExist(owner, tenantDomain, new DeviceIdentifier(
deviceId, DeviceTypeConstants.DEVICE_TYPE))) {
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
} else {
return true;
}
} catch (DeviceManagementException e) {
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
} }
return false;
} }
} }

@ -1,4 +1,3 @@
package ${groupId}.${rootArtifactId}.controller.api.dto;
/* /*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* *
@ -16,6 +15,8 @@ package ${groupId}.${rootArtifactId}.controller.api.dto;
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package ${groupId}.${rootArtifactId}.controller.api.dto;
import org.codehaus.jackson.annotate.JsonIgnoreProperties; import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;

@ -1,4 +1,3 @@
package ${groupId}.${rootArtifactId}.controller.api.exception;
/* /*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* *
@ -17,6 +16,8 @@ package ${groupId}.${rootArtifactId}.controller.api.exception;
* under the License. * under the License.
*/ */
package ${groupId}.${rootArtifactId}.controller.api.exception;
public class DeviceTypeException extends Exception { public class DeviceTypeException extends Exception {
private static final long serialVersionUID = 2736466230451105441L; private static final long serialVersionUID = 2736466230451105441L;

@ -1,5 +1,3 @@
package ${groupId}.${rootArtifactId}.controller.api.transport;
/* /*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* *
@ -18,6 +16,8 @@ package ${groupId}.${rootArtifactId}.controller.api.transport;
* under the License. * under the License.
*/ */
package ${groupId}.${rootArtifactId}.controller.api.transport;
import ${groupId}.${rootArtifactId}.controller.api.exception.DeviceTypeException; import ${groupId}.${rootArtifactId}.controller.api.exception.DeviceTypeException;
import ${groupId}.${rootArtifactId}.plugin.constants.DeviceTypeConstants; import ${groupId}.${rootArtifactId}.plugin.constants.DeviceTypeConstants;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -110,11 +110,11 @@ public class MQTTConnector extends MQTTTransportHandler {
log.debug("Received MQTT message for: [OWNER-" + owner + "] & [DEVICE.ID-" + deviceId + "]"); log.debug("Received MQTT message for: [OWNER-" + owner + "] & [DEVICE.ID-" + deviceId + "]");
} }
if (messageData.length == 2) { if (messageData.length == 2) {
String lockerCurrentState = messageData[1]; String currentState = messageData[1];
SensorDataManager.getInstance().setSensorRecord(deviceId, DeviceTypeConstants.SENSOR_READING, SensorDataManager.getInstance().setSensorRecord(deviceId, DeviceTypeConstants.SENSOR_READING,
lockerCurrentState, Calendar.getInstance().getTimeInMillis()); currentState, Calendar.getInstance().getTimeInMillis());
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Current value of the sensor: " + lockerCurrentState); log.debug("Current value of the sensor: " + currentState);
} }
} }
} }

@ -1,3 +1,4 @@
<?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.
* *
@ -24,10 +25,10 @@
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>${artifactId}</artifactId> <artifactId>${project-base-package}.manager</artifactId>
<packaging>war</packaging> <packaging>war</packaging>
<version>${version}</version> <version>${version}</version>
<name>${artifactId} </name> <name>${project-base-package}.manager</name>
<url>http://wso2.org</url> <url>http://wso2.org</url>
<build> <build>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory> <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
@ -38,8 +39,8 @@
<version>${maven-compiler-plugin.version}</version> <version>${maven-compiler-plugin.version}</version>
<configuration> <configuration>
<encoding>UTF-8</encoding> <encoding>UTF-8</encoding>
<source>${wso2.maven.compiler.source}</source> <source>${maven.compiler.source}</source>
<target>${wso2.maven.compiler.target}</target> <target>${maven.compiler.target}</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>

@ -1,4 +1,3 @@
package ${groupId}.${rootArtifactId}.plugin.constants;
/* /*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* *
@ -16,10 +15,15 @@ package ${groupId}.${rootArtifactId}.plugin.constants;
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package ${groupId}.${rootArtifactId}.plugin.constants;
public class DeviceTypeConstants { public class DeviceTypeConstants {
public final static String DEVICE_TYPE = "${deviceType}"; public final static String DEVICE_TYPE = "${deviceType}";
public final static String DEVICE_PLUGIN_DEVICE_NAME = "DEVICE_NAME"; public final static String DEVICE_PLUGIN_DEVICE_NAME = "DEVICE_NAME";
public final static String DEVICE_PLUGIN_DEVICE_ID = "${deviceType}_DEVICE_ID"; public final static String DEVICE_PLUGIN_DEVICE_ID = "${deviceType}_DEVICE_ID";
public final static String SENSOR_READING = "sensorValue"; public final static String SENSOR_READING = "sensorValue";
public static final String DATA_SOURCE_NAME = "jdbc/${deviceType}DM_DB"; public static final String DATA_SOURCE_NAME = "jdbc/${deviceType}DM_DB";
public final static String DEVICE_PLUGIN_PROPERTY_ACCESS_TOKEN = "accessToken";
public final static String DEVICE_PLUGIN_PROPERTY_REFRESH_TOKEN = "refreshToken";
} }

@ -1,3 +1,4 @@
<?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.
* *
@ -235,7 +236,7 @@
<version>${commons-json.version}</version> <version>${commons-json.version}</version>
<scope>system</scope> <scope>system</scope>
<systemPath> <systemPath>
${basedir}/../../../../repository/components/plugins/json_2.0.0.wso2v1.jar ${basedir}/../../../../repository/components/plugins/json_${commons-json.version}.jar
</systemPath> </systemPath>
</dependency> </dependency>
<dependency> <dependency>

@ -26,8 +26,8 @@
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>${artifactId}</artifactId> <artifactId>${project-base-package}.ui</artifactId>
<name>${artifactId}</name> <name>${project-base-package}.ui</name>
<packaging>pom</packaging> <packaging>pom</packaging>
<build> <build>
<plugins> <plugins>

@ -25,9 +25,9 @@
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<version>${version}</version> <version>${version}</version>
<artifactId>${artifactId}</artifactId> <artifactId>${project-base-package}.feature</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>
<name> ${project.artifactId} </name> <name>${project-base-package}.feature </name>
<url>http://wso2.org</url> <url>http://wso2.org</url>
<dependencies> <dependencies>
<dependency> <dependency>
@ -131,7 +131,6 @@
<type>war</type> <type>war</type>
<overWrite>true</overWrite> <overWrite>true</overWrite>
<outputDirectory> <outputDirectory>
<!--${basedir}/src/main/resources/webapps/-->
${project.build.directory}/maven-shared-archive-resources/webapps/ ${project.build.directory}/maven-shared-archive-resources/webapps/
</outputDirectory> </outputDirectory>
<destFileName>${deviceType}_mgt.war</destFileName> <destFileName>${deviceType}_mgt.war</destFileName>
@ -153,7 +152,6 @@
<type>war</type> <type>war</type>
<overWrite>true</overWrite> <overWrite>true</overWrite>
<outputDirectory> <outputDirectory>
<!--${basedir}/src/main/resources/webapps/-->
${project.build.directory}/maven-shared-archive-resources/webapps/ ${project.build.directory}/maven-shared-archive-resources/webapps/
</outputDirectory> </outputDirectory>
<destFileName>${deviceType}.war</destFileName> <destFileName>${deviceType}.war</destFileName>
@ -199,6 +197,7 @@
<plugin> <plugin>
<groupId>org.wso2.maven</groupId> <groupId>org.wso2.maven</groupId>
<artifactId>carbon-p2-plugin</artifactId> <artifactId>carbon-p2-plugin</artifactId>
<version>${carbon-p2-plugin.version}</version>
<executions> <executions>
<execution> <execution>
<id>p2-feature-generation</id> <id>p2-feature-generation</id>

@ -70,7 +70,8 @@ if sys.version_info<(2,6,0):
parser = argparse.ArgumentParser(description="Python service to push RPi info to the Device Cloud") parser = argparse.ArgumentParser(description="Python service to push RPi info to the Device Cloud")
parser.add_argument("-l", "--log", help="file to write log to (default '" + LOG_FILENAME + "')") parser.add_argument("-l", "--log", help="file to write log to (default '" + LOG_FILENAME + "')")
help_string_for_data_push_interval = "time interval between successive locker status push to server(default '" + str(PUSH_INTERVAL) + "')" help_string_for_data_push_interval = "time interval between successive locker status push to server(default '" + \
str(PUSH_INTERVAL) + "')"
parser.add_argument("-i", "--interval", type=int, help=help_string_for_data_push_interval) parser.add_argument("-i", "--interval", type=int, help=help_string_for_data_push_interval)
args = parser.parse_args() args = parser.parse_args()
@ -137,7 +138,8 @@ def registerAgent():
if sys.version_info<(2,7,9): if sys.version_info<(2,7,9):
dcConncection = httplib.HTTPSConnection(host=SERVER_IP, port=SERVER_PORT) dcConncection = httplib.HTTPSConnection(host=SERVER_IP, port=SERVER_PORT)
else: else:
dcConncection = httplib.HTTPSConnection(host=SERVER_IP, port=SERVER_PORT, context=ssl._create_unverified_context()) dcConncection = httplib.HTTPSConnection(host=SERVER_IP, port=SERVER_PORT
, context=ssl._create_unverified_context())
#TODO need to get server certificate when initializing https connection #TODO need to get server certificate when initializing https connection
dcConncection.set_debuglevel(1) dcConncection.set_debuglevel(1)
dcConncection.connect() dcConncection.connect()
@ -205,7 +207,8 @@ def pushSensorValue():
if sys.version_info<(2,7,9): if sys.version_info<(2,7,9):
dcConncection = httplib.HTTPSConnection(host=SERVER_IP, port=SERVER_PORT) dcConncection = httplib.HTTPSConnection(host=SERVER_IP, port=SERVER_PORT)
else: else:
dcConncection = httplib.HTTPSConnection(host=SERVER_IP, port=SERVER_PORT, context=ssl._create_unverified_context()) dcConncection = httplib.HTTPSConnection(host=SERVER_IP, port=SERVER_PORT
, context=ssl._create_unverified_context())
#TODO need to get server certificate when initializing https connection #TODO need to get server certificate when initializing https connection
dcConncection.set_debuglevel(1) dcConncection.set_debuglevel(1)
dcConncection.connect() dcConncection.connect()

@ -1,31 +0,0 @@
#
# Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
#
# Licensed 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.
#
#
[Device-Configurations]
owner=${DEVICE_OWNER}
deviceId=${DEVICE_ID}
device-name=${DEVICE_NAME}
controller-context=/${deviceType}/controller
device-type=${deviceType}
mqtt-ep=${MQTT_EP}
https-ep=${HTTPS_EP}
auth-method=token
auth-token=${DEVICE_TOKEN}
refresh-token=${DEVICE_REFRESH_TOKEN}
push-interval=15

@ -1,3 +1,4 @@
<?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.
~ ~

@ -1,3 +1,4 @@
<?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.
~ ~

@ -1,3 +1,4 @@
<?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.
~ ~
@ -234,24 +235,24 @@
<carbon.kernel.version>4.4.3</carbon.kernel.version> <carbon.kernel.version>4.4.3</carbon.kernel.version>
<carbon.device.mgt.version>1.1.0-SNAPSHOT</carbon.device.mgt.version> <carbon.device.mgt.version>1.1.0-SNAPSHOT</carbon.device.mgt.version>
<carbon.device.mgt.jar.version>1.1.0.SNAPSHOT</carbon.device.mgt.jar.version> <carbon.device.mgt.jar.version>1.1.0.SNAPSHOT</carbon.device.mgt.jar.version>
<carbon-p2-plugin.version>1.5.3</carbon-p2-plugin.version>
<carbon.iot.device.mgt.version>2.0.4-SNAPSHOT</carbon.iot.device.mgt.version>
<carbon.iot.device.mgt.jar.version>2.0.4.SNAPSHOT</carbon.iot.device.mgt.jar.version>
<paho.mqtt.version>1.0.2</paho.mqtt.version> <paho.mqtt.version>1.0.2</paho.mqtt.version>
<commons-json.version>3.0.0.wso2v1</commons-json.version> <commons-json.version>3.0.0.wso2v1</commons-json.version>
<commons-httpclient.orbit.version>3.1.0.wso2v2</commons-httpclient.orbit.version>
<commons-io.version>2.4</commons-io.version>
<eclipse.osgi.version>3.8.1.v20120830-144521</eclipse.osgi.version> <eclipse.osgi.version>3.8.1.v20120830-144521</eclipse.osgi.version>
<carbon.iot.device.mgt.version>1.9.2-SNAPSHOT</carbon.iot.device.mgt.version>
<carbon.iot.device.mgt.jar.version>1.9.2.SNAPSHOT</carbon.iot.device.mgt.jar.version>
<javax.ws.rs.version>1.1.1</javax.ws.rs.version> <javax.ws.rs.version>1.1.1</javax.ws.rs.version>
<commons-io.version>2.4</commons-io.version>
<!--XMPP/MQTT Version-->
<smack.wso2.version>3.0.4.wso2v1</smack.wso2.version> <smack.wso2.version>3.0.4.wso2v1</smack.wso2.version>
<smackx.wso2.version>3.0.4.wso2v1</smackx.wso2.version> <smackx.wso2.version>3.0.4.wso2v1</smackx.wso2.version>
<cxf.version>2.6.1</cxf.version> <cxf.version>2.6.1</cxf.version>
<jackson.version>1.9.0</jackson.version> <jackson.version>1.9.0</jackson.version>
<commons-httpclient.orbit.version>3.1.0.wso2v2</commons-httpclient.orbit.version>
<eclipse.equinox.common.version>3.6.100.v20120522-1841</eclipse.equinox.common.version> <eclipse.equinox.common.version>3.6.100.v20120522-1841</eclipse.equinox.common.version>
<wso2.maven.compiler.source>1.7</wso2.maven.compiler.source> <project-base-package>${project.groupId}.${rootArtifactId}</project-base-package>
<wso2.maven.compiler.target>1.7</wso2.maven.compiler.target>
<project-base-package>${groupId}.${rootArtifactId}</project-base-package>
<junit.version>3.8.1</junit.version> <junit.version>3.8.1</junit.version>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<org.apache.felix.version>1.4.0</org.apache.felix.version> <org.apache.felix.version>1.4.0</org.apache.felix.version>
<maven-clean-plugin.version>2.4.1</maven-clean-plugin.version> <maven-clean-plugin.version>2.4.1</maven-clean-plugin.version>
<maven-compiler-plugin.version>2.3.2</maven-compiler-plugin.version> <maven-compiler-plugin.version>2.3.2</maven-compiler-plugin.version>

Loading…
Cancel
Save