diff --git a/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/Adafruit_Python_DHT.zip b/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/Adafruit_Python_DHT.zip new file mode 100644 index 000000000..bff9920cf Binary files /dev/null and b/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/Adafruit_Python_DHT.zip differ diff --git a/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/RaspberryService.sh b/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/RaspberryService.sh index e32907e54..114226790 100644 --- a/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/RaspberryService.sh +++ b/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/RaspberryService.sh @@ -1,23 +1,3 @@ -#""" -#/** -#* 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. -#**/ -#""" - #!/bin/sh ### BEGIN INIT INFO @@ -35,7 +15,7 @@ DESC="This service is used to publish events from the Raspberry Pi to the WSO2 D NAME=RaspberryStats DIR=/usr/local/src/RaspberryAgent/src/ -DAEMON=$DIR/RaspberryAgent.py +DAEMON=python $DIR/RaspberryAgent.py DAEMON_NAME=$NAME SCRIPTNAME=RaspberryService.sh diff --git a/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/RaspberryAgent.py b/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/RaspberryAgent.py index 7b4afed5b..759a0b6c9 100644 --- a/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/RaspberryAgent.py +++ b/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/RaspberryAgent.py @@ -23,6 +23,7 @@ import logging, logging.handlers import sys, os, signal, argparse import running_mode import time, threading, datetime, calendar +import iotUtils, mqttConnector, Adafruit_DHT, httpServer # import httplib, ssl # from functools import wraps @@ -40,7 +41,7 @@ import time, threading, datetime, calendar # return bar # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -PUSH_INTERVAL = 5000 # time interval between successive data pushes in seconds +PUSH_INTERVAL = 2 # time interval between successive data pushes in seconds # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -82,7 +83,7 @@ if args.mode: running_mode.RUNNING_MODE = args.mode iotUtils = __import__('iotUtils') mqttConnector = __import__('mqttConnector') - # httpServer = __import__('httpServer') # python script used to start a http-server to listen for operations + httpServer = __import__('httpServer') # python script used to start a http-server to listen for operations # (includes the TEMPERATURE global variable) if running_mode.RUNNING_MODE == 'N': @@ -329,6 +330,7 @@ def main(): # ListenHTTPServerThread() # starts an HTTP Server that listens for operational commands to switch ON/OFF Led SubscribeToMQTTQueue() # connects and subscribes to an MQTT Queue that receives MQTT commands from the server TemperatureReaderThread() # initiates and runs the thread to continuously read temperature from DHT Sensor + # time.sleep(2) #wait for agent to connect to broker before publishing data while True: try: if iotUtils.LAST_TEMP > 0: # Push data only if there had been a successful temperature read diff --git a/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/mqttConnector.py b/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/mqttConnector.py index f0da9154c..ccfa6b067 100644 --- a/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/mqttConnector.py +++ b/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/src/mqttConnector.py @@ -72,9 +72,11 @@ def on_publish(client, userdata, mid): # The callback for when a PUBLISH message to the server when door is open or close # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def publish(msg): -# global mqttClient + global mqttClient mqttClient.publish(TOPIC_TO_PUBLISH, msg) +def on_subscribe(client, userdata, mid, granted_qos): + print "Successfully subscribed to " + TOPIC_TO_SUBSCRIBE # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # The Main method of the server script @@ -103,6 +105,7 @@ def main(): mqttClient.on_connect = on_connect mqttClient.on_message = on_message mqttClient.on_publish = on_publish + mqttClient.on_subscribe = on_subscribe mqttClient.username_pw_set(iotUtils.AUTH_TOKEN, password = "") while True: diff --git a/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/startService.sh b/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/startService.sh index e073b1092..4ccf64e01 100644 --- a/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/startService.sh +++ b/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.feature/src/main/resources/agent/startService.sh @@ -33,6 +33,17 @@ if [ ! -d "$destination" ] then mkdir $destination fi +# installing dependencies +echo ===Installing Dependencies +sudo apt-get update +sudo apt-get install python-pip +sudo pip install paho-mqtt + +#installing ada +sudo apt-get install build-essential python-dev +unzip Adafruit_Python_DHT +sudo python Adafruit_Python_DHT/setup.py install + sudo cp $currentDir/deviceConfig.properties $currentDir/src sudo cp -r $currentDir/src $destination sudo chmod +x $destination/src/RaspberryAgent.py