Beispiel #1
0
 def toSensorDataFromJson(self, jsonData):
     sdDict = json.loads(jsonData)
     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']
     
     return sd 
Beispiel #2
0
    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
Beispiel #3
0
 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
Beispiel #4
0
from labs.common            import ConfigConst
from labs.common.ConfigUtil import ConfigUtil
from labs.common.DataUtil   import DataUtil
from labs.common.SensorData import SensorData
from labs.module06.MqttClientConnector  import MqttClientConnector

topic   = "Temperature Sensor"

config  = ConfigUtil('../../../config/ConnectedDevicesConfig.props');
host    = config.getProperty(ConfigConst.ConfigConst.MQTT_CLOUD_SECTION, ConfigConst.ConfigConst.HOST_KEY)

'''
Creating the Sensor Data
'''
sensor              = SensorData(topic,0,30)
sensor.curValue     = uniform(float(sensor.getMinValue()), float(sensor.getMaxValue())); 
sensor.addValue(sensor.curValue);
sensor.diffValue    = sensor.curValue - sensor.avgVal;
sensor.timestamp    = datetime.now();
logging.info('SensorData to be sent:')
print("Sensor data before converting to Json: " + str(sensor));

'''
Converting the Sensor Data to the JSON format
'''
data        = DataUtil()
jsonData    = data.SensorDataToJson(sensor)
logging.info('SensorData converted into Json:')
print("SensorData in Json Format before publishing" + "\n" + str(jsonData) + "\n")
pub_client  = MqttClientConnector();