removed mqtt dependencies

GPrathap 9 years ago
parent a7ee8c6b24
commit 69110859f2

@ -84,7 +84,6 @@
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
<version>4.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>

@ -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) {

@ -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

@ -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

@ -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.

@ -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 &

@ -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

@ -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

@ -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

@ -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

@ -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

Loading…
Cancel
Save