diff --git a/components/device-mgt-iot-raspberrypi/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/pom.xml b/components/device-mgt-iot-raspberrypi/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/pom.xml
index 861718e9be..3e778e17f0 100644
--- a/components/device-mgt-iot-raspberrypi/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/pom.xml
+++ b/components/device-mgt-iot-raspberrypi/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/pom.xml
@@ -84,7 +84,6 @@
org.apache.httpcomponents
httpasyncclient
4.1
- provided
org.wso2.carbon.devicemgt-plugins
diff --git a/components/device-mgt-iot-raspberrypi/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/RaspberryPiService.java b/components/device-mgt-iot-raspberrypi/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/RaspberryPiService.java
index 61e077a6b9..756b9a2c36 100644
--- a/components/device-mgt-iot-raspberrypi/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/RaspberryPiService.java
+++ b/components/device-mgt-iot-raspberrypi/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/RaspberryPiService.java
@@ -88,8 +88,7 @@ public class RaspberryPiService {
public void setRaspberryPiMQTTSubscriber(
final RaspberryPiMQTTSubscriber raspberryPiMQTTSubscriber) {
this.raspberryPiMQTTSubscriber = raspberryPiMQTTSubscriber;
-
- if (MqttConfig.getInstance().isEnabled()) {
+ /*if (MqttConfig.getInstance().isEnabled()) {
Runnable xmppStarter = new Runnable() {
@Override
public void run() {
@@ -102,8 +101,8 @@ public class RaspberryPiService {
xmppStarterThread.setDaemon(true);
xmppStarterThread.start();
} else {
- log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmMQTTConnector not started.");
- }
+ log.warn("MQTT disabled in 'devicemgt-config.xml");
+ }*/
}
/**
@@ -193,26 +192,14 @@ public class RaspberryPiService {
}
try {
- switch (protocolString) {
- case HTTP_PROTOCOL:
- String deviceHTTPEndpoint = deviceToIpMap.get(deviceId);
- if (deviceHTTPEndpoint == null) {
- response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode());
- return;
- }
-
- RaspberrypiServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint, callUrlPattern, true);
- break;
-
- case MQTT_PROTOCOL:
- String mqttMessage = RaspberrypiConstants.BULB_CONTEXT.replace("/", "");
- RaspberrypiServiceUtils.sendCommandViaMQTT(owner, deviceId, mqttMessage, switchToState);
- break;
-
- default:
- response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
- return;
+
+ String deviceHTTPEndpoint = deviceToIpMap.get(deviceId);
+ if (deviceHTTPEndpoint == null) {
+ response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode());
+ return;
}
+
+ RaspberrypiServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint, callUrlPattern, true);
} catch (DeviceManagementException e) {
log.error("Failed to send switch-bulb request to device [" + deviceId + "] via " + protocolString);
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
@@ -261,29 +248,18 @@ public class RaspberryPiService {
}
try {
- switch (protocolString) {
- case HTTP_PROTOCOL:
- String deviceHTTPEndpoint = deviceToIpMap.get(deviceId);
- if (deviceHTTPEndpoint == null) {
- response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode());
- }
-
- String temperatureValue = RaspberrypiServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint,
- RaspberrypiConstants
- .TEMPERATURE_CONTEXT,
- false);
- SensorDataManager.getInstance().setSensorRecord(deviceId, RaspberrypiConstants.SENSOR_TEMPERATURE,
- temperatureValue,
- Calendar.getInstance().getTimeInMillis());
- break;
-
- case MQTT_PROTOCOL:
- String mqttMessage = RaspberrypiConstants.BULB_CONTEXT.replace("/", "");
- RaspberrypiServiceUtils.sendCommandViaMQTT(owner, deviceId, mqttMessage, "");
- break;
- default:
- response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
+ String deviceHTTPEndpoint = deviceToIpMap.get(deviceId);
+ if (deviceHTTPEndpoint == null) {
+ response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode());
}
+
+ String temperatureValue = RaspberrypiServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint,
+ RaspberrypiConstants
+ .TEMPERATURE_CONTEXT,
+ false);
+ SensorDataManager.getInstance().setSensorRecord(deviceId, RaspberrypiConstants.SENSOR_TEMPERATURE,
+ temperatureValue,
+ Calendar.getInstance().getTimeInMillis());
sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId,
RaspberrypiConstants.SENSOR_TEMPERATURE);
} catch (DeviceManagementException | DeviceControllerException e) {
diff --git a/components/device-mgt-iot-raspberrypi/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/util/RaspberrypiServiceUtils.java b/components/device-mgt-iot-raspberrypi/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/util/RaspberrypiServiceUtils.java
index 56fe46dabb..61bbfc02f3 100644
--- a/components/device-mgt-iot-raspberrypi/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/util/RaspberrypiServiceUtils.java
+++ b/components/device-mgt-iot-raspberrypi/org.wso2.carbon.device.mgt.iot.raspberrypi.controller.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/raspberrypi/service/util/RaspberrypiServiceUtils.java
@@ -126,7 +126,7 @@ public class RaspberrypiServiceUtils {
}
- public static boolean sendCommandViaMQTT(String deviceOwner, String deviceId, String resource,
+ /*public static boolean sendCommandViaMQTT(String deviceOwner, String deviceId, String resource,
String state) throws DeviceManagementException {
boolean result;
@@ -140,7 +140,7 @@ public class RaspberrypiServiceUtils {
throw new DeviceManagementException(errorMsg, e);
}
return result;
- }
+ }*/
/* ---------------------------------------------------------------------------------------
Utility methods relevant to creating and sending http requests
diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/README.md b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/README.md
index b62a8bfc76..bd47154704 100644
--- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/README.md
+++ b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/README.md
@@ -17,6 +17,10 @@
--------------
This script is used to run this service in a testing environment. It can be run on a real Raspberry Pi device or in a
virtual environment.
+If this runs on a real Raspberry Pi device, you need to install Adafruit Python DHT Sensor Library and RPi.GPIO Python Library.To install Adafruit Python DHT Sensor Library, follow the
+instructions given here https://github.com/adafruit/Adafruit_Python_DHT.
+To install RPi.GPIO Python Library, sudo apt-get install rpi.gpio
+
To run: sudo ./testAgent.sh and follow the instructions.
-------------------
@@ -32,3 +36,10 @@ DAEMON_OPTS="-l /usr/local/src/RaspberryAgent/RaspberryStats.log -m N -i 56"
-l ----> file to write log
-i ----> time interval between successive data pushes to the wso2 IoT Server
-m ----> weather is going to run on the real device or not
+
+start service:
+ service /etc/init.d/RaspberryService.sh start
+
+stop service:
+ service /etc/init.d/RaspberryService.sh stop
+
diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/RaspberryService.sh b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/RaspberryService.sh
index c4b1d82f71..7473ae0e7d 100644
--- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/RaspberryService.sh
+++ b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/RaspberryService.sh
@@ -44,7 +44,7 @@ SCRIPTNAME=RaspberryService.sh
PIDFILE=/var/run/$DAEMON_NAME.pid
# Add any command line options for your daemon here
-DAEMON_OPTS="-l /usr/local/src/RaspberryAgent/RaspberryStats.log -m N -i 56"
+DAEMON_OPTS="-l /usr/local/src/RaspberryAgent/RaspberryStats.log -m N -i 60"
# This next line determines what user the script runs as.
# Root generally not recommended but necessary if you are using the Raspberry Pi GPIO from Python.
diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/Adafruit_Python_DHT.zip b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/Adafruit_Python_DHT.zip
deleted file mode 100644
index 889117c3f7..0000000000
Binary files a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/Adafruit_Python_DHT.zip and /dev/null differ
diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/GuideToPi b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/GuideToPi
deleted file mode 100644
index 9c23d9eea6..0000000000
--- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/GuideToPi
+++ /dev/null
@@ -1,17 +0,0 @@
-Install Rpi.GPIO
-Install sh
- sudo easy_install pip
- sudo pip install sh
-
-
-wget http://67.192.60.197/mikem/bcm2835/bcm2835-1.8.tar.gz
-tar xvfz bcm2835-1.8.tar.gz;
-cd bcm2835-1.8;
-./configure;
-make;
-sudo make install
-
-sudo apt-get update
-sudo apt-get install python-dev
-
-nohup command >/dev/null 2>&1 &
\ No newline at end of file
diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/RaspberryAgent.py b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/RaspberryAgent.py
old mode 100755
new mode 100644
index d17e5ceb79..793aa42d8b
--- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/RaspberryAgent.py
+++ b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/RaspberryAgent.py
@@ -51,6 +51,13 @@ logging_enabled = False
LOG_LEVEL = logging.INFO # Could be e.g. "DEBUG" or "WARNING"
### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# Python version
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+if sys.version_info<(2,7,5):
+ sys.stderr.write("You need python 2.7.5 or later to run this script\n")
+ exit(1)
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Define and parse command line arguments
diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/getMac.sh b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/getMac.sh
deleted file mode 100644
index 0b35872df2..0000000000
--- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/getMac.sh
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/sh
-
-"""
-/**
-* 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.
-**/
-"""
-
-piMac=`/sbin/ifconfig | grep 'wlan0' | tr -s ' ' | cut -d ' ' -f5 | tr -d ':'`
-echo The device ID is $piMac
diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/httpServer.pyc b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/httpServer.pyc
deleted file mode 100644
index 3d8918bcc8..0000000000
Binary files a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/httpServer.pyc and /dev/null differ
diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/iotUtils.py b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/iotUtils.py
index b5bdc9b179..fa05965b13 100644
--- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/iotUtils.py
+++ b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/iotUtils.py
@@ -123,7 +123,11 @@ def getDeviceIP():
print "IOT_UTILS: IP Addresses of RaspberryPi: " + str(rPi_IP)
print "IOT_UTILS: IP Address used for HTTP Server: " + rPi_IP[0]
print "------------------------------------------------------------------------------------"
- return rPi_IP[0]
+ if len(rPi_IP[0].split(":"))>1:
+ return rPi_IP[0].split(":")[1]
+ else:
+ return rPi_IP[0]
+
# for windows systems
else:
from subprocess import check_output
diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/iotUtils.pyc b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/iotUtils.pyc
deleted file mode 100644
index 4a9ef3ac7e..0000000000
Binary files a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/iotUtils.pyc and /dev/null differ
diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/org.eclipse.paho.mqtt.python.tar b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/org.eclipse.paho.mqtt.python.tar
deleted file mode 100644
index 5f65105b8f..0000000000
Binary files a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/org.eclipse.paho.mqtt.python.tar and /dev/null differ
diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/running_mode.pyc b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/running_mode.pyc
deleted file mode 100644
index fb6fa37c2c..0000000000
Binary files a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/running_mode.pyc and /dev/null differ
diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/startService.sh b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/startService.sh
index c964ec26fc..7e236beb2c 100644
--- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/startService.sh
+++ b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/startService.sh
@@ -33,3 +33,4 @@ sudo update-rc.d -f RaspberryService.sh remove
sudo cp $currentDir/RaspberryService.sh /etc/init.d
sudo chmod +x /etc/init.d/RaspberryService.sh
sudo update-rc.d RaspberryService.sh defaults
+sudo service /etc/init.d/RaspberryService.sh start
diff --git a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/testAgent.sh b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/testAgent.sh
old mode 100755
new mode 100644
index c3470b517a..4fab6da8db
--- a/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/testAgent.sh
+++ b/features/device-mgt-iot-raspberrypi-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/testAgent.sh
@@ -95,6 +95,11 @@ while true; do
esac
done
cp deviceConfig.properties ./src
+
+if [ $mode -eq "N" ]; then
+ sudo apt-get install rpi.gpio
+fi
+
chmod +x ./src/RaspberryAgent.py
./src/RaspberryAgent.py -i $input -m $mode