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..8873cac84 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 @@ -59,6 +39,7 @@ DAEMON_USER=root #pi do_start () { log_daemon_msg "Starting system $DAEMON_NAME daemon" start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --user $DAEMON_USER --chuid $DAEMON_USER --startas $DAEMON -- $DAEMON_OPTS + python $DAEMON & log_end_msg $? } do_stop () { 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..5ab04be85 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 @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin python """ /** * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. @@ -23,6 +23,8 @@ import logging, logging.handlers import sys, os, signal, argparse import running_mode import time, threading, datetime, calendar +import iotUtils, mqttConnector, httpServer +import Adafruit_DHT # import httplib, ssl # from functools import wraps @@ -40,7 +42,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 +84,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 +331,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..f85bc7a98 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,11 +33,22 @@ 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 +sudo chmod 755 $destination/src/RaspberryAgent.py 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 chmod 755 /etc/init.d/RaspberryService.sh sudo update-rc.d RaspberryService.sh defaults sudo service RaspberryService.sh start