- Those who need to use the TATU library should preferably import it like this: from TATU import TatuReq, TatuRes
- Consider that a device (e.g., sc01) may have several sensors (e.g., humiditySensor, temperatureSensor...)
- The TATU protocol is not case-sensitive, however, creating messages in lowercase should be prioritized.
First example requesting information from only one temperatureSensor sensor embedded in device sc01:
#Object creation
tatuMessage = TatuReq("FLOW",collect="10000",publish="10000",sensor="temperatureSensor",device="sc01")
#The value in tatuMessage.getTatu() should be:
'{"method":"flow", "sensor":"temperatureSensor", "time":{"collect":"10000", "publish":"10000"}}'
#O valor em tatuMessage.getTopic() deverá ser:
'dev/sc01/REQ'
tatuMessage = TatuReq("FLOW",collect="10000",publish="20000",sensor="temperatureSensor",device="sc01")
#The response:
'{"method":"flow", "device":"temperatureSensor", "time":{"collect":"10000", "publish":"20000"}}'
#The value in tatuMessage.getTopic() should be:
'dev/sc01/REQ'
tatuMessage = TatuReq("FLOW",collect="10000",publish="10000",sensor=None,device="sc01")
#The response tatuMessage.getTatu():
'{"method":"flow", "device":"sc01", "time":{"collect":"10000", "publish":"10000"}}'
#The value in tatuMessage.getTopic() should be:
'dev/sc01/REQ'
Fourth Example requesting that all sensors on device sc01 stop sending new messages (this message does not require a response):
tatuMessage = TatuReq("STOP",collect="10000",publish="10000",sensor=None,device="sc01")
#The response tatuMessage.getTatu()
'{"method":"stop", "device":"sc01"}'
#The value in tatuMessage.getTopic() should be:
'dev/sc01/REQ'
Fifth Example requesting that the temperatureSensor of device sc01 stop sending new messages (this message does not require a response):
tatuMessage = TatuReq("STOP",collect="10000",publish="10000",sensor="temperatureSensor",device="sc01")
#The response tatuMessage.getTatu()
'{"method":"stop", "sensor":"temperatureSensor"}'
#The value in tatuMessage.getTopic() should be:
'dev/sc01/REQ'
tatuMessage = TatuReq("GET",sensor="temperatureSensor",device="sc01")
#The response tatuMessage.getTatu()
'{"method":"get", "sensor":"temperatureSensor"}'
#O valor em tatuMessage.getTopic() deverá ser:
'dev/sc01/REQ'
tatuMessage = TatuReq("GET",sensor="None",device="sc01")
#The response tatuMessage.getTatu()
'{"method":"get", "device":"sc01"}'
#The value in tatuMessage.getTopic() should be:
'dev/sc01/REQ'
Ninth example requesting a TATU message from the temperatureSensor only when a delta variation occurs:
tatuMessage = TatuReq("EVT",sensor="temperatureSensor",device="sc01",delta="2")
#The response tatuMessage.getTatu()
'{"method":"evt", "sensor":"temperatureSensor","delta","2"}'
#The value in tatuMessage.getTopic() should be:
'dev/sc01/REQ'
First example responding to a message that requested data from only one temperatureSensor sensor embedded in device sc01:
#collect and publish optional params tatuMessage = TatuRes("FLOW",collect="10000",publish="10000",sensor="temperatureSensor",device="sc01",sample="37")
#O valor em tatuMessage.getTatu() deverá ser:
'{"header": {"method": "FLOW", "device": "sc01"}, "payload": {"sensors": [{"temperatureSensor": ["37"]}]}}'
#The value in tatuMessage.getTopic() should be:
'dev/sc01/RES'
Second example responding to a message that requested information from only one temperatureSensor sensor embedded in device sc01:
tatuMessage = TatuRes("FLOW",collect=10000,publish=20000,sensor="temperatureSensor",device="sc01",sample=["37","38"])
#O valor em tatuMessage.getTatu() deverá ser:
'{"header": {"method": "FLOW", "device": "sc01"}, "payload": {"sensors": [{"temperatureSensor": ["37", "38"]}]}}'
#The value in tatuMessage.getTopic() should be:
'dev/sc01/RES'
tatuMessage = TatuRes("FLOW",collect="10000",publish="10000",sensor=None,device="sc01",sensorsList=["humiditySensor","temperatureSensor","soilmoistureSensor","solarradiationSensor","ledActuator"], sensorsValue=[["66"],["31"],["650"],["2291"],["true"]])
#The response tatuMessage.getTatu():
'{"header": {"method": "FLOW", "device": "sc01"}, "payload": {"sensors": [{"humiditySensor": ["66"]}, {"temperatureSensor": ["31"]}, {"soilmoistureSensor": ["650"]}, {"solarradiationSensor": ["2291"]}, {"ledActuator": ["true"]}]}}'
#The value in tatuMessage.getTopic() should be:
'dev/sc01/RES'
Fourth example response to a request for immediate data from the temperatureSensor sensor of device sc01:
tatuMessage = TatuRes("GET",sensor="temperatureSensor",device="sc01",sample="27")
#The response tatuMessage.getTatu()
'{"header":{"method":"GET", "device":"sc01"}, "payload":{"sensors":{"temperatureSensor":["27"]}}}'
#The value in tatuMessage.getTopic() should be:
'dev/sc01/RES'
tatuMessage = TatuRes("GET",sensor="None",device="sc01",sensorsList=["humiditySensor","temperatureSensor","soilmoistureSensor","solarradiationSensor","ledActuator"], sensorsValue=[["66"],["31"],["650"],["2291"],["true"]])
#The response tatuMessage.getTatu()
'{"header": {"method": "get", "device": "sc01"}, "payload": {"sensors": [{"humiditySensor": ["66"]}, {"temperatureSensor": ["31"]}, {"soilmoistureSensor": ["650"]}, {"solarradiationSensor": ["2291"]}, {"ledActuator": ["true"]}]}}'
#The value in tatuMessage.getTopic() should be:
'dev/sc01/RES'