|
|
@ -23,6 +23,7 @@ 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, Adafruit_DHT, httpServer
|
|
|
|
|
|
|
|
|
|
|
|
# import httplib, ssl
|
|
|
|
# import httplib, ssl
|
|
|
|
# from functools import wraps
|
|
|
|
# from functools import wraps
|
|
|
@ -40,7 +41,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 +83,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 +330,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
|
|
|
|