def toJsonfromSensor(self, SensorData):
     data = {}
     data['name'] = SensorData.name
     data['avgVal'] = SensorData.avgVal
     data['maxVal'] = SensorData.getMaxValue()
     data['minVal'] = SensorData.getMinValue()
     data['curVal'] = SensorData.getValue()
     data['timeStamp'] = str(SensorData.timestamp)
     self.jsonSd = json.dumps(data)
     outputSd = open('sensordata.txt', 'w')
     outputSd.write(self.jsonSd)
     return self.jsonSd
 def sendNotification(self):
     if (abs(SensorData.getValue() - SensorData.getAvgValue()) >=
             self.alertDiff):
         #             print(SensorData.curValue)
         #             print(SensorData.sampleCount)
         logging.basicConfig(format='%(asctime)s:%(levelname)s:%(message)s',
                             level=logging.DEBUG)
         logging.info('\n Current temp exceeds average by > ' +
                      str(self.alertDiff) + '.Triggering alert...')
         data = SensorData.__str__()
         connector = SmtpClientConnector()
         connector.publishMessage('Excessive Temp', data)
Ejemplo n.º 3
0
 def sensorTojson(self, SensorData):
     data = {};
     data['name'] = SensorData.name;
     data['avgVal'] = SensorData.avgVal;
     data['maxVal'] = SensorData.getMaxValue();
     data['minVal'] = SensorData.getMinValue();
     data['curVal'] = SensorData.getValue();
     data['timeStamp'] = str(SensorData.timeStamp);
     data['totVal'] = SensorData.getTotalValue();
     data['sampleCount'] = SensorData.getSamplecount();
     self.jsonSd = json.dumps(data)
     outputSd = open('sensedata.txt','w')
     outputSd.write(self.jsonSd)
     return self.jsonSd
Ejemplo n.º 4
0
 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