Merge pull request #584 from madhawap/3.1.0-test

Adding Raspberry Pi fixes from master to 3.1.0-test
revert-dabc3590
Kamidu Sachith Punchihewa 8 years ago committed by GitHub
commit a4ac88ef58

@ -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 #!/bin/sh
### BEGIN INIT INFO ### BEGIN INIT INFO
@ -59,6 +39,7 @@ DAEMON_USER=root #pi
do_start () { do_start () {
log_daemon_msg "Starting system $DAEMON_NAME daemon" 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 start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --user $DAEMON_USER --chuid $DAEMON_USER --startas $DAEMON -- $DAEMON_OPTS
python $DAEMON &
log_end_msg $? log_end_msg $?
} }
do_stop () { do_stop () {

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin python
""" """
/** /**
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * 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 sys, os, signal, argparse
import running_mode import running_mode
import time, threading, datetime, calendar import time, threading, datetime, calendar
import iotUtils, mqttConnector, httpServer
import Adafruit_DHT
# import httplib, ssl # import httplib, ssl
# from functools import wraps # from functools import wraps
@ -40,7 +42,7 @@ import time, threading, datetime, calendar
# return bar # 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 running_mode.RUNNING_MODE = args.mode
iotUtils = __import__('iotUtils') iotUtils = __import__('iotUtils')
mqttConnector = __import__('mqttConnector') 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) # (includes the TEMPERATURE global variable)
if running_mode.RUNNING_MODE == 'N': 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 # 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 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 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: while True:
try: try:
if iotUtils.LAST_TEMP > 0: # Push data only if there had been a successful temperature read if iotUtils.LAST_TEMP > 0: # Push data only if there had been a successful temperature read

@ -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 # The callback for when a PUBLISH message to the server when door is open or close
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def publish(msg): def publish(msg):
# global mqttClient global mqttClient
mqttClient.publish(TOPIC_TO_PUBLISH, msg) 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 # The Main method of the server script
@ -103,6 +105,7 @@ def main():
mqttClient.on_connect = on_connect mqttClient.on_connect = on_connect
mqttClient.on_message = on_message mqttClient.on_message = on_message
mqttClient.on_publish = on_publish mqttClient.on_publish = on_publish
mqttClient.on_subscribe = on_subscribe
mqttClient.username_pw_set(iotUtils.AUTH_TOKEN, password = "") mqttClient.username_pw_set(iotUtils.AUTH_TOKEN, password = "")
while True: while True:

@ -33,11 +33,22 @@ if [ ! -d "$destination" ]
then then
mkdir $destination mkdir $destination
fi 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 $currentDir/deviceConfig.properties $currentDir/src
sudo cp -r $currentDir/src $destination 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 update-rc.d -f RaspberryService.sh remove
sudo cp $currentDir/RaspberryService.sh /etc/init.d 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 update-rc.d RaspberryService.sh defaults
sudo service RaspberryService.sh start sudo service RaspberryService.sh start

Loading…
Cancel
Save