IMBUILDINGS Comfort Sensor
Describes how to integrate the Comfort Sensor from IMBUILDINGS with your application.
IMBUILDING provides a Ready for IoT Creators comfort sensor which can be shipped with a IoT Creators SIM card and is already pre-integrated with IoT Creators SCS. The sensor measures CO2, temperature, humditiy and body sense.
In this chapter I explain you how to decode the sensor data to integrate it into your application or IoT platform.
The sensor provides its measurement values as a single data package in hex format. This data is forwarded by the SCS to your application URL as the value element as part of the following JSON payload.
{
"reports":[{
"serialNumber":"IMEI:351938100106687",
"timestamp":1600439712734,
"subscriptionId":"fa37d89c-a7e2-4f3d-b12f-6002a3642b4c",
"resourcePath":"uplinkMsg/0/data",
"value":"0101d880396f026e000158a50a4b121503d301"
}],
"registrations":[],
"deregistrations":[],
"updates":[],
"expirations":[],
"responses":[]
}
To get the measurement values of the sensor into your application you need to decode the hex data of the value element to the actual measurement values.
Payload Specification
No matter if you can receive JSON payload from IoT Creators SCS directly in your application or if you have to switch an additional message transformation service in between you have to implement (or to configure) data decoding according to the data specification of IMBUILDING.
As shown in the next picture the payload of the comfort sensor is devided into the four blocks
- type of payload
- version of payload format
- device info
- measurement data
In the following image you see the detailed payload specification of the Comfort Sensor.
In the following you will get a simple sample how you can decode payload of the Comfort Sensor for your application.
Payload decoder (JavaScript)
You can find the decoder on our GitHub . This decoder also works for other IMBUILDING devices like their [Moodbox].(https://docs.iotcreators.com/docs/imbuildings-mood-box).
Whether you extracted the value of the JSON or just copied it from the IoT Creators Portal to test the decoder, you can simply pass the value to the decodeUplink function of the decoder and get our decoded message in return.
var decoded_value = imbuilding.decodeUplink(<<HEX STRING VALUE>>);
console.log(decoded_value);
Payload decoder (Python 3.2+)
Whether you extracted the value of the JSON or just copied it from the IoT Creators Portal to test the decoder, you can simply pass the value to the decodeUplink function and get our decoded message in return.
def decodeUplink(hexString):
a = bytearray.fromhex(hexString)
type = a[0]
version = a[1]
if type == 1 and version == 1:
d = {
"status" : a[8],
"batteryV" : int.from_bytes(a[9:11], "big") / 100.,
"temperature" : int.from_bytes(a[12:14], "big") / 100.,
"humidity" : int.from_bytes(a[14:16], "big") / 100.,
"co2" : int.from_bytes(a[16:18], "big"),
"presence" : a[18]
}
return d
else:
raise Exception("Unsupported type %d and version %d" % (type, version))
Decoded values
For the payload of 0101d880396f026e000158a50a4b121503d301 the decoding function provides the following result:
{
'status': 0,
'batteryV': 3.44,
'temperature': 26.35,
'humidity': 46.29,
'co2': 979,
'presence': 1
}
Updated over 1 year ago
After you have decoded the sensor data into a handy format the next step is to transform this JSON data into the formation of your application which is probably very easy for you because you are the expert of your application.