Exemplo n.º 1
0
class TempSensorAdaptor(Thread):

    #creating the sensor data object and initial values to use inside Adaptor
    sensorData = SensorData.SensorData()
    actuator = ActuatorData.ActuatorData()
    connector = SmtpClientConnector.SmtpClientConnector()
    actuatorEmulator = TempActuatorEmulator.TempActuatorEmulator()
    isPrevTempSet = False
    lowVal = 0
    highVal = 30
    nominalTemp = 20
    alertDiff = 5

    #initiating the thread for the Adaptor
    def __init__(self):
        Thread.__init__(self)

    def run(self):
        while True:
            if self.enableAdaptor:
                #generate temperature information
                self.curTemp = uniform(float(self.lowVal), float(self.highVal))
                self.sensorData.addValue(self.curTemp)
                print('\n--------------------')
                print('New sensor readings:')
                print(' ' + str(self.sensorData))

                if self.isPrevTempSet == False:
                    self.prevTemp = self.curTemp
                    self.isPrevTempSet = True
                else:
                    #checking for alerting difference and sending the message through SMTP
                    if (abs(self.curTemp - self.sensorData.getAvgValue()) >=
                            self.alertDiff):
                        print('\n Current temp exceeds average by > ' +
                              str(self.alertDiff) + '. Triggering alert...')
                        self.connector.publishMessage(
                            'Exceptional sensor data [test]', self.sensorData)
                '''
                checking to see if the temperature exceeds nominal temperature to set status
                for actuator and send the message accordingly
                '''
                if (self.curTemp > self.nominalTemp):

                    self.actuator.setCommand(ActuatorData.COMMAND_ON)
                    self.actuator.setStatusCode(ActuatorData.STATUS_ACTIVE)
                    self.actuator.setErrorCode(ActuatorData.ERROR_OK)
                    self.actuator.setStateData('Decrease')
                    self.actuator.setValue(self.curTemp - self.nominalTemp)
                    self.actuatorEmulator.processMessage(self.actuator)

                elif (self.curTemp < self.nominalTemp):

                    self.actuator.setCommand(ActuatorData.COMMAND_OFF)
                    self.actuator.setStatusCode(ActuatorData.STATUS_ACTIVE)
                    self.actuator.setErrorCode(ActuatorData.ERROR_OK)
                    self.actuator.setStatusCode('Increase')
                    self.actuator.setValue(self.curTemp - self.nominalTemp)
                    self.actuatorEmulator.processMessage(self.actuator)
            sleep(5)
Exemplo n.º 2
0
    def __init__(self, name):

        Thread.__init__(self)
        self.enableAdaptor = True
        self.sensor = SensorData.SensorData(name, 0, 30)
        self.temp = ConfigUtil.ConfigUtil(
            '../../../config/ConnectedDevicesConfig.props')
        self.tempEmulator = TempActuatorEmulator.TempActuatorEmulator()
Exemplo n.º 3
0
 def __init__(self, name):
     Thread.__init__(self)
     self.enableAdaptor = True;
     self.sensorData = SensorData.SensorData(name, 0, 30);
     self.actuator = ActuatorData.ActuatorData()
     self.connector = SmtpClientConnector.SmtpClientConnector()
     self.tempConf = ConfigUtil.ConfigUtil('../../../config/ConnectedDevicesConfig.props'); 
     self.actuatorEmulator = TempActuatorEmulator.TempActuatorEmulator();
 def __init__(self, name):
     '''
      _init_() is called during object initialization.
     '''
     Thread.__init__(self)
     self.enableEmulator = True
     # flag to enable emulator function
     self.sensor = SensorData.SensorData(name, 0, 30)
     # creating a sensor data object
     self.temp = ConfigUtil.ConfigUtil(
         '../../../config/ConnectedDevicesConfig.props')
     self.temp_emul = TempActuatorEmulator.TempActuatorEmulator()
     '''
 def __init__(self, name):
     '''
     This thread generates a random float variable(Current Value). 
     If the current value is greater than given threshold notification is generated.
     Creating a sensor data object.
     This Constructor is initialized in __init__; and setting enableEmulator flag to true.
     Assigning the sensor minimum temperature value = 0 and maximum value = 30.
     '''
     Thread.__init__(self)
     self.enableAdaptor = True
     self.sensor = SensorData.SensorData(name, 0, 30)
     self.temp = ConfigUtil.ConfigUtil(
         '../../../config/ConnectedDevicesConfig.props')
     self.tempEmulator = TempActuatorEmulator.TempActuatorEmulator()
 def __init__(self, name):
     '''
 Constructor
 Creates object of SensorData, ConfiUtil and TempActuatorEmulator
 This class is used to send notification through mail 
 and initiate an action to control the temperature 
     '''
     Thread.__init__(self)
     self.enableEmulator = True
     # flag to enable emulator function
     self.sensor = SensorData.SensorData(name, 0, 30)
     # creating a sensor data object
     self.temp = ConfigUtil.ConfigUtil(
         '../../../config/ConnectedDevicesConfig.props')
     self.temp_emul = TempActuatorEmulator.TempActuatorEmulator()
     '''
Exemplo n.º 7
0
class TempSensorAdaptor(threading.Thread):
    sensorData = SensorData.SensorData()
    actuatorData = ActuatorData.ActuatorData()
    connector = SmtpClientConnector.SmtpClientConnector()
    actu = TempActuatorEmulator.TempActuatorEmulator()
    enableEmulator = False
    isPrevTempSet = False
    rateInSec = DEFAULT_RATE_IN_SEC
    sensorData.setName('Temperature')

    lowVal = 0
    highVal = 30
    alertDiff = 5

    def __init__(self, rateInSec=DEFAULT_RATE_IN_SEC):
        super(TempSensorAdaptor, self).__init__()

        if rateInSec > 0:
            self.rateInSec = rateInSec

    def run(self):
        while True:
            if self.enableEmulator:
                self.curTemp = uniform(float(self.lowVal), float(self.highVal))
                self.sensorData.addValue(self.curTemp)
                self.actuatorData.setValue(self.curTemp)
                self.actu.processMessage(self.actuatorData)
                print('\n--------------------')
                print('New sensor readings:')
                print('  ' + str(self.sensorData))
                if self.isPrevTempSet == False:
                    self.prevTemp = self.curTemp
                    self.isPrevTempSet = True
                else:
                    if (abs(self.curTemp - self.sensorData.getAvgValue()) >=
                            self.alertDiff):
                        print('\n  Current temp exceeds average by > ' +
                              str(self.alertDiff) + '. Triggeringalert...')
                        self.connector.publishMessage(
                            'Exceptional sensor data [test]', self.sensorData)
            sleep(self.rateInSec)
Exemplo n.º 8
0
'''
Created on Oct 08, 2018

@author: stannis
'''
import os,sys
sys.path.append('/home/pi/Desktop/zexin/iot-device/apps')
from labs.module03 import TempSensorAdaptor
from labs.module03 import TempActuatorEmulator
from labs.module03 import MQTTClient
from labs.common import ActuatorData
from time import sleep
from builtins import int
from sense_hat import SenseHat


path = "/Users/stannis/eclipse-workspace2/iot-device/data/ConnectedDeviceConfig.props"

tempSensor = TempSensorAdaptor.TempSensorAdaptor(3)
tempSensor.enableEmulator = True
tempActuatorData = ActuatorData.ActuatorData()
tempActuatorEmulator = TempActuatorEmulator.TempActuatorEmulator();
tempSensor.start()
val = 0
senseHat = SenseHat()
client = MQTTClient.MQTTClient()
client.go()

Exemplo n.º 9
0
from labs.common import ConfigConst
from labs.common import ConfigUtil
from labs.common import ActuatorData
from labs.common import SensorData
from labs.module03 import SmtpClientConnector
from labs.module03 import TempActuatorEmulator
from labs.module03 import SimpleLedActivator
from labs.module03 import CoapSimpleClientConnector

from sense_hat import SenseHat
from time import sleep

DEFAULT_RATE_IN_SEC = 10

sen = SenseHat()
Tem = TempActuatorEmulator.TempActuatoeEmulator()
Sens = SensorData.SensorData()
SmtpConnector = SmtpClientConnector.SmtpClientConnector()
Act = ActuatorData.ActuatorData()
Sim = SimpleLedActivator.SimpleLedActivator()
coapConnector = CoapSimpleClientConnector.CoapSimpleClientConnector()


class TempSensorAdaptor(threading.Thread):
    enableEmulator = False
    isPrevTempSet = False
    rateInSec = DEFAULT_RATE_IN_SEC
    Sens.setName('Temperature')
    alertDiff = 2
    alertDiffb = 0
Exemplo n.º 10
0
#import sys
#sys.path.append('/home/pi/workspace/iot-device/apps')

import random
from time import sleep
import threading
from labs.common import SensorData
from labs.common import ActuatorData

from labs.module03 import SmtpClientConnector
from labs.module03 import TempActuatorEmulator

DEFAULT_RATE_IN_SEC = 15

TempAcEmu = TempActuatorEmulator.TempActuatorEmulator()
Sens = SensorData.SensorData()
ActD = ActuatorData.ActuatorData()
SmtpConnector = SmtpClientConnector.SmtpClientConnector()


class TempSensorAdaptor(threading.Thread):
    enableEmulator = False
    isPrevTempSet = False
    rateInSec = DEFAULT_RATE_IN_SEC
    Sens.setName('Temperature')

    lowVal = 0
    highVal = 30
    alertDiff = 15