Bug fixes on Raspberry Pi agent

merge-requests/1/head
savi_wso2 8 years ago
parent c761324460
commit 16f6bda20a

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

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

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

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

Loading…
Cancel
Save