diff --git a/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.plugin.impl/pom.xml b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.plugin.impl/pom.xml
new file mode 100644
index 0000000000..15b74b2dd2
--- /dev/null
+++ b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.plugin.impl/pom.xml
@@ -0,0 +1,127 @@
+
+
+
+
+
+
+ device-mgt-iot-arduino
+ org.wso2.carbon.devicemgt-plugins
+ 1.9.2-SNAPSHOT
+ ../pom.xml
+
+
+ 4.0.0
+ org.wso2.carbon.device.mgt.iot.arduino.plugin.impl
+ 1.9.2-SNAPSHOT
+ bundle
+ WSO2 Carbon - IoT Server Arduino Management Plugin
+ WSO2 Carbon - Arduino Management/Control Plugin Implementation
+ http://wso2.org
+
+
+
+
+ org.apache.felix
+ maven-scr-plugin
+
+
+ maven-compiler-plugin
+
+
+ 1.7
+
+ 2.3.2
+
+
+ org.apache.felix
+ maven-bundle-plugin
+ 1.4.0
+ true
+
+
+ ${project.artifactId}
+ ${project.artifactId}
+ ${carbon.iot.device.mgt.version}
+ IoT Server Arduino Impl Bundle
+ org.wso2.carbon.device.mgt.iot.arduino.plugin.internal
+
+ org.osgi.framework,
+ org.osgi.service.component,
+ org.apache.commons.logging,
+ javax.xml.bind.*,
+ javax.naming,
+ javax.sql,
+ javax.xml.bind.annotation.*,
+ javax.xml.parsers,
+ javax.net,
+ javax.net.ssl,
+ org.w3c.dom,
+ org.wso2.carbon.device.mgt.common.*,
+ org.wso2.carbon.device.mgt.common,
+ org.wso2.carbon.context.*,
+ org.wso2.carbon.ndatasource.core,
+ org.wso2.carbon.device.mgt.iot.*,
+
+
+
+ !org.wso2.carbon.device.mgt.iot.arduino.plugin.internal,
+ org.wso2.carbon.device.mgt.iot.arduino.plugin.*
+
+
+
+
+
+
+
+
+
+ org.eclipse.osgi
+ org.eclipse.osgi
+
+
+ org.eclipse.osgi
+ org.eclipse.osgi.services
+
+
+
+ org.wso2.carbon
+ org.wso2.carbon.logging
+
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.common
+
+
+ org.wso2.carbon
+ org.wso2.carbon.ndatasource.core
+
+
+
+ org.wso2.carbon.devicemgt-plugins
+ org.wso2.carbon.device.mgt.iot
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/constants/ArduinoConstants.java b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/constants/ArduinoConstants.java
new file mode 100644
index 0000000000..c6fb9ca016
--- /dev/null
+++ b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/constants/ArduinoConstants.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2015, 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.
+ */
+
+package org.wso2.carbon.device.mgt.iot.arduino.plugin.constants;
+
+public class ArduinoConstants {
+
+ public final static String DEVICE_TYPE = "arduino";
+ public final static String DEVICE_PLUGIN_DEVICE_NAME = "DEVICE_NAME";
+ public final static String DEVICE_PLUGIN_DEVICE_ID = "ARDUINO_DEVICE_ID";
+ public final static String STATE_ON = "ON";
+ public final static String STATE_OFF = "OFF";
+}
diff --git a/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/ArduinoManager.java b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/ArduinoManager.java
new file mode 100644
index 0000000000..47db24223e
--- /dev/null
+++ b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/ArduinoManager.java
@@ -0,0 +1,281 @@
+/*
+ * Copyright (c) 2015, 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.
+ */
+
+package org.wso2.carbon.device.mgt.iot.arduino.plugin.impl;
+
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.device.mgt.common.Device;
+import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
+import org.wso2.carbon.device.mgt.common.DeviceManagementException;
+import org.wso2.carbon.device.mgt.common.DeviceManager;
+import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
+import org.wso2.carbon.device.mgt.common.FeatureManager;
+import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
+import org.wso2.carbon.device.mgt.common.license.mgt.License;
+import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
+import org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.dao.ArduinoDAO;
+import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOException;
+import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOFactory;
+import org.wso2.carbon.device.mgt.iot.util.iotdevice.dto.IotDevice;
+import org.wso2.carbon.device.mgt.iot.util.iotdevice.util.IotDeviceManagementUtil;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * This represents the Arduino implementation of DeviceManagerService.
+ */
+public class ArduinoManager implements DeviceManager {
+
+ private static final IotDeviceManagementDAOFactory iotDeviceManagementDAOFactory = new ArduinoDAO();
+ private static final Log log = LogFactory.getLog(ArduinoManager.class);
+
+
+ @Override
+ public FeatureManager getFeatureManager() {
+ return null;
+ }
+
+ @Override
+ public boolean saveConfiguration(TenantConfiguration tenantConfiguration)
+ throws DeviceManagementException {
+ //TODO implement this
+ return false;
+ }
+
+ @Override
+ public TenantConfiguration getConfiguration() throws DeviceManagementException {
+ //TODO implement this
+ return null;
+ }
+
+ @Override
+ public boolean enrollDevice(Device device) throws DeviceManagementException {
+ boolean status;
+ IotDevice iotDevice = IotDeviceManagementUtil.convertToIotDevice(device);
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("Enrolling a new Arduino device : " + device.getDeviceIdentifier());
+ }
+ ArduinoDAO.beginTransaction();
+ status = iotDeviceManagementDAOFactory.getIotDeviceDAO().addIotDevice(
+ iotDevice);
+ ArduinoDAO.commitTransaction();
+ } catch (IotDeviceManagementDAOException e) {
+ try {
+ ArduinoDAO.rollbackTransaction();
+ } catch (IotDeviceManagementDAOException iotDAOEx) {
+ String msg = "Error occurred while roll back the device enrol transaction :" + device.toString();
+ log.warn(msg, iotDAOEx);
+ }
+ String msg = "Error while enrolling the Arduino device : " + device.getDeviceIdentifier();
+ log.error(msg, e);
+ throw new DeviceManagementException(msg, e);
+ }
+ return status;
+ }
+
+ @Override
+ public boolean modifyEnrollment(Device device) throws DeviceManagementException {
+ boolean status;
+ IotDevice iotDevice = IotDeviceManagementUtil.convertToIotDevice(device);
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("Modifying the Arduino device enrollment data");
+ }
+ ArduinoDAO.beginTransaction();
+ status = iotDeviceManagementDAOFactory.getIotDeviceDAO()
+ .updateIotDevice(iotDevice);
+ ArduinoDAO.commitTransaction();
+ } catch (IotDeviceManagementDAOException e) {
+ try {
+ ArduinoDAO.rollbackTransaction();
+ } catch (IotDeviceManagementDAOException iotDAOEx) {
+ String msg = "Error occurred while roll back the update device transaction :" + device.toString();
+ log.warn(msg, iotDAOEx);
+ }
+ String msg = "Error while updating the enrollment of the Arduino device : " +
+ device.getDeviceIdentifier();
+ log.error(msg, e);
+ throw new DeviceManagementException(msg, e);
+ }
+ return status;
+ }
+
+ @Override
+ public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
+ boolean status;
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("Dis-enrolling Arduino device : " + deviceId);
+ }
+ ArduinoDAO.beginTransaction();
+ status = iotDeviceManagementDAOFactory.getIotDeviceDAO()
+ .deleteIotDevice(deviceId.getId());
+ ArduinoDAO.commitTransaction();
+ } catch (IotDeviceManagementDAOException e) {
+ try {
+ ArduinoDAO.rollbackTransaction();
+ } catch (IotDeviceManagementDAOException iotDAOEx) {
+ String msg = "Error occurred while roll back the device dis enrol transaction :" + deviceId.toString();
+ log.warn(msg, iotDAOEx);
+ }
+ String msg = "Error while removing the Arduino device : " + deviceId.getId();
+ log.error(msg, e);
+ throw new DeviceManagementException(msg, e);
+ }
+ return status;
+ }
+
+ @Override
+ public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
+ boolean isEnrolled = false;
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("Checking the enrollment of Arduino device : " + deviceId.getId());
+ }
+ IotDevice iotDevice =
+ iotDeviceManagementDAOFactory.getIotDeviceDAO().getIotDevice(
+ deviceId.getId());
+ if (iotDevice != null) {
+ isEnrolled = true;
+ }
+ } catch (IotDeviceManagementDAOException e) {
+ String msg = "Error while checking the enrollment status of Arduino device : " +
+ deviceId.getId();
+ log.error(msg, e);
+ throw new DeviceManagementException(msg, e);
+ }
+ return isEnrolled;
+ }
+
+ @Override
+ public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
+ return true;
+ }
+
+ @Override
+ public boolean setActive(DeviceIdentifier deviceId, boolean status)
+ throws DeviceManagementException {
+ return true;
+ }
+
+ @Override
+ public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
+ Device device;
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("Getting the details of Arduino device : " + deviceId.getId());
+ }
+ IotDevice iotDevice = iotDeviceManagementDAOFactory.getIotDeviceDAO().
+ getIotDevice(deviceId.getId());
+ device = IotDeviceManagementUtil.convertToDevice(iotDevice);
+ } catch (IotDeviceManagementDAOException e) {
+ String msg = "Error while fetching the Arduino device : " + deviceId.getId();
+ log.error(msg, e);
+ throw new DeviceManagementException(msg, e);
+ }
+ return device;
+ }
+
+ @Override
+ public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
+ throws DeviceManagementException {
+ return true;
+ }
+
+ public boolean isClaimable(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
+ return false;
+ }
+
+ @Override
+ public boolean setStatus(DeviceIdentifier deviceId, String currentOwner,
+ EnrolmentInfo.Status status) throws DeviceManagementException {
+ return false;
+ }
+
+ @Override
+ public License getLicense(String s) throws LicenseManagementException {
+ return null;
+ }
+
+ @Override
+ public void addLicense(License license) throws LicenseManagementException {
+
+ }
+
+ @Override
+ public boolean requireDeviceAuthorization() {
+ return false;
+ }
+
+ @Override
+ public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException {
+ boolean status;
+ IotDevice iotDevice = IotDeviceManagementUtil.convertToIotDevice(device);
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug(
+ "updating the details of Arduino device : " + deviceIdentifier);
+ }
+ ArduinoDAO.beginTransaction();
+ status = iotDeviceManagementDAOFactory.getIotDeviceDAO()
+ .updateIotDevice(iotDevice);
+ ArduinoDAO.commitTransaction();
+ } catch (IotDeviceManagementDAOException e) {
+ try {
+ ArduinoDAO.rollbackTransaction();
+ } catch (IotDeviceManagementDAOException iotDAOEx) {
+ String msg = "Error occurred while roll back the update device info transaction :" + device.toString();
+ log.warn(msg, iotDAOEx);
+ }
+ String msg =
+ "Error while updating the Arduino device : " + deviceIdentifier;
+ log.error(msg, e);
+ throw new DeviceManagementException(msg, e);
+ }
+ return status;
+ }
+
+ @Override
+ public List getAllDevices() throws DeviceManagementException {
+ List devices = null;
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("Fetching the details of all Arduino devices");
+ }
+ List iotDevices =
+ iotDeviceManagementDAOFactory.getIotDeviceDAO().getAllIotDevices();
+ if (iotDevices != null) {
+ devices = new ArrayList();
+ for (IotDevice iotDevice : iotDevices) {
+ devices.add(IotDeviceManagementUtil.convertToDevice(iotDevice));
+ }
+ }
+ } catch (IotDeviceManagementDAOException e) {
+ String msg = "Error while fetching all Arduino devices.";
+ log.error(msg, e);
+ throw new DeviceManagementException(msg, e);
+ }
+ return devices;
+ }
+
+}
\ No newline at end of file
diff --git a/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/ArduinoManagerService.java b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/ArduinoManagerService.java
new file mode 100644
index 0000000000..371eddf87e
--- /dev/null
+++ b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/ArduinoManagerService.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2015, 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.
+ */
+
+package org.wso2.carbon.device.mgt.iot.arduino.plugin.impl;
+
+import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
+import org.wso2.carbon.device.mgt.common.DeviceManagementException;
+import org.wso2.carbon.device.mgt.common.DeviceManager;
+import org.wso2.carbon.device.mgt.common.app.mgt.Application;
+import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
+import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
+import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
+import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
+import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants;
+
+import java.util.List;
+
+public class ArduinoManagerService implements DeviceManagementService {
+ private DeviceManager deviceManager;
+
+ @Override
+ public String getType() {
+ return ArduinoConstants.DEVICE_TYPE;
+ }
+
+ @Override
+ public String getProviderTenantDomain() {
+ return "carbon.super";
+ }
+
+ @Override
+ public boolean isSharedWithAllTenants() {
+ return true;
+ }
+
+ @Override
+ public String[] getSharedTenantsDomain() {
+ return new String[0];
+ }
+
+ @Override
+ public void init() throws DeviceManagementException {
+ deviceManager=new ArduinoManager();
+
+ }
+
+ @Override
+ public DeviceManager getDeviceManager() {
+ return deviceManager;
+ }
+
+ @Override
+ public ApplicationManager getApplicationManager() {
+ return null;
+ }
+
+ @Override
+ public void notifyOperationToDevices(Operation operation, List deviceIds)
+ throws DeviceManagementException {
+
+ }
+
+ @Override
+ public Application[] getApplications(String domain, int pageNumber, int size)
+ throws ApplicationManagementException {
+ return new Application[0];
+ }
+
+ @Override
+ public void updateApplicationStatus(DeviceIdentifier deviceId, Application application,
+ String status) throws ApplicationManagementException {
+
+ }
+
+ @Override
+ public String getApplicationStatus(DeviceIdentifier deviceId, Application application)
+ throws ApplicationManagementException {
+ return null;
+ }
+
+ @Override
+ public void installApplicationForDevices(Operation operation, List deviceIdentifiers)
+ throws ApplicationManagementException {
+
+ }
+
+ @Override
+ public void installApplicationForUsers(Operation operation, List userNameList)
+ throws ApplicationManagementException {
+
+ }
+
+ @Override
+ public void installApplicationForUserRoles(Operation operation, List userRoleList)
+ throws ApplicationManagementException {
+
+ }
+}
diff --git a/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/dao/ArduinoDAO.java b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/dao/ArduinoDAO.java
new file mode 100644
index 0000000000..5c0ff4c836
--- /dev/null
+++ b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/dao/ArduinoDAO.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2015, 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.
+ */
+
+package org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.dao;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants;
+import org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.dao.impl.ArduinoDeviceDAOImpl;
+import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceDAO;
+import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOException;
+import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOFactory;
+import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOFactoryInterface;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+public class ArduinoDAO extends IotDeviceManagementDAOFactory implements IotDeviceManagementDAOFactoryInterface {
+
+ private static final Log log = LogFactory.getLog(ArduinoDAO.class);
+ static DataSource dataSource;
+ private static ThreadLocal currentConnection = new ThreadLocal();
+
+ public ArduinoDAO() {
+ initArduinoDAO();
+ }
+
+ public static void initArduinoDAO() {
+ dataSource = getDataSourceMap().get(ArduinoConstants.DEVICE_TYPE);
+ }
+
+ @Override public IotDeviceDAO getIotDeviceDAO() {
+ return new ArduinoDeviceDAOImpl();
+ }
+
+ public static void beginTransaction() throws IotDeviceManagementDAOException {
+ try {
+ Connection conn = dataSource.getConnection();
+ conn.setAutoCommit(false);
+ currentConnection.set(conn);
+ } catch (SQLException e) {
+ throw new IotDeviceManagementDAOException("Error occurred while retrieving datasource connection", e);
+ }
+ }
+
+ public static Connection getConnection() throws IotDeviceManagementDAOException {
+ if (currentConnection.get() == null) {
+ try {
+ currentConnection.set(dataSource.getConnection());
+ } catch (SQLException e) {
+ throw new IotDeviceManagementDAOException("Error occurred while retrieving data source connection", e);
+ }
+ }
+ return currentConnection.get();
+ }
+
+ public static void commitTransaction() throws IotDeviceManagementDAOException {
+ try {
+ Connection conn = currentConnection.get();
+ if (conn != null) {
+ conn.commit();
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("Datasource connection associated with the current thread is null, hence commit "
+ + "has not been attempted");
+ }
+ }
+ } catch (SQLException e) {
+ throw new IotDeviceManagementDAOException("Error occurred while committing the transaction", e);
+ } finally {
+ closeConnection();
+ }
+ }
+
+ public static void closeConnection() throws IotDeviceManagementDAOException {
+
+ Connection con = currentConnection.get();
+ if (con != null) {
+ try {
+ con.close();
+ } catch (SQLException e) {
+ log.error("Error occurred while close the connection");
+ }
+ }
+ currentConnection.remove();
+ }
+
+ public static void rollbackTransaction() throws IotDeviceManagementDAOException {
+ try {
+ Connection conn = currentConnection.get();
+ if (conn != null) {
+ conn.rollback();
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("Datasource connection associated with the current thread is null, hence rollback "
+ + "has not been attempted");
+ }
+ }
+ } catch (SQLException e) {
+ throw new IotDeviceManagementDAOException("Error occurred while rollback the transaction", e);
+ } finally {
+ closeConnection();
+ }
+ }
+}
\ No newline at end of file
diff --git a/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/dao/impl/ArduinoDeviceDAOImpl.java b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/dao/impl/ArduinoDeviceDAOImpl.java
new file mode 100644
index 0000000000..1379238e69
--- /dev/null
+++ b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/dao/impl/ArduinoDeviceDAOImpl.java
@@ -0,0 +1,238 @@
+/*
+ * Copyright (c) 2015, 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.
+ */
+
+package org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.dao.impl;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceDAO;
+import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOException;
+import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.util.IotDeviceManagementDAOUtil;
+import org.wso2.carbon.device.mgt.iot.util.iotdevice.dto.IotDevice;
+import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants;
+import org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.dao.ArduinoDAO;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Implements IotDeviceDAO for arduino Devices.
+ */
+public class ArduinoDeviceDAOImpl implements IotDeviceDAO{
+
+
+ private static final Log log = LogFactory.getLog(ArduinoDeviceDAOImpl.class);
+
+ @Override
+ public IotDevice getIotDevice(String iotDeviceId)
+ throws IotDeviceManagementDAOException {
+ Connection conn = null;
+ PreparedStatement stmt = null;
+ IotDevice iotDevice = null;
+ ResultSet resultSet = null;
+ try {
+ conn = ArduinoDAO.getConnection();
+ String selectDBQuery =
+ "SELECT ARDUINO_DEVICE_ID, DEVICE_NAME" +
+ " FROM ARDUINO_DEVICE WHERE ARDUINO_DEVICE_ID = ?";
+ stmt = conn.prepareStatement(selectDBQuery);
+ stmt.setString(1, iotDeviceId);
+ resultSet = stmt.executeQuery();
+
+ if (resultSet.next()) {
+ iotDevice = new IotDevice();
+ iotDevice.setIotDeviceName(resultSet.getString(
+ ArduinoConstants.DEVICE_PLUGIN_DEVICE_NAME));
+ Map propertyMap = new HashMap();
+
+
+
+ iotDevice.setDeviceProperties(propertyMap);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Arduino device " + iotDeviceId + " data has been fetched from " +
+ "Arduino database.");
+ }
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while fetching Arduino device : '" + iotDeviceId + "'";
+ log.error(msg, e);
+ throw new IotDeviceManagementDAOException(msg, e);
+ } finally {
+ IotDeviceManagementDAOUtil.cleanupResources(stmt, resultSet);
+ ArduinoDAO.closeConnection();
+ }
+
+ return iotDevice;
+ }
+
+ @Override
+ public boolean addIotDevice(IotDevice iotDevice)
+ throws IotDeviceManagementDAOException {
+ boolean status = false;
+ Connection conn = null;
+ PreparedStatement stmt = null;
+ try {
+ conn = ArduinoDAO.getConnection();
+ String createDBQuery =
+ "INSERT INTO ARDUINO_DEVICE(ARDUINO_DEVICE_ID, DEVICE_NAME) VALUES (?, ?)";
+
+ stmt = conn.prepareStatement(createDBQuery);
+ stmt.setString(1, iotDevice.getIotDeviceId());
+ stmt.setString(2,iotDevice.getIotDeviceName());
+ if (iotDevice.getDeviceProperties() == null) {
+ iotDevice.setDeviceProperties(new HashMap());
+ }
+
+
+ int rows = stmt.executeUpdate();
+ if (rows > 0) {
+ status = true;
+ if (log.isDebugEnabled()) {
+ log.debug("Arduino device " + iotDevice.getIotDeviceId() + " data has been" +
+ " added to the Arduino database.");
+ }
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while adding the Arduino device '" +
+ iotDevice.getIotDeviceId() + "' to the Arduino db.";
+ log.error(msg, e);
+ throw new IotDeviceManagementDAOException(msg, e);
+ } finally {
+ IotDeviceManagementDAOUtil.cleanupResources(stmt, null);
+ }
+ return status;
+ }
+
+ @Override
+ public boolean updateIotDevice(IotDevice iotDevice)
+ throws IotDeviceManagementDAOException {
+ boolean status = false;
+ Connection conn = null;
+ PreparedStatement stmt = null;
+ try {
+ conn = ArduinoDAO.getConnection();
+ String updateDBQuery =
+ "UPDATE ARDUINO_DEVICE SET DEVICE_NAME = ? WHERE ARDUINO_DEVICE_ID = ?";
+
+ stmt = conn.prepareStatement(updateDBQuery);
+
+ if (iotDevice.getDeviceProperties() == null) {
+ iotDevice.setDeviceProperties(new HashMap());
+ }
+ stmt.setString(1, iotDevice.getIotDeviceName());
+
+ stmt.setString(2, iotDevice.getIotDeviceId());
+ int rows = stmt.executeUpdate();
+ if (rows > 0) {
+ status = true;
+ if (log.isDebugEnabled()) {
+ log.debug("Arduino device " + iotDevice.getIotDeviceId() + " data has been" +
+ " modified.");
+ }
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while modifying the Arduino device '" +
+ iotDevice.getIotDeviceId() + "' data.";
+ log.error(msg, e);
+ throw new IotDeviceManagementDAOException(msg, e);
+ } finally {
+ IotDeviceManagementDAOUtil.cleanupResources(stmt, null);
+ }
+ return status;
+ }
+
+ @Override
+ public boolean deleteIotDevice(String iotDeviceId)
+ throws IotDeviceManagementDAOException {
+ boolean status = false;
+ Connection conn = null;
+ PreparedStatement stmt = null;
+ try {
+ conn = ArduinoDAO.getConnection();
+ String deleteDBQuery =
+ "DELETE FROM ARDUINO_DEVICE WHERE ARDUINO_DEVICE_ID = ?";
+ stmt = conn.prepareStatement(deleteDBQuery);
+ stmt.setString(1, iotDeviceId);
+ int rows = stmt.executeUpdate();
+ if (rows > 0) {
+ status = true;
+ if (log.isDebugEnabled()) {
+ log.debug("Arduino device " + iotDeviceId + " data has deleted" +
+ " from the Arduino database.");
+ }
+ }
+ } catch (SQLException e) {
+ String msg = "Error occurred while deleting Arduino device " + iotDeviceId;
+ log.error(msg, e);
+ throw new IotDeviceManagementDAOException(msg, e);
+ } finally {
+ IotDeviceManagementDAOUtil.cleanupResources(stmt, null);
+ }
+ return status;
+ }
+
+ @Override
+ public List getAllIotDevices()
+ throws IotDeviceManagementDAOException {
+
+ Connection conn = null;
+ PreparedStatement stmt = null;
+ ResultSet resultSet = null;
+ IotDevice iotDevice;
+ List iotDevices = new ArrayList();
+
+ try {
+ conn = ArduinoDAO.getConnection();
+ String selectDBQuery =
+ "SELECT ARDUINO_DEVICE_ID, DEVICE_NAME " +
+ "FROM ARDUINO_DEVICE";
+ stmt = conn.prepareStatement(selectDBQuery);
+ resultSet = stmt.executeQuery();
+ while (resultSet.next()) {
+ iotDevice = new IotDevice();
+ iotDevice.setIotDeviceId(resultSet.getString(ArduinoConstants.DEVICE_PLUGIN_DEVICE_ID));
+ iotDevice.setIotDeviceName(resultSet.getString(ArduinoConstants.DEVICE_PLUGIN_DEVICE_NAME));
+
+ Map propertyMap = new HashMap();
+
+ iotDevice.setDeviceProperties(propertyMap);
+ iotDevices.add(iotDevice);
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("All Arduino device details have fetched from Arduino database.");
+ }
+ return iotDevices;
+ } catch (SQLException e) {
+ String msg = "Error occurred while fetching all Arduino device data'";
+ log.error(msg, e);
+ throw new IotDeviceManagementDAOException(msg, e);
+ } finally {
+ IotDeviceManagementDAOUtil.cleanupResources(stmt, resultSet);
+ ArduinoDAO.closeConnection();
+ }
+
+ }
+
+ }
\ No newline at end of file
diff --git a/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/util/ArduinoUtils.java b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/util/ArduinoUtils.java
new file mode 100644
index 0000000000..0dd5f36fc7
--- /dev/null
+++ b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/impl/util/ArduinoUtils.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2015, 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.
+ */
+
+package org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Map;
+
+/**
+ * Contains utility methods used by Arduino plugin.
+ */
+public class ArduinoUtils {
+
+ private static Log log = LogFactory.getLog(ArduinoUtils.class);
+
+ public static String getDeviceProperty(Map deviceProperties, String property) {
+
+ String deviceProperty = deviceProperties.get(property);
+
+ if (deviceProperty == null) {
+ return "";
+ }
+
+ return deviceProperty;
+ }
+
+
+}
diff --git a/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/internal/ArduinoManagementServiceComponent.java b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/internal/ArduinoManagementServiceComponent.java
new file mode 100644
index 0000000000..4d2564e74f
--- /dev/null
+++ b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.plugin.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/plugin/internal/ArduinoManagementServiceComponent.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2015, 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.
+ */
+
+package org.wso2.carbon.device.mgt.iot.arduino.plugin.internal;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.component.ComponentContext;
+import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
+import org.wso2.carbon.device.mgt.iot.arduino.plugin.impl.ArduinoManagerService;
+import org.wso2.carbon.device.mgt.iot.service.DeviceTypeService;
+
+
+/**
+ * @scr.component name="org.wso2.carbon.device.mgt.iot.arduino.internal.ArduinoManagementServiceComponent"
+ * immediate="true"
+ * @scr.reference name="wso2.carbon.device.mgt.iot.DeviceTypeService"
+ * interface="org.wso2.carbon.device.mgt.iot.service.DeviceTypeService"
+ * cardinality="1..1"
+ * policy="dynamic"
+ * bind="setDeviceTypeService"
+ * unbind="unsetDeviceTypeService"
+ */
+public class ArduinoManagementServiceComponent {
+
+
+ private ServiceRegistration arduinoServiceRegRef;
+
+
+
+ private static final Log log = LogFactory.getLog(ArduinoManagementServiceComponent.class);
+ protected void activate(ComponentContext ctx) {
+ if (log.isDebugEnabled()) {
+ log.debug("Activating Arduino Device Management Service Component");
+ }
+ try {
+ BundleContext bundleContext = ctx.getBundleContext();
+
+
+ arduinoServiceRegRef =
+ bundleContext.registerService(DeviceManagementService.class.getName(), new
+ ArduinoManagerService(), null);
+
+
+
+ if (log.isDebugEnabled()) {
+ log.debug("Arduino Device Management Service Component has been successfully activated");
+ }
+ } catch (Throwable e) {
+ log.error("Error occurred while activating Arduino Device Management Service Component", e);
+ }
+ }
+
+ protected void deactivate(ComponentContext ctx) {
+ if (log.isDebugEnabled()) {
+ log.debug("De-activating Arduino Device Management Service Component");
+ }
+ try {
+ if (arduinoServiceRegRef != null) {
+ arduinoServiceRegRef.unregister();
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug(
+ "Arduino Device Management Service Component has been successfully de-activated");
+ }
+ } catch (Throwable e) {
+ log.error("Error occurred while de-activating Arduino Device Management bundle", e);
+ }
+ }
+
+ protected void setDeviceTypeService(DeviceTypeService deviceTypeService) {
+ /* This is to avoid this component getting initialized before the
+ common registered */
+ if (log.isDebugEnabled()) {
+ log.debug("Data source service set to mobile service component");
+ }
+ }
+
+ protected void unsetDeviceTypeService(DeviceTypeService deviceTypeService) {
+ //do nothing
+ }
+
+
+
+}
diff --git a/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/pom.xml b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/pom.xml
new file mode 100644
index 0000000000..3fff740804
--- /dev/null
+++ b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/pom.xml
@@ -0,0 +1,161 @@
+
+
+
+
+
+ device-mgt-iot-arduino
+ org.wso2.carbon.devicemgt-plugins
+ 1.9.2-SNAPSHOT
+ ../pom.xml
+
+
+
+ 4.0.0
+ org.wso2.carbon.device.mgt.iot.arduino.service.impl
+ 1.9.2-SNAPSHOT
+ war
+ WSO2 Carbon - IoT Server Arduino API
+ WSO2 Carbon - Arduino Service API Implementation
+ http://wso2.org
+
+
+
+
+ org.wso2.carbon
+ org.wso2.carbon.utils
+ provided
+
+
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.common
+ provided
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.core
+ provided
+
+
+ org.apache.axis2.wso2
+ axis2-client
+
+
+
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.analytics
+ provided
+
+
+ org.apache.axis2.wso2
+ axis2-client
+
+
+
+
+
+
+
+ org.apache.cxf
+ cxf-rt-frontend-jaxws
+ provided
+
+
+ org.apache.cxf
+ cxf-rt-frontend-jaxrs
+ provided
+
+
+ org.apache.cxf
+ cxf-rt-transports-http
+ provided
+
+
+
+
+ org.eclipse.paho
+ mqtt-client
+ provided
+
+
+
+
+ org.apache.httpcomponents
+ httpasyncclient
+ 4.1
+ provided
+
+
+ org.wso2.carbon.devicemgt-plugins
+ org.wso2.carbon.device.mgt.iot
+ provided
+
+
+ org.wso2.carbon.devicemgt-plugins
+ org.wso2.carbon.device.mgt.iot.arduino.plugin.impl
+ provided
+
+
+
+
+ org.codehaus.jackson
+ jackson-core-asl
+
+
+ org.codehaus.jackson
+ jackson-jaxrs
+
+
+ javax
+ javaee-web-api
+ provided
+
+
+ javax.ws.rs
+ jsr311-api
+ provided
+
+
+
+
+
+
+
+ maven-compiler-plugin
+
+ UTF-8
+
+ ${wso2.maven.compiler.target}
+
+
+
+ maven-war-plugin
+
+ arduino
+
+
+
+
+
+
\ No newline at end of file
diff --git a/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerService.java b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerService.java
new file mode 100644
index 0000000000..ac88a357c4
--- /dev/null
+++ b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoControllerService.java
@@ -0,0 +1,173 @@
+/*
+ * Copyright (c) 2015, 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.
+ */
+
+package org.wso2.carbon.device.mgt.iot.arduino.service.impl;
+
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.context.PrivilegedCarbonContext;
+import org.wso2.carbon.device.mgt.analytics.exception.DataPublisherConfigurationException;
+import org.wso2.carbon.device.mgt.analytics.service.DeviceAnalyticsService;
+import org.wso2.carbon.device.mgt.common.DeviceManagementException;
+import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.DeviceJSON;
+import org.wso2.carbon.device.mgt.iot.arduino.service.impl.util.ArduinoMQTTSubscriber;
+import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants;
+import org.wso2.carbon.device.mgt.iot.DeviceController;
+import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.*;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import java.util.*;
+
+public class ArduinoControllerService {
+
+ private static Log log = LogFactory.getLog(ArduinoControllerService.class);
+
+ private static Map> replyMsgQueue = new HashMap<>();
+ private static Map> internalControlsQueue = new HashMap<>();
+ private static ArduinoMQTTSubscriber arduinoMQTTSubscriber;
+ private static final String TEMPERATURE_STREAM_DEFINITION = "org.wso2.iot.devices.temperature";
+ private final String SUPER_TENANT = "carbon.super";
+
+ public void setMqttArduinoSubscriber(ArduinoMQTTSubscriber arduinoMQTTSubscriber) {
+ ArduinoControllerService.arduinoMQTTSubscriber = arduinoMQTTSubscriber;
+ try {
+ arduinoMQTTSubscriber.connectAndSubscribe();
+ } catch (DeviceManagementException e) {
+ log.error(e.getErrorMessage());
+ }
+ }
+
+ public ArduinoMQTTSubscriber getMqttArduinoSubscriber() {
+ return arduinoMQTTSubscriber;
+ }
+
+ public static Map> getReplyMsgQueue() {
+ return replyMsgQueue;
+ }
+
+ public static Map> getInternalControlsQueue() {
+ return internalControlsQueue;
+ }
+
+ /* Service to switch arduino bulb (pin 13) between "ON" and "OFF"
+ Called by an external client intended to control the Arduino */
+ @Path("/bulb/{deviceId}/{state}")
+ @POST
+ public void switchBulb(@QueryParam("owner") String owner,
+ @PathParam("deviceId") String deviceId,
+ @PathParam("state") String state,
+ @Context HttpServletResponse response) {
+
+ String switchToState = state.toUpperCase();
+
+ if (!switchToState.equals(ArduinoConstants.STATE_ON) && !switchToState.equals(
+ ArduinoConstants.STATE_OFF)) {
+ log.error("The requested state change shoud be either - 'ON' or 'OFF'");
+ response.setStatus(HttpStatus.SC_BAD_REQUEST);
+ return;
+ }
+
+ try {
+ DeviceController deviceController = new DeviceController();
+ boolean result = deviceController.publishMqttControl(owner,
+ ArduinoConstants.DEVICE_TYPE,
+ deviceId, "BULB", switchToState);
+ if (result) {
+ response.setStatus(HttpStatus.SC_ACCEPTED);
+
+ } else {
+ response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+
+ }
+
+ } catch (DeviceControllerException e) {
+ response.setStatus(HttpStatus.SC_UNAUTHORIZED);
+
+ }
+
+ }
+
+ /* Service to poll the control-queue for the controls sent to the Arduino
+ Called by the Arduino device */
+ @Path("/readcontrols/{deviceId}")
+ @GET
+ public String readControls(@QueryParam("owner") String owner,
+ @PathParam("deviceId") String deviceId,
+ @Context HttpServletResponse response) {
+ String result;
+ LinkedList deviceControlList = internalControlsQueue.get(deviceId);
+
+ if (deviceControlList == null) {
+ result = "No controls have been set for device " + deviceId + " of owner " + owner;
+ response.setStatus(HttpStatus.SC_NO_CONTENT);
+ } else {
+ try {
+ result = deviceControlList.remove(); //returns the head value
+ response.setStatus(HttpStatus.SC_ACCEPTED);
+
+ } catch (NoSuchElementException ex) {
+ result = "There are no more controls for device " + deviceId + " of owner " +
+ owner;
+ response.setStatus(HttpStatus.SC_NO_CONTENT);
+ }
+ }
+ if (log.isDebugEnabled()) {
+ log.debug(result);
+ }
+
+ return result;
+ }
+
+
+ /*Service to push all the sensor data collected by the Arduino
+ Called by the Arduino device */
+ @Path("/pushdata")
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ public void pushData(final DeviceJSON dataMsg, @Context HttpServletResponse response) {
+
+ float temperature = dataMsg.value;
+
+ if (log.isDebugEnabled()) {
+ log.debug("Recieved Temperature Data Value: " + temperature + " degrees C");
+ }
+
+ PrivilegedCarbonContext.startTenantFlow();
+ PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
+ ctx.setTenantDomain(SUPER_TENANT, true);
+ DeviceAnalyticsService deviceAnalyticsService = (DeviceAnalyticsService) ctx
+ .getOSGiService(DeviceAnalyticsService.class, null);
+ Object metdaData[] = {dataMsg.owner, ArduinoConstants.DEVICE_TYPE, dataMsg.deviceId,
+ System.currentTimeMillis()};
+ Object payloadData[] = {temperature};
+ try {
+ deviceAnalyticsService.publishEvent(TEMPERATURE_STREAM_DEFINITION, "1.0.0",
+ metdaData, new Object[0], payloadData);
+ } catch (DataPublisherConfigurationException e) {
+ log.error("Error on connecting to data publisher");
+ response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+
+ } finally {
+ PrivilegedCarbonContext.endTenantFlow();
+ }
+ }
+}
diff --git a/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoManagerService.java b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoManagerService.java
new file mode 100644
index 0000000000..5b66c113d8
--- /dev/null
+++ b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/ArduinoManagerService.java
@@ -0,0 +1,276 @@
+/*
+ * Copyright (c) 2015, 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.
+ */
+
+package org.wso2.carbon.device.mgt.iot.arduino.service.impl;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.device.mgt.common.Device;
+import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
+import org.wso2.carbon.device.mgt.common.DeviceManagementException;
+import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
+import org.wso2.carbon.device.mgt.iot.DeviceManagement;
+import org.wso2.carbon.device.mgt.iot.util.ZipArchive;
+import org.wso2.carbon.device.mgt.iot.util.ZipUtil;
+import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+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.Context;
+import javax.ws.rs.core.Response;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.Date;
+import java.util.UUID;
+
+public class ArduinoManagerService {
+
+ private static Log log = LogFactory.getLog(ArduinoManagerService.class);
+
+ //TODO; replace this tenant domain
+ private final String SUPER_TENANT = "carbon.super";
+ @Context //injected response proxy supporting multiple thread
+ private HttpServletResponse response;
+
+ @Path("/device/register")
+ @PUT
+ public boolean register(@QueryParam("deviceId") String deviceId,
+ @QueryParam("name") String name, @QueryParam("owner") String owner) {
+
+ DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
+
+ DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
+ deviceIdentifier.setId(deviceId);
+ deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE);
+ try {
+ if (deviceManagement.getDeviceManagementService().isEnrolled(deviceIdentifier)) {
+ response.setStatus(Response.Status.CONFLICT.getStatusCode());
+ 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(ArduinoConstants.DEVICE_TYPE);
+ enrolmentInfo.setOwner(owner);
+ device.setEnrolmentInfo(enrolmentInfo);
+ boolean added = deviceManagement.getDeviceManagementService().enrollDevice(device);
+ if (added) {
+ response.setStatus(Response.Status.OK.getStatusCode());
+ } else {
+ response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
+ }
+
+ return added;
+ } catch (DeviceManagementException e) {
+ response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
+ return false;
+ } finally {
+ deviceManagement.endTenantFlow();
+ }
+ }
+
+ @Path("/device/remove/{device_id}")
+ @DELETE
+ public void removeDevice(@PathParam("device_id") String deviceId,
+ @Context HttpServletResponse response) {
+
+ DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
+ DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
+ deviceIdentifier.setId(deviceId);
+ deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE);
+ try {
+ boolean removed = deviceManagement.getDeviceManagementService().disenrollDevice(
+ deviceIdentifier);
+ if (removed) {
+ response.setStatus(Response.Status.OK.getStatusCode());
+
+ } else {
+ response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
+
+ }
+ } catch (DeviceManagementException e) {
+ response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
+ } finally {
+ deviceManagement.endTenantFlow();
+ }
+
+
+ }
+
+ @Path("/device/update/{device_id}")
+ @POST
+ public boolean updateDevice(@PathParam("device_id") String deviceId,
+ @QueryParam("name") String name,
+ @Context HttpServletResponse response) {
+
+ DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
+
+ DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
+ deviceIdentifier.setId(deviceId);
+ deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE);
+ try {
+ Device device = deviceManagement.getDeviceManagementService().getDevice(
+ deviceIdentifier);
+ device.setDeviceIdentifier(deviceId);
+
+ // device.setDeviceTypeId(deviceTypeId);
+ device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
+
+ device.setName(name);
+ device.setType(ArduinoConstants.DEVICE_TYPE);
+
+ boolean updated = deviceManagement.getDeviceManagementService().modifyEnrollment(
+ device);
+
+
+ if (updated) {
+ response.setStatus(Response.Status.OK.getStatusCode());
+
+ } else {
+ response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
+
+ }
+ return updated;
+ } catch (DeviceManagementException e) {
+ response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
+ return false;
+ } finally {
+ deviceManagement.endTenantFlow();
+ }
+
+ }
+
+ @Path("/device/{device_id}")
+ @GET
+ @Consumes("application/json")
+ @Produces("application/json")
+ public Device getDevice(@PathParam("device_id") String deviceId) {
+
+ DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
+ DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
+ deviceIdentifier.setId(deviceId);
+ deviceIdentifier.setType(ArduinoConstants.DEVICE_TYPE);
+
+ try {
+ Device device = deviceManagement.getDeviceManagementService().getDevice(
+ deviceIdentifier);
+
+ return device;
+ } catch (DeviceManagementException e) {
+ response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
+ return null;
+ } finally {
+ deviceManagement.endTenantFlow();
+ }
+
+ }
+
+ @Path("/device/{sketch_type}/download")
+ @GET
+ @Produces("application/octet-stream")
+ public Response downloadSketch(@QueryParam("owner") String owner,
+ @QueryParam("deviceName") String customDeviceName,
+ @PathParam("sketch_type") String
+ sketchType) {
+
+ ZipArchive zipFile = null;
+ try {
+ zipFile = createDownloadFile(owner, customDeviceName, sketchType);
+ Response.ResponseBuilder rb = Response.ok(zipFile.getZipFile());
+ rb.header("Content-Disposition",
+ "attachment; filename=\"" + zipFile.getFileName() + "\"");
+ return rb.build();
+ } catch (IllegalArgumentException ex) {
+ return Response.status(400).entity(ex.getMessage()).build();//bad request
+ } catch (DeviceManagementException ex) {
+ return Response.status(500).entity(ex.getMessage()).build();
+ }
+
+ }
+
+ @Path("/device/{sketch_type}/generate_link")
+ @GET
+ public Response generateSketchLink(@QueryParam("owner") String owner,
+ @QueryParam("deviceName") String customDeviceName,
+ @PathParam("sketch_type") String
+ sketchType) {
+
+ ZipArchive zipFile = null;
+ try {
+ zipFile = createDownloadFile(owner, customDeviceName, sketchType);
+ Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId());
+ return rb.build();
+ } catch (IllegalArgumentException ex) {
+ return Response.status(400).entity(ex.getMessage()).build();//bad request
+ } catch (DeviceManagementException ex) {
+ return Response.status(500).entity(ex.getMessage()).build();
+ }
+
+ }
+
+ private ZipArchive createDownloadFile(String owner, String customDeviceName, String sketchType)
+ throws DeviceManagementException {
+ if (owner == null) {
+ throw new IllegalArgumentException("Error on createDownloadFile() Owner is null!");
+ }
+
+ //create new device id
+ String deviceId = shortUUID();
+
+ //create token
+ String token = UUID.randomUUID().toString();
+ String refreshToken = UUID.randomUUID().toString();
+ //adding registering data
+
+ String deviceName = customDeviceName + "_" + deviceId;
+ boolean status = register(deviceId, deviceName, owner);
+ if (!status) {
+ String msg = "Error occurred while registering the device with " + "id: " + deviceId
+ + " owner:" + owner;
+ throw new DeviceManagementException(msg);
+ }
+
+ ZipUtil ziputil = new ZipUtil();
+ ZipArchive zipFile = null;
+
+ zipFile = ziputil.downloadSketch(owner, SUPER_TENANT, sketchType, deviceId, deviceName, token, refreshToken);
+ zipFile.setDeviceId(deviceId);
+ return zipFile;
+ }
+
+ private static String shortUUID() {
+ UUID uuid = UUID.randomUUID();
+ long l = ByteBuffer.wrap(uuid.toString().getBytes(StandardCharsets.UTF_8)).getLong();
+ return Long.toString(l, Character.MAX_RADIX);
+ }
+
+}
diff --git a/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/util/ArduinoMQTTSubscriber.java b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/util/ArduinoMQTTSubscriber.java
new file mode 100644
index 0000000000..c7e30743be
--- /dev/null
+++ b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/util/ArduinoMQTTSubscriber.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2015, 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.
+ */
+
+package org.wso2.carbon.device.mgt.iot.arduino.service.impl.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.eclipse.paho.client.mqttv3.MqttMessage;
+import org.wso2.carbon.device.mgt.iot.arduino.service.impl.ArduinoControllerService;
+import org.wso2.carbon.device.mgt.iot.arduino.plugin.constants.ArduinoConstants;
+import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
+import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttSubscriber;
+
+import java.io.File;
+import java.util.LinkedList;
+import java.util.UUID;
+
+public class ArduinoMQTTSubscriber extends MqttSubscriber {
+
+ private static Log log = LogFactory.getLog(ArduinoMQTTSubscriber.class);
+ private static final String iotServerSubscriber = UUID.randomUUID().toString().substring(0,5);
+ private static final String subscribetopic =
+ "wso2" + File.separator + "iot" + File.separator + "+" + File.separator +
+ ArduinoConstants.DEVICE_TYPE + File.separator + "#";
+
+
+ //make it singleton
+ private ArduinoMQTTSubscriber() {
+ super(iotServerSubscriber, ArduinoConstants.DEVICE_TYPE, MqttConfig.getInstance().getMqttQueueEndpoint(),
+ subscribetopic);
+ }
+
+ @Override protected void postMessageArrived(final String topic, final MqttMessage message) {
+ int lastIndex = topic.lastIndexOf("/");
+ String deviceId = topic.substring(lastIndex + 1);
+
+ lastIndex = message.toString().lastIndexOf(":");
+ String msgContext = message.toString().substring(lastIndex + 1);
+
+ LinkedList deviceControlList = null;
+ LinkedList replyMessageList = null;
+
+ if (msgContext.equals("IN") || msgContext.equals(ArduinoConstants.STATE_ON) || msgContext
+ .equals(ArduinoConstants.STATE_OFF)) {
+ log.info("Recieved a control message: ");
+ log.info("Control message topic: " + topic);
+ log.info("Control message: " + message.toString());
+ synchronized (ArduinoControllerService.getInternalControlsQueue()) {
+ deviceControlList = ArduinoControllerService.getInternalControlsQueue().get(deviceId);
+ if (deviceControlList == null) {
+ ArduinoControllerService.getInternalControlsQueue()
+ .put(deviceId, deviceControlList = new LinkedList());
+ }
+ }
+ deviceControlList.add(message.toString());
+ } else if (msgContext.equals("OUT")) {
+ log.info("Recieved reply from a device: ");
+ log.info("Reply message topic: " + topic);
+ log.info("Reply message: " + message.toString().substring(0, lastIndex));
+ synchronized (ArduinoControllerService.getReplyMsgQueue()) {
+ replyMessageList = ArduinoControllerService.getReplyMsgQueue().get(deviceId);
+ if (replyMessageList == null) {
+ ArduinoControllerService.getReplyMsgQueue()
+ .put(deviceId, replyMessageList = new LinkedList());
+ }
+ }
+ replyMessageList.add(message.toString());
+ }
+
+ }
+}
diff --git a/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/util/DeviceJSON.java b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/util/DeviceJSON.java
new file mode 100644
index 0000000000..22e8caedac
--- /dev/null
+++ b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/impl/util/DeviceJSON.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2015, 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.
+ */
+
+package org.wso2.carbon.device.mgt.iot.arduino.service.impl.util;
+
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class DeviceJSON {
+ @XmlElement(required = true) public String owner;
+ @XmlElement(required = true) public String deviceId;
+ @XmlElement(required = true) public String reply;
+ @XmlElement public Long time;
+ @XmlElement public String key;
+ @XmlElement public float value;
+}
diff --git a/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/webapp/META-INF/webapp-classloading.xml b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/webapp/META-INF/webapp-classloading.xml
new file mode 100644
index 0000000000..fa44619195
--- /dev/null
+++ b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/webapp/META-INF/webapp-classloading.xml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+ false
+
+
+ CXF,Carbon
+
diff --git a/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml
new file mode 100644
index 0000000000..dc40589708
--- /dev/null
+++ b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/webapp/WEB-INF/cxf-servlet.xml
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/webapp/WEB-INF/web.xml b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000000..2175bbda26
--- /dev/null
+++ b/components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.service.impl/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,23 @@
+
+
+ Arduino
+ Arduino
+
+
+ CXFServlet
+ org.apache.cxf.transport.servlet.CXFServlet
+ 1
+
+
+
+
+ CXFServlet
+ /*
+
+
+
+
diff --git a/components/device-mgt-iot-arduino/pom.xml b/components/device-mgt-iot-arduino/pom.xml
new file mode 100644
index 0000000000..42ce389a7e
--- /dev/null
+++ b/components/device-mgt-iot-arduino/pom.xml
@@ -0,0 +1,62 @@
+
+
+
+
+
+
+ org.wso2.carbon.devicemgt-plugins
+ carbon-device-mgt-plugins-parent
+ 1.9.2-SNAPSHOT
+ ../../pom.xml
+
+
+ 4.0.0
+ device-mgt-iot-arduino
+ 1.9.2-SNAPSHOT
+ pom
+ WSO2 Carbon - IoT Device Ardunio Management Component
+ http://wso2.org
+
+
+ org.wso2.carbon.device.mgt.iot.arduino.plugin.impl
+ org.wso2.carbon.device.mgt.iot.arduino.service.impl
+
+
+
+
+
+
+ org.apache.felix
+ maven-scr-plugin
+ 1.7.2
+
+
+ generate-scr-scrdescriptor
+
+ scr
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/pom.xml b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/pom.xml
index 2ca93920ac..253485db8c 100644
--- a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/pom.xml
+++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl/pom.xml
@@ -59,7 +59,7 @@
${project.artifactId}
${project.artifactId}
${carbon.iot.device.mgt.version}
- IoT Server Impl Bundle
+ IoT Server Virtual Firealarm Impl Bundle
org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal
org.osgi.framework,
diff --git a/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/pom.xml b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/pom.xml
new file mode 100644
index 0000000000..d8ff3a757f
--- /dev/null
+++ b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/pom.xml
@@ -0,0 +1,142 @@
+
+
+
+
+
+
+
+ org.wso2.carbon.devicemgt-plugins
+ device-mgt-iot-arduino-feature
+ 1.9.2-SNAPSHOT
+ ../pom.xml
+
+
+ 4.0.0
+ org.wso2.carbon.device.mgt.iot.arduino.feature
+ pom
+ 1.9.2-SNAPSHOT
+ WSO2 Carbon - IoT Server Arduino Feature
+ http://wso2.org
+ This feature contains the Arduino Device type specific implementations for the IoT Server
+
+
+
+
+ org.wso2.carbon.devicemgt-plugins
+ org.wso2.carbon.device.mgt.iot.arduino.plugin.impl
+
+
+ org.wso2.carbon.devicemgt-plugins
+ org.wso2.carbon.device.mgt.iot.arduino.service.impl
+ war
+
+
+
+
+
+
+ maven-resources-plugin
+
+
+ copy-resources
+ generate-resources
+
+ copy-resources
+
+
+ src/main/resources
+
+
+ resources
+
+ build.properties
+ p2.inf
+
+
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+
+
+ copy-jaxrs-war
+ package
+
+ copy
+
+
+
+
+ org.wso2.carbon.devicemgt-plugins
+ org.wso2.carbon.device.mgt.iot.arduino.service.impl
+
+ war
+ true
+ ${basedir}/src/main/resources/webapps/
+ arduino.war
+
+
+
+
+
+
+
+
+ org.wso2.maven
+ carbon-p2-plugin
+
+
+ p2-feature-generation
+ package
+
+ p2-feature-gen
+
+
+ org.wso2.carbon.device.mgt.iot.arduino
+ ../../../features/etc/feature.properties
+
+
+ org.wso2.carbon.p2.category.type:server
+ org.eclipse.equinox.p2.type.group:false
+
+
+
+
+ org.wso2.carbon.devicemgt-plugins:org.wso2.carbon.device.mgt.iot.arduino.plugin.impl:${carbon.iot.device.mgt.version}
+
+
+
+ org.wso2.carbon.core.server:${carbon.kernel.version}
+
+ org.wso2.carbon.device.mgt.server:${carbon.device.mgt.version}
+
+
+
+
+
+
+
+
+
diff --git a/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/ArduinoBoardSketch.h b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/ArduinoBoardSketch.h
new file mode 100644
index 0000000000..c8ac26e914
--- /dev/null
+++ b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/ArduinoBoardSketch.h
@@ -0,0 +1,62 @@
+/**
+ * Copyright (c) 2015, 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.
+**/
+
+#ifndef ArduinoWifiAgent_H
+#define ArduinoWifiAgent_H
+
+#include "Arduino.h"
+
+// These are the interrupt and control pins
+#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin!
+// These can be any two pins
+#define ADAFRUIT_CC3000_VBAT 5
+#define ADAFRUIT_CC3000_CS 10
+
+#define WLAN_SSID "SSID" // cannot be longer than 32 characters!
+#define WLAN_PASS "password"
+
+#define WLAN_SECURITY WLAN_SEC_WPA
+// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
+#define IDLE_TIMEOUT_MS 3000
+
+#define DEVICE_OWNER "${DEVICE_OWNER}"
+#define DEVICE_ID "${DEVICE_ID}"
+#define DEVICE_TOKEN "${DEVICE_TOKEN}"
+#define REFRESH_DEVICE_TOKEN "${REFRESH_DEVICE_TOKEN}"
+
+
+#define SERVICE_PORT 9763
+#define SERVICE_EPOINT "/arduino/controller/"
+
+#define POLL_INTERVAL 1000
+#define PUSH_INTERVAL 10000
+#define DEBUG true
+#define CON_DEBUG true
+
+byte server[4] = { 192, 168, 1, 101 };
+String host, jsonPayLoad, replyMsg;
+String responseMsg, subStrn;
+double cpuTemperature =0;
+static unsigned long pushTimestamp = 0;
+static unsigned long pollTimestamp = 0;
+
+
+#endif
+
+
+
diff --git a/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/ArduinoBoardSketch.ino b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/ArduinoBoardSketch.ino
new file mode 100644
index 0000000000..50601b634a
--- /dev/null
+++ b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/ArduinoBoardSketch.ino
@@ -0,0 +1,75 @@
+/**
+ * Copyright (c) 2015, 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.
+**/
+
+
+#include "ArduinoBoardSketch.h"
+#include
+#include
+#include
+Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
+ SPI_CLOCK_DIVIDER); // you can change this clock speed
+
+Adafruit_CC3000_Client client;
+
+uint32_t sserver;
+
+
+void setup()
+{
+ Serial.begin(9600);
+ Serial.println(F("Internal Temperature Sensor"));
+ pinMode(6, OUTPUT);
+ connectHttp();
+ setupResource();
+ wdt_enable(WDTO_8S);
+}
+
+void loop()
+{
+ while( !cc3000.checkConnected() ){
+ connectHttp();
+
+ }
+ cpuTemperature=getBoardTemp();
+
+
+ if(millis() - pushTimestamp > PUSH_INTERVAL){
+ while (!client.connected()) {
+ setupClient();
+ }
+ pushData();
+
+ pushTimestamp = millis();
+ }
+
+ //Serial.println("PUSHED");
+
+
+ if(millis() - pollTimestamp > POLL_INTERVAL){
+ while (!client.connected()) {
+ setupClient();
+ }
+ readControls();
+
+ pollTimestamp = millis();
+
+ }
+
+ //Serial.println("LOOPING");
+ wdt_reset();
+}
diff --git a/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/Connect.ino b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/Connect.ino
new file mode 100644
index 0000000000..38dfeacdaa
--- /dev/null
+++ b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/Connect.ino
@@ -0,0 +1,175 @@
+/**
+ * Copyright (c) 2015, 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.
+**/
+
+#include "ArduinoBoardSketch.h"
+/**********************************************************************************************
+ Use the below variables when required to set a static IP for the WifiSheild
+ ***********************************************************************************************/
+// byte dns2[] = { 8, 8, 8, 8 };
+// byte subnet[] = { 255, 255, 255, 0 };
+// byte gateway[] = { 10, 100, 9, 254 };
+// byte deviceIP[4] = { 10, 100, 9, 9 };
+// byte gateway[] = { 192, 168, 1, 1 };
+// byte deviceIP[4] = { 192, 168, 1, 219 };
+
+// uint32_t ip, ddns, ssubnet, ggateway;
+
+// byte mac[6] = { 0xC0, 0x4A, 0x00, 0x1A, 0x08, 0xDA }; //mac - c0:4a:00:1a:08:da
+// c0:4a:00:1a:03:f8
+// b8:27:eb:88:37:7a
+String connecting = "connecting.... ";
+
+void connectHttp() {
+ /* Initialise the module */
+ if(DEBUG) Serial.println(F("\nInitializing..."));
+ if (!cc3000.begin())
+ {
+ if(DEBUG) Serial.println(F("Couldn't begin()! Check your wiring?"));
+ while(1);
+ }
+
+ // if( cc3000.setMacAddress(mac) ) { // Set your own mac and print it to re-check
+ // uint8_t address[6];
+ // cc3000.getMacAddress(address);
+ // if(DEBUG){
+ // Serial.print(address[0], HEX); Serial.print(":");
+ // Serial.print(address[1], HEX); Serial.print(":");
+ // Serial.print(address[2], HEX); Serial.print(":");
+ // Serial.print(address[3], HEX); Serial.print(":");
+ // Serial.print(address[4], HEX); Serial.print(":");
+ // Serial.println(address[5], HEX);
+ // }
+ // }
+
+ /**********************************************************************************************
+ Only required if using static IP for the WifiSheild
+ ***********************************************************************************************/
+
+ // ip = cc3000.IP2U32(deviceIP[0], deviceIP[1], deviceIP[2], deviceIP[3]);
+ // ddns = cc3000.IP2U32(dns2[0], dns2[1], dns2[2], dns2[3]);
+ // ssubnet = cc3000.IP2U32(subnet[0], subnet[1], subnet[2], subnet[3]);
+ // ggateway = cc3000.IP2U32(gateway[0], gateway[1], gateway[2], gateway[3]);
+ // cc3000.setStaticIPAddress(ip, ssubnet, ggateway, ddns); // required for setting static IP
+
+ /***********************************************************************************************/
+
+ sserver = cc3000.IP2U32(server[0], server[1], server[2], server[3]);
+
+ if(CON_DEBUG) {
+ Serial.print(F("\nAttempting to connect to "));
+ Serial.println(WLAN_SSID);
+ }
+
+ if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
+ if(CON_DEBUG) Serial.println(F("Failed!"));
+ while(1);
+ }
+
+ if(CON_DEBUG) Serial.println(F("Connected to Wifi network!"));
+
+ if(CON_DEBUG) Serial.println(F("Request DHCP"));
+ while (!cc3000.checkDHCP())
+ {
+ delay(100); // ToDo: Insert a DHCP timeout!
+ }
+
+ /* Display the IP address DNS, Gateway, etc. */
+ while (! displayConnectionDetails()) {
+ delay(1000);
+ }
+
+ client = cc3000.connectTCP(sserver, SERVICE_PORT); //SERVICE_PORT
+ if (client.connected()) {
+ if(CON_DEBUG) Serial.println("client Connected to server");
+ } else {
+ if(CON_DEBUG) Serial.println(F("client Connection failed"));
+ }
+
+
+
+
+ if(CON_DEBUG) Serial.println(F("-------------------------------------"));
+}
+
+
+void setupResource(){
+ String hostIP = getHostIP(server);
+ String port = String(SERVICE_PORT);
+
+ host = "Host: " + hostIP + ":" + port;
+ if(DEBUG) Serial.println(host);
+
+ jsonPayLoad = "{\"owner\":\"";
+ jsonPayLoad += String(DEVICE_OWNER);
+ jsonPayLoad += "\",\"deviceId\":\"";
+ jsonPayLoad += String(DEVICE_ID);
+ jsonPayLoad += "\",\"reply\":\"";
+
+ if(DEBUG) {
+ Serial.print("JSON Payload: ");
+ Serial.println(jsonPayLoad);
+ Serial.println("-------------------------------");
+ }
+}
+
+String getHostIP(byte server[4]){
+ String hostIP = String(server[0]);
+
+ for ( int index = 1; index < 4; index++) {
+ hostIP += "." + String(server[index]);
+ }
+
+ return hostIP;
+}
+
+
+bool displayConnectionDetails(void)
+{
+ uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
+
+ if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
+ {
+ if(DEBUG) Serial.println(F("Unable to retrieve the IP Address!\r\n"));
+ return false;
+ }
+ else
+ {
+ if(CON_DEBUG) {
+ Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
+ Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask);
+ Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway);
+ Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv);
+ Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv);
+ Serial.println();
+ }
+ return true;
+ }
+}
+
+void setupClient(){
+ client = cc3000.connectTCP(sserver, SERVICE_PORT); //SERVICE_PORT
+ if (client.connected()) {
+ if(CON_DEBUG) Serial.println("client Connected to server");
+ } else {
+ while( !cc3000.checkConnected() ){
+ connectHttp();
+
+ }
+ if(CON_DEBUG) Serial.println(F("client Connection failed"));
+ }
+}
diff --git a/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/PollServer.ino b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/PollServer.ino
new file mode 100644
index 0000000000..a3bfce0e18
--- /dev/null
+++ b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/PollServer.ino
@@ -0,0 +1,66 @@
+/**
+ * Copyright (c) 2015, 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.
+**/
+
+#include "ArduinoBoardSketch.h"
+void readControls() {
+ // String responseMsg;
+
+ client.fastrprint(F("GET "));
+ client.fastrprint(SERVICE_EPOINT);
+ client.fastrprint(F("readcontrols/"));
+ client.fastrprint(DEVICE_ID);
+ client.fastrprint(F("?owner="));
+ client.fastrprint(DEVICE_OWNER);
+ client.fastrprint(F(" HTTP/1.1")); client.fastrprint(F("\n"));
+ client.fastrprint(host.c_str()); client.fastrprint(F("\n"));
+ client.println();
+
+ delay(1000);
+
+
+ while (client.available()) {
+ char response = client.read();
+ responseMsg += response;
+
+ }
+ int index = responseMsg.lastIndexOf(":");
+ int newLine = responseMsg.lastIndexOf("\n");
+ subStrn = responseMsg.substring(index + 1);
+ responseMsg = responseMsg.substring(newLine + 1, index);
+ if(DEBUG) {
+ Serial.print(responseMsg);
+ Serial.println();
+ Serial.println("-------------------------------");
+ }
+
+ if (subStrn.equals("ON")) {
+ Serial.println("ITS ON");
+ //digitalWrite(13, HIGH);
+ digitalWrite(6, HIGH);
+ } else if (subStrn.equals("OFF")){
+
+ Serial.println("ITS OFF");
+ //digitalWrite(13, LOW);
+ digitalWrite(6, LOW);
+
+ }
+
+}
+
+
+
diff --git a/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/PushData.ino b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/PushData.ino
new file mode 100644
index 0000000000..faaa72f01d
--- /dev/null
+++ b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/PushData.ino
@@ -0,0 +1,138 @@
+/**
+ * Copyright (c) 2015, 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.
+**/
+
+#include "ArduinoBoardSketch.h"
+
+/**********************************************************************************************
+ This method will traverse the array of digital pins and batch the data from the those pins together.
+ It makes a single call to the server and sends all pin values as a batch.
+ Server dis-assembles it accordingly and makes multiple publish calls for each sensor type.
+ ***********************************************************************************************/
+
+void pushData(){
+ String payLoad = "Data";
+ payLoad = payLoad + "\",\"value\":\"";
+
+
+ payLoad+=cpuTemperature;
+
+
+ payLoad += "\"}";
+
+ client.fastrprint(F("POST "));
+ client.fastrprint(SERVICE_EPOINT); client.fastrprint(F("pushdata"));
+ client.fastrprint(F(" HTTP/1.1")); client.fastrprint(F("\n"));
+ client.fastrprint(host.c_str()); client.fastrprint(F("\n"));
+ client.fastrprint(F("Content-Type: application/json")); client.fastrprint(F("\n"));
+ client.fastrprint(F("Content-Length: "));
+
+ int payLength = jsonPayLoad.length() + payLoad.length();
+
+ client.fastrprint(String(payLength).c_str()); client.fastrprint(F("\n"));
+ client.fastrprint(F("\n"));
+
+ if(DEBUG) {
+ Serial.print("POST ");
+ Serial.print(SERVICE_EPOINT); Serial.print("pushdata");
+ Serial.print(" HTTP/1.1"); Serial.println();
+ Serial.print(host); Serial.println();
+ Serial.print("Content-Type: application/json"); Serial.println();
+ Serial.print("Content-Length: ");
+ Serial.print(payLength); Serial.println();
+ Serial.println();
+ }
+
+
+ int chunkSize = 50;
+
+ for (int i = 0; i < jsonPayLoad.length(); i++) {
+ if ( (i+1)*chunkSize > jsonPayLoad.length()) {
+ client.print(jsonPayLoad.substring(i*chunkSize, jsonPayLoad.length()));
+ if(DEBUG) Serial.print(jsonPayLoad.substring(i*chunkSize, jsonPayLoad.length()));
+ i = jsonPayLoad.length();
+ } else {
+ client.print(jsonPayLoad.substring(i*chunkSize, (i+1)*chunkSize));
+ if(DEBUG) Serial.print(jsonPayLoad.substring(i*chunkSize, (i+1)*chunkSize));
+ }
+ }
+
+ for (int i = 0; i < payLoad.length(); i++) {
+ if ( (i+1)*chunkSize > payLoad.length()) {
+ client.print(payLoad.substring(i*chunkSize, payLoad.length()));
+ if(DEBUG) Serial.print(payLoad.substring(i*chunkSize, payLoad.length()));
+ i = payLoad.length();
+ } else {
+ client.print(payLoad.substring(i*chunkSize, (i+1)*chunkSize));
+ if(DEBUG) Serial.print(payLoad.substring(i*chunkSize, (i+1)*chunkSize));
+ }
+ }
+
+ client.fastrprint(F("\n"));
+ if(DEBUG) Serial.println();
+
+ delay(1000);
+
+
+ while (client.available()) {
+ char response = client.read();
+ if(DEBUG) Serial.print(response);
+ }
+
+
+ if(DEBUG) {
+ Serial.println();
+ Serial.println("-------------------------------");
+ }
+
+ payLoad = "";
+}
+
+
+
+
+double getBoardTemp(void)
+{
+ unsigned int wADC;
+ double t;
+
+ // The internal temperature has to be used
+ // with the internal reference of 1.1V.
+ // Channel 8 can not be selected with
+ // the analogRead function yet.
+
+ // Set the internal reference and mux.
+ ADMUX = (_BV(REFS1) | _BV(REFS0) | _BV(MUX3));
+ ADCSRA |= _BV(ADEN); // enable the ADC
+
+ delay(20); // wait for voltages to become stable.
+
+ ADCSRA |= _BV(ADSC); // Start the ADC
+
+ // Detect end-of-conversion
+ while (bit_is_set(ADCSRA,ADSC));
+
+ // Reading register "ADCW" takes care of how to read ADCL and ADCH.
+ wADC = ADCW;
+
+ // The offset of 324.31 could be wrong. It is just an indication.
+ t = (wADC - 324.31 ) / 1.22;
+
+ // The returned temperature is in degrees Celcius.
+ return (t);
+}
+
diff --git a/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/sketch.properties b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/sketch.properties
new file mode 100644
index 0000000000..57ba905ef0
--- /dev/null
+++ b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/agent/sketch.properties
@@ -0,0 +1,20 @@
+#
+# Copyright (c) 2015, 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.
+#
+
+templates=ArduinoBoardSketch.h
+zipfilename=ArduinoBoardSketch.zip
\ No newline at end of file
diff --git a/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/build.properties b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/build.properties
new file mode 100644
index 0000000000..9c86577d76
--- /dev/null
+++ b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/build.properties
@@ -0,0 +1 @@
+custom = true
diff --git a/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/configs/arduino.xml b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/configs/arduino.xml
new file mode 100644
index 0000000000..c6adf5d565
--- /dev/null
+++ b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/configs/arduino.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ jdbc/Arduino_DB
+
+
+
diff --git a/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/datasources/arduino-datasources.xml b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/datasources/arduino-datasources.xml
new file mode 100644
index 0000000000..4c6d53263f
--- /dev/null
+++ b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/datasources/arduino-datasources.xml
@@ -0,0 +1,48 @@
+
+
+
+
+ org.wso2.carbon.ndatasource.rdbms.RDBMSDataSourceReader
+
+
+
+
+ Arduino_DB
+ The datasource used for the Virtual-Firealarm database
+
+ jdbc/ArduinoDM_DB
+
+
+
+ jdbc:h2:repository/database/VirtualFireAlarmDM_DB;DB_CLOSE_ON_EXIT=FALSE
+
+ wso2carbon
+ wso2carbon
+ org.h2.Driver
+ 50
+ 60000
+ true
+ SELECT 1
+ 30000
+
+
+
+
+
+
diff --git a/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/dbscripts/h2_arduino.sql b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/dbscripts/h2_arduino.sql
new file mode 100644
index 0000000000..2e9bc926b5
--- /dev/null
+++ b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/dbscripts/h2_arduino.sql
@@ -0,0 +1,11 @@
+
+-- -----------------------------------------------------
+-- Table for `ARDUINO_DEVICE`
+-- -----------------------------------------------------
+CREATE TABLE IF NOT EXISTS `ARDUINO_DEVICE` (
+ `ARDUINO_DEVICE_ID` VARCHAR(45) NOT NULL ,
+ `DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL,
+ PRIMARY KEY (`ARDUINO_DEVICE_ID`) );
+
+
+
diff --git a/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/dbscripts/mysql_arduino.sql b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/dbscripts/mysql_arduino.sql
new file mode 100644
index 0000000000..a9d5fd9224
--- /dev/null
+++ b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/dbscripts/mysql_arduino.sql
@@ -0,0 +1,12 @@
+-- -----------------------------------------------------
+-- Table for `ARDUINO_DEVICE`
+-- -----------------------------------------------------
+CREATE TABLE IF NOT EXISTS `ARDUINO_DEVICE` (
+ `ARDUINO_DEVICE_ID` VARCHAR(45) NOT NULL ,
+ `DEVICE_NAME` VARCHAR(100) NULL DEFAULT NULL,
+ PRIMARY KEY (`ARDUINO_DEVICE_ID`) )
+ENGINE = InnoDB;
+
+
+
+
diff --git a/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/p2.inf b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/p2.inf
new file mode 100644
index 0000000000..dfd77312db
--- /dev/null
+++ b/features/device-mgt-iot-arduino-feature/org.wso2.carbon.device.mgt.iot.arduino.feature/src/main/resources/p2.inf
@@ -0,0 +1,13 @@
+instructions.configure = \
+org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../conf/devicetype-conf/);\
+org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.arduino_${feature.version}/configs/,target:${installFolder}/../../conf/devicetype-conf/,overwrite:true);\
+org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/webapps/);\
+org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.arduino_${feature.version}/webapps/,target:${installFolder}/../../deployment/server/webapps/,overwrite:true);\
+org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../resources/sketches/);\
+org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../resources/sketches/arduino/);\
+org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.arduino_${feature.version}/agent/,target:${installFolder}/../../resources/sketches/arduino/,overwrite:true);\
+org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.arduino_${feature.version}/dbscripts/,target:${installFolder}/../../../dbscripts/cdm/plugins/arduino,overwrite:true);\
+org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/jaggeryapps/);\
+org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.arduino_${feature.version}/jaggeryapps/,target:${installFolder}/../../deployment/server/jaggeryapps/,overwrite:true);\
+org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../conf/datasources/devicemgt/);\
+org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.arduino_${feature.version}/datasources/,target:${installFolder}/../../conf/datasources/devicemgt,overwrite:true);\
diff --git a/features/device-mgt-iot-arduino-feature/pom.xml b/features/device-mgt-iot-arduino-feature/pom.xml
new file mode 100644
index 0000000000..2dba8b7603
--- /dev/null
+++ b/features/device-mgt-iot-arduino-feature/pom.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+ org.wso2.carbon.devicemgt-plugins
+ carbon-device-mgt-plugins-parent
+ 1.9.2-SNAPSHOT
+ ../../pom.xml
+
+
+ 4.0.0
+ device-mgt-iot-arduino-feature
+ 1.9.2-SNAPSHOT
+ pom
+ WSO2 Carbon - IoT Server Arduino Device Feature
+ http://wso2.org
+
+
+ org.wso2.carbon.device.mgt.iot.arduino.feature
+
+
+
diff --git a/pom.xml b/pom.xml
index f2f7968dfe..5c41a8bcd1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -47,10 +47,11 @@
components/device-mgt-mdm-windows
- components/device-mgt-iot-virtualfirealarm
- components/device-mgt-iot-digitaldisplay
components/device-mgt-iot-androidsense
+ components/device-mgt-iot-arduino
+ components/device-mgt-iot-digitaldisplay
components/device-mgt-iot-droneanalyzer
+ components/device-mgt-iot-virtualfirealarm
features/device-mgt-iot-feature
@@ -61,10 +62,11 @@
features/device-mgt-mdm-windows-feature
- features/device-mgt-iot-virtualfirealarm-feature
- features/device-mgt-iot-digitaldisplay-feature
features/device-mgt-iot-androidsense-feature
+ features/device-mgt-iot-arduino-feature
+ features/device-mgt-iot-digitaldisplay-feature
features/device-mgt-iot-droneanalyzer-feature
+ features/device-mgt-iot-virtualfirealarm-feature
@@ -361,91 +363,97 @@
-
+
org.wso2.carbon.devicemgt-plugins
- org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl
+ org.wso2.carbon.device.mgt.iot.androidsense
${carbon.iot.device.mgt.version}
-
org.wso2.carbon.devicemgt-plugins
- org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl
+ org.wso2.carbon.device.mgt.iot.androidsense.api
${carbon.iot.device.mgt.version}
war
+
+
+
org.wso2.carbon.devicemgt-plugins
- org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl
+ org.wso2.carbon.device.mgt.iot.arduino.plugin.impl
${carbon.iot.device.mgt.version}
-
org.wso2.carbon.devicemgt-plugins
- org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl
+ org.wso2.carbon.device.mgt.iot.arduino.service.impl
${carbon.iot.device.mgt.version}
+ war
-
-
-
+
org.wso2.carbon.devicemgt-plugins
- org.wso2.carbon.device.mgt.iot.androidsense
+ org.wso2.carbon.device.mgt.iot.digitaldisplay
${carbon.iot.device.mgt.version}
org.wso2.carbon.devicemgt-plugins
- org.wso2.carbon.device.mgt.iot.androidsense.api
+ org.wso2.carbon.device.mgt.iot.digitaldisplay.api
${carbon.iot.device.mgt.version}
war
-
+
org.wso2.carbon.devicemgt-plugins
- org.wso2.carbon.device.mgt.iot.digitaldisplay
+ org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.impl
${carbon.iot.device.mgt.version}
+
org.wso2.carbon.devicemgt-plugins
- org.wso2.carbon.device.mgt.iot.digitaldisplay.api
+ org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl
${carbon.iot.device.mgt.version}
+ war
-
+
+
+
+
org.wso2.carbon.devicemgt-plugins
- org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.impl
+ org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl
${carbon.iot.device.mgt.version}
org.wso2.carbon.devicemgt-plugins
- org.wso2.carbon.device.mgt.iot.droneanalyzer.service.impl
+ org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl
${carbon.iot.device.mgt.version}
war
-
+
+ org.wso2.carbon.devicemgt-plugins
+ org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl
+ ${carbon.iot.device.mgt.version}
+
-
-
-
org.wso2.carbon.devicemgt-plugins
- org.wso2.carbon.device.mgt.iot.digitaldisplay
+ org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl
${carbon.iot.device.mgt.version}
- provided
+
org.json.wso2
json