class HumiditySensorAdaptorTask(threading.Thread): rateInSec = 10 curHumid = 0 sensorData = SensorData() sense = SenseHat() manager = SensorDataManager() i2cHumid = HI2CSensorAdaptorTask() enableHumidSensor = False ''' Read the Humidity data from the SenseHAT ''' def __init__(self, rateInSec=10): threading.Thread.__init__(self) self.rateInSec = rateInSec self.time = self.sensorData.timeStamp def getHumidity(self): self.curHumid = self.sense.get_humidity() return self.curHumid def run(self): while True: if self.enableHumidSensor: self.sensorData.setName("Humid") self.sensorData.addValue(self.getHumidity()) #print(str(datetime.now()) + "SenseHat API Humidity " + str(self.curHumid)) #print(str(datetime.now()) + "I2C Direct Humidity: " + str(self.i2cHumid.getHumidityData())) ##print(self.sensorData.curValue) self.manager.handleSensorData(self.sensorData) sleep(self.rateInSec)
class Module03Test(unittest.TestCase): confU=ConfigUtil(); sensorD=SensorData() hasConf=confU.hasConfig() curVal=sensorD.getCurrentValue() avgVal=sensorD.getAverageValue() actD=ActuatorData() senDM=SensorDataManager() """ it checks for the datatype of hasConf to be boolean, If true test case is passed. """ def testConfigUtil(self): self.assertTrue(isinstance(self.hasConf,bool),"Boolean Value") """ it checks for the datatype of curVal to be float, If true test case is passed. Second checks for the avgVal to be within the specified range.If true test case is passed. """ def testSensorData(self): self.assertTrue(isinstance(self.curVal,float),"Float Value") self.assertTrue(self.avgVal>=0.0 and self.avgVal<=30.0,"Average Temperature within the range") ''' It checks for the datatype of the getCommand function to be String. ''' def testActuatorData(self): self.assertTrue(isinstance(self.actD.getCommand(),str), "String") ''' It checks for the returntype of the function handleSensorData of class SensorDataManager to be of type actuator data. ''' def testSensorDataManager(self): self.assertTrue(isinstance(self.senDM.handleSensorData(self.sensorD),ActuatorData), "Type Actuator Data")
class TempSensorAdaptorTask(object): ''' The TempSensorAdaptorTask reads the temperature from the SenseHAT, creates a SensorData object using that value and returns it ''' #Initialize sense_hat sense = sense_hat.SenseHat() #Initialize SensorData sensorData = SensorData() #Set the name of the Sensor sensorData.setName("Temperature Sensor") #Empty constructor as we do not want to initialize anything during instantiation def __init__(self): ''' Constructor ''' """ Method to return the SensorData reference after getting the temperature from SenseHAT API """ def getTemperature(self): #Get the temperature and add it to SensorData self.sensorData.addValue(self.sense.get_temperature()) #Return the SensorData reference return self.sensorData
class TempSensorAdaptorTask(threading.Thread): rateInSec = 10 curTemp = 0 sensorData = SensorData() sense = SenseHat() manager = SensorDataManager() enableTempSensor = False ''' Read the Temperature from the SenseHAT ''' def __init__(self, rateInSec=10): threading.Thread.__init__(self) self.rateInSec = rateInSec self.time = self.sensorData.timeStamp def getTemperature(self): self.curTemp = self.sense.get_temperature() return self.curTemp def run(self): while True: if self.enableTempSensor: self.sensorData.setName('Temp') self.sensorData.addValue(self.getTemperature()) #print(self.sensorData.curValue) self.manager.handleSensorData(self.sensorData) sleep(self.rateInSec)
class Module02Test(unittest.TestCase): smtp_object = smtpconnect() # Creating Instances of Classes Required data_object = SensorData() x = 0 def setUp(self): self.x = temperaturegen.getSensorData(self) self.data_object.addValue( self.x) # Passing Generated Values Into SensorData Classs def testgeneratedtemperature(self): self.assertTrue( temperaturegen.getSensorData(self) >= 0.0 and temperaturegen.getSensorData(self) <= 30.0, "Not in RANGE") self.assertTrue(isinstance(temperaturegen.getSensorData(self), int), "Its not a Integer ") # Checking Generated Temperature is float & within range def testPublishMessage(self): self.assertTrue(isinstance(self.smtp_object.getfromAddr(), str), "Its not a String ") # Test Case to check valid mail self.assertTrue(isinstance(self.smtp_object.gettoAddr(), str), "Its not a String ") self.assertTrue(isinstance(self.smtp_object.getmsgBody(), str), "Its not a String ") self.assertTrue(self.connect("https://www.google.com")) def connect(self, host): # Internet connectivity checker try: urllib.request.urlopen(host) return 1 except: return 0
class Module07Test(unittest.TestCase): sensorD = SensorData() #hasConf=confU.hasConfig() curVal = sensorD.getCurrentValue() avgVal = sensorD.getAverageValue() actD = ActuatorData() du = DataUtil() adl = ActuatorDataListener() j = "" def testSensorData(self): self.assertTrue(isinstance(self.curVal, float), "Float Value") self.assertTrue(self.avgVal >= 0.0 and self.avgVal <= 30.0, "Average Temperature within the range") ''' It checks for the datatype of the getCommand function to be String. ''' def testDataUtil(self): self.assertTrue( isinstance(self.du.toJsonFromSensorData(self.sensorD), str), "String") def testActuatorDataFromJson(self): self.assertTrue( isinstance(self.du.toActuatorDataFromJson(self.j), str), "String") def testActuatorDataListener(self): self.assertTrue( isinstance(self.adl.onActuatorMessage(str(self.curVal)), float), "Type String")
def testreadSensorValuePushNotification(self): self.tat.sensorData = SensorData() self.tat.sensorData.addValue(12) self.tat.sensorData.setName("Test") self.tat.sdm = SensorDataManager() self.assertTrue(self.tat.pushData(), "Message not getting pushed to Sensor Data Manager")
def testAddValue(self): testValue = 10.0 sensordata = SensorData() sensordata.addValue(testValue) sampleCount = sensordata.getSampleCount() assert sampleCount == 1 curValue = sensordata.getValue() assert curValue == testValue avgValue = sensordata.getAvgValue() assert avgValue == testValue minValue = sensordata.getMinValue() assert minValue == testValue maxValue = sensordata.getMaxValue() assert maxValue == testValue totValue = sensordata.getTotValue() assert totValue == testValue
class Mem(threading.Thread): ''' Class to create a threaded task to report the system CPU and memory usage using coAP ''' def __init__(self, coAPClient: CoAPClientConnector, intervalTime=20, looplimit=-1): ''' Constructor ''' #Get an event loop self.loop = asyncio.get_event_loop() self.looplimit = looplimit #Initialzing the threaded class threading.Thread.__init__(self, args=(self.loop, )) self.interval = intervalTime self.coAPClient = coAPClient #Initializing the sensorData instance self.hrSensorData = SensorData() def getRam(self): ''' Method to return percentage of system memory being used ''' i = 0 while True: i = i + 1 data = psutil.virtual_memory()[2] #Only adding the data to sensorData instance #if it's not None if data != None: self.hrSensorData.addValue(float(data)) self.hrSensorData.setName("Memory Usage") self.coAPClient.sendSensorDataPOST(self.loop, self.hrSensorData) sleep(self.interval) if self.looplimit != -1: if i == self.looplimit: break def run(self): self.getRam() return True
class HumiditySensorAdaptorTask(Thread): ''' Variables are defined and objects of required classes are created with the class scope. ''' sensorData = SensorData() #constructor of sensorData is created. #multiAct=MultiActuatorAdaptor() #constructor of TempActuatorAdaptor is created. sensorDataM = SensorDataManager( ) #constructor of SensorDataManager is created. avgValue = 0.0 count = 0.0 total = 0.0 currentValue = 0.0 maxValue = 0.0 minValue = 0.0 timestamp = None sh = SenseHat() def __init__(self, name): #constructor is initialized Thread.__init__(self) self.name = name ''' this run function overrides the run function of Thread and calls the sense hat function to generate the Humidity values,addValue fnctn of sensorData is called humidity of class sensorDataManager is called and sensorData object is passed as a parameter. This function will return the actuator data. ''' def run(self): #run method of thread is overriden # logging.basicConfig(level=logging.INFO,format='%(asctime)s:%(levelname)s:%(message)s') sh = SenseHat() mqtt_client = mqttClient.Client() while True: res = sh.get_humidity() print("this is humidity value...", res) self.sensorData.addValue(res) self.act_data = self.sensorDataM.humidity(self.sensorData) self.getSensorData() ubidots(mqtt_client, self.currentValue, "humidity") time.sleep(2) # if(self.act_data!=None): # self.multiAct.updateActuator(self.act_data) #calling of updateActuator # # logging.basicConfig(level=logging.INFO) # data="Humidity Sensor:\nTime: "+str(self.timestamp)+"\nCurrent: "+str(self.currentValue)+"\nAverage: "+str(self.avgValue)+"\nSamples: "+str(self.count)+"\nMin: "+str(self.minValue)+"\nMax: "+str(self.maxValue) # logging.info(data) # print("\n") # ''' This function fetches the values from sensorData and store it to the local variables of this class. ''' def getSensorData(self): self.avgValue = self.sensorData.getAverageValue() self.count = self.sensorData.getCount() self.total = self.sensorData.getTotal() self.currentValue = self.sensorData.getCurrentValue() self.maxValue = self.sensorData.getMaxValue() self.minValue = self.sensorData.getMinValue() self.timestamp = self.sensorData.getTimestamp()
def toSensorDataFromJson(self, string): act = SensorData() data = json.loads(string) logging.info(data) act.name = data['name'] act.reading_number = data['reading_number'] act.current = data['current'] act.min_value = data['min_value'] act.max_value = data['max_value'] act.total_value = data['total_value'] act.timestamp = data['timestamp'] logging.info("New actuator generated from JSon \n") return act
def __init__(self, coAPClient: CoAPClientConnector, intervalTime=20, looplimit=-1): ''' Constructor ''' #Get an asyncio loop self.loop = asyncio.get_event_loop() self.looplimit = looplimit #Initialzing the threaded class threading.Thread.__init__(self, args=(self.loop, )) self.interval = intervalTime self.coAPClient = coAPClient #Initializing the sensorData instance self.hrSensorData = SensorData()
def toSensorDataFromJson(self,jsonData): sdDict = json.loads(jsonData) print(" decode [pre] --> " + str(sdDict)) sd = SensorData() sd.name = sdDict['name'] sd.timeStamp = sdDict['timeStamp'] sd.avgValue = sdDict['avgValue'] sd.minValue = sdDict['minValue'] sd.maxValue = sdDict['maxValue'] sd.curValue = sdDict['curValue'] sd.totValue = sdDict['totValue'] sd.sampleCount = sdDict['sampleCount'] print(" decode [post] --> " + str(sd)) return sd
class HumiditySensorAdaptorTask: #Default Constructor def __init__(self): self.sensor = SenseHat() self.sensorData = SensorData() self.sdm = None #Method to implement lazy object initialization def objectLoader(self): self.sensorData.setName("HumiditySenseHat") #self.sdm = SensorDataManager.SensorDataManager() #Method for fetching the sensor value from senseHat module def readSensorValue(self): humidity = self.sensor.get_humidity() self.sensorData.addValue(humidity) return self.sensorData
class Module05Test(unittest.TestCase): """ Use this to setup your tests. This is where you may want to load configuration information (if needed), initialize class-scoped variables, create class-scoped instances of complex objects, initialize any requisite connections, etc. """ def setUp(self): self.ac = ActuatorData() self.ac.addValue(15) self.sensor = SensorData() self.sensor.addValue(15) self.hsa = HumiditySensorAdaptorTask() self.hsa.objectLoader() self.pu = PersistenceUtil() pass """ Use this to tear down any allocated resources after your tests are complete. This is where you may want to release connections, zero out any long-term data, etc. """ def tearDown(self): pass """ Place your comments describing the test here. """ def testSenseHatActivator(self): hat = SenseHatLedActivator() self.assertTrue(hat.updateLed("Test"),"Led Update Failed") pass def testSensorData(self): a = self.hsa.readSensorValue() self.assertGreaterEqual(a.current, 0, "Issue with sensor") pass def testWriteActuator(self): self.assertTrue(self.pu.writeActuatorToDataDbms(self.ac)) pass def testWriteSensor(self): self.assertTrue(self.pu.writeSensorToDataDbms(self.sensor)) pass
def render_POST_advanced(self, request, response): if (self.sensorData != None): response.code = defines.Codes.BAD_REQUEST.number response.payload = (defines.Content_types["text/plain"], "Object is already exist") else: jsonData = request.payload self.sensorData = SensorData(self.config) self.sensorData.fromJson( False, jsonData ) #Initialize a new SensorData object form the request payload response.code = defines.Codes.CREATED.number response.payload = (defines.Content_types["text/plain"], "Object is created successfully") return self, response
def __init__(self, coAPClient: CoAPClientConnector, intervalTime=2, looplimit=-1): ''' Constructor Sets the interval time and mqttClient creates a sensorData instace ''' self.loop = asyncio.get_event_loop() self.looplimit = looplimit #Initialzing the threaded class threading.Thread.__init__(self, args=(self.loop, )) self.interval = intervalTime self.coAPClient = coAPClient #Getting an instance of the shared resource self.dataStore = SensorResource.getInstance() #Initializing the sensorData instance self.hrSensorData = SensorData()
def toSensorfromJson(self, jsonData): sdDict = json.loads(jsonData) sd = SensorData('Temperature', 0, 30) sd.name = sdDict['name'] sd.timeStamp = sdDict['timeStamp'] sd.avgVal = sdDict['avgVal'] sd.minVal = sdDict['minVal'] sd.maxVal = sdDict['maxVal'] sd.curVal = sdDict['curVal'] return sd
class TempSensorAdaptorTask(threading.Thread): def __init__(self): self.data = SensorData() logging.basicConfig(format='%(asctime)s:%(levelname)s:%(message)s', level=logging.DEBUG) # logging basic data ''' get sensordata from senshat API''' def run(self): sensData = SenseHat() #instance of SenseHat sense = sensData.get_temperature( ) #calling method get_Temperature for SenseHat # self.data.setName('Temperature') self.data.addValue(sense) #updating values using addvalue method # print(self.data.getRecord()) #printing record logging.info("Temperature Value: " + str(self.data.getCurrentValue())) # json = "Temperature Value:"+ str(self.data.getCurrentValue()) data = self.data.getCurrentValue() return sense
class GasSensor(object): def __init__(self): self.sendata = SensorValueGenerator() self.data = SensorData() logging.basicConfig(format='%(asctime)s:%(levelname)s:%(message)s', level=logging.DEBUG) # logging basic data '''if(gasValue > 1000 | gasValue < 1500): print(" Healthy environment -- Enough CO2 for plants") if(gasValue > 2000): print("GAS ALERT!! Co2 exceeding in the air") else: print(" please increase the co2 value for good growth of plants!!!") ''' def gasSensorvalue(self): gasValue = self.sendata.GasEmulator() self.data.setName('gasValue') #setting sensor name with setName method self.data.getCurrentValue() return gasValue
def toSensorDataFromJson(self, jsonStr) -> SensorData: #instantiate SensorData sensorData = SensorData() #use json load to convert it to a dictionary jsonLoad = json.loads(jsonStr) #parse and add it to the sensorData object one by one sensorData.currentValue = jsonLoad["currentValue"] sensorData.average = jsonLoad["average"] sensorData.totalCount = jsonLoad["totalCount"] sensorData.minValue = jsonLoad["minValue"] sensorData.maxValue = jsonLoad["maxValue"] sensorData.totalValue = jsonLoad["totalValue"] sensorData.sensorName = jsonLoad["sensorName"] sensorData.timeStamp = jsonLoad["timestamp"] #return the SensorData reference return sensorData
class Module02Test(unittest.TestCase): """ class scoped variables and objects are created """ confU = ConfigUtil() sensorD = SensorData() tempSensor = TempSensorEmulatorTask() curVal = 0.0 avgVal = 0.0 hasConf = "" data = None ''' values are setup into the variables ''' def setUp(self): self.data = self.tempSensor.getSensorData() self.hasConf = self.confU.hasConfig() self.curVal = self.sensorD.getCurrentValue() self.avgVal = self.sensorD.getAverageValue() """ All the resources are tear down here. """ def tearDown(self): del self.data del self.hasConf del self.curVal del self.avgVal """ it checks for the datatype of hasConf to be boolean, If true test case is passed. """ def testConfigUtil(self): self.assertTrue(isinstance(self.hasConf, bool), "Boolean Value") """ it checks for the datatype of curVal to be float, If true test case is passed. Second checks for the avgVal to be within the specified range.If true test case is passed. """ def testSensorData(self): self.assertTrue(isinstance(self.curVal, float), "Float Value") self.assertTrue(self.avgVal >= 0.0 and self.avgVal <= 30.0, "Average Temperature within the range") ''' It checks for the datatype of data to be of class type SensorData, If true test case is passed. ''' def testTemperatureSensorEmulatorTask(self): self.assertTrue(isinstance(self.data, SensorData), "Sensor Data Type Value")
class TempSensorAdaptor(Thread): alertDiff = 5 curTemp = 0 max_value = 0 min_value = 0 enableTempEmulator = False maxUpdateTime = 0 minUpdatetime = 0 tempSensorData = SensorData("Temperature") emailSender = None isPrevTempSet = True rateInSec = 1 sh = None deviceConfigReader = None nominalTemp = 0 # constructor def __init__(self, max_temp, min_temp, max_updateTime, min_updateTime, configDir): Thread.__init__(self) self.max_value = max_temp self.min_value = min_temp self.maxUpdateTime = max_updateTime self.minUpdatetime = min_updateTime # get the data of device like: enableEmulator,nominalTemp... self.deviceConfigReader = ConfigUtil.ConfigUtil(configDir, "device") self.enableTempEmulator = self.deviceConfigReader.getProperty("enableEmulator") self.nominalTemp = self.deviceConfigReader.getProperty("nominalTemp") # if we chose sensehat, we should connect to sensehat part, dont add temperature by uniform function self.sh = sense_hat.SenseHat() def getCurrValue(self): return self.curTemp # TempSensorEmulator thread which gets newTemp around min / max updatetime(In this part we set the time is 1 sec) # thread to calculate the curVal . then send the data to MQtt broker if temperature different def run(self): while True: if self.enableTempEmulator == "True": if self.isPrevTempSet == False: # corner code self.prevTemp = self.curTemp self.isPrevTempSet = True else: self.curTemp = int(uniform(int(self.min_value), int(self.max_value))) self.tempSensorData.addNewValue(self.curTemp) else: print("using Sensor_Hat") self.curTemp = int(self.sh.get_temperature()) self.tempSensorData.addNewValue(self.curTemp) print('New sensor readings:') print(str(self.tempSensorData)) sleep(self.rateInSec)
class LuminanceSensor(threading.Thread): def __init__(self): self.data = SensorData() self.sendata = SensorValueGenerator() logging.basicConfig(format='%(asctime)s:%(levelname)s:%(message)s', level=logging.DEBUG) # logging basic data ''' if(Luminance < 589 and Luminance > 495): print("\n Intensity of green and yellow is good!!") elif(Luminance < 627 and Luminance > 589): print("\n Intensity of Orange is good for maximum Photosynthesis!!") elif(Luminance < 770 and Luminance > 627): print("\n Intensity enhancing flowering") else: print("\n Luminance is harmful !! plant will burn!!!") ''' def Luminance(self): Luminance = self.sendata.LuminanceEmulator() self.data.setName( 'luminance') #setting sensor name with setName method return Luminance
class MqttClientConnector(object): ''' classdocs ''' tempSensor = TempSensorAdaptorTask() sensorData = SensorData() dataUtil = DataUtil() client = mqtt.Client() def __init__(self): ''' Constructor ''' ''' Callback function ''' def _on_connect(self, client, userdata, flags, rc): print("Connected with result code " + str(rc)) def _on_disconnect(self, client, userdata, rc): print("Dissconnected with result code: " + str(rc)) def _on_message(self, client, userdata, msg): print(msg.topic + "" + str(msg.payload)) def getSensorData(self): temp = self.tempSensor.getTemperature() self.sensorData.addValue(temp) jsonData = self.dataUtil.toJsonFromSensorData(self.sensorData) return jsonData ''' Connect to remote mqtt broker:mqtt.eclipse.org publish msg ''' def run(self): self.client.on_connect = self._on_connect self.client.on_message = self._on_message self.client.on_disconnect = self._on_disconnect self.client.connect("mqtt.eclipse.org", 1883, 60) jsonData = self.getSensorData() logging.info("SensorData befor publishing: " + jsonData) self.client.loop_start() self.client.publish("kai_test1", jsonData, 2, True) self.client.loop_stop() self.client.disconnect()
class TempSensorEmulatorTask: sensorObj=SensorData() currentValue=0.0 total=0.0 count=0.0 minValue=0.0 maxValue=0.0 avgValue=0.0 threshold=5.0 timestamp=None ''' Email will be sent according to the difference in current and average temperature values logging info is also generated. ''' def sendNotification(self): if(abs(self.currentValue-self.avgValue)>self.threshold): smtpCCObject=SmtpClientConnector() smtpCCObject.connector() logging.basicConfig(level=logging.INFO,format='%(asctime)s:%(levelname)s:%(message)s') logging.info('\n Current temperature exceeds average by ' + str(round(abs(self.currentValue-self.avgValue),2)) + '. Triggering alert...') logging.basicConfig(level=logging.INFO) data="Temperature:\nTime: "+str(self.timestamp)+"\nCurrent: "+str(self.currentValue)+"\nAverage: "+str(self.avgValue)+"\nSamples: "+str(self.count)+"\nMin: "+str(self.minValue)+"\nMax: "+str(self.maxValue) logging.info(data) print("\n") ''' fetch data from SensorData class, hence create an object of that class and fetch the variables using getter functions. ''' def getSensorData(self): self.avgValue= self.sensorObj.getAverageValue(); self.count=self.sensorObj.getCount(); self.total=self.sensorObj.getTotal(); self.currentValue=self.sensorObj.getCurrentValue(); self.maxValue=self.sensorObj.getMaxValue(); self.minValue=self.sensorObj.getMinValue(); self.timestamp=self.sensorObj.getTimestamp(); return self.sensorObj ''' Random temperature value is generated and it is passed in the addValue function of SensorData class. After getting all the values sendNotification function is called and thread is sleep for 2 seconds. ''' def temperatureGenerator(self): for i in range(0,10): temperatureValue=random.uniform(0,30) self.sensorObj.addValue(temperatureValue) self.getSensorData() self.sendNotification() time.sleep(2)
def testWriteSensorDataToDbms(self): #Create ActuatorData instance sensorData = SensorData(); #write to redis and check if it returns true self.assertEqual(True, self.persistenceUtil.writeSensorDataToDbms(sensorData)); #add an invalid port to the jedisSensor self.persistenceUtil.r_sensor = Redis(host = "localhost", port = 6890) #write to redis and check if it returns false self.assertEqual(False, self.persistenceUtil.writeSensorDataToDbms(sensorData));
class TempSensorAdaptorTask: def run(self): i=0 while(i<11): self.readSensorValue() sleep(10) i+=1 #Default Constructor def __init__(self): self.sensor = SenseHat() self.sensorData = SensorData() #Method for fetching the sensor value from senseHat module def readSensorValue(self): temp = self.sensor.get_temperature() self.sensorData.addValue(temp) self.sdm = SensorDataManager.SensorDataManager() self.sdm.hadleSensorData(self.sensorData) return self.sensorData.current
def jsonToSensorData(self, jsonData): sdDict = json.loads(jsonData) #print(" decode [pre] --> " + str(sdDict)) sd = SensorData("Temperature Sensor", 0.0, 30.0) sd.name = sdDict['name'] sd.timeStamp = sdDict['time'] sd.avgValue = sdDict['avgValue'] sd.minValue = sdDict['minValue'] sd.maxValue = sdDict['maxValue'] sd.curValue = sdDict['curValue'] #print(" decode [post] --> " + str(sd)) return sd
class TempSensorEmulator(Thread): alertDiff = 5 curTemp = \ max_value = 0 min_value = 0 enableTempEmulator = False maxUpdateTime = 0 minUpdatetime = 0 tempSensorData = SensorData("Temperature") emailSender = None isPrevTempSet = False rateInSec = 5 # constructor which get 4 reference def __init__(self, max_temp, min_temp, max_updateTime, min_updateTime): Thread.__init__(self) self.max_value = max_temp self.min_value = min_temp self.maxUpdateTime = max_updateTime self.minUpdatetime = min_updateTime def getCurrValue(self): return self.curTemp # TempSensorEmulator thread which gets newTemp around min / max updatetime(In this part we set the time is 5 sec) # thread to calculate the curVal exceeds average than 5. def run(self): while True: if self.enableTempEmulator: if self.isPrevTempSet == False: # corner code self.prevTemp = self.curTemp self.isPrevTempSet = True else: self.curTemp = uniform(float(self.min_value), float(self.max_value)) self.tempSensorData.addNewValue(self.curTemp) print('----------------------------') print('New sensor readings:') print(str(self.tempSensorData)) if abs(self.tempSensorData.avgTemp - self.tempSensorData.curTemp) > 5: print("Current temp exceeds average by >" + str(abs(self.tempSensorData.avgTemp - self.curTemp))) # config data path path = "../../../data/ConnectedDevicesConfig.props" # new SmtpClientConnector instance add path emailSender = SmtpClientConnector.SmtpClientConnector(path) emailSender.sendEmailMessage("TemperatureEmulator(Exceptional)", self.tempSensorData) print("") sleep(self.rateInSec)