Following this guide, you will be able to decode and monitor the temperature and humidity data from the UnaSense sensor when it is set up in Timer Mode, which means that it sends the temperature and the humidity level at the designated rate.


Table of contents

  1. Understanding the data

  2. Decoding function at Sigfox Plugin

  3. Function testing

1. Understanding the data

The following payload structure is an example of the data being sent from Sigfox to Ubidots specifically for an UnaSense sensor.

"device_id": "21O561D"
"data": "018b0925092f2035202c",

Now, here’s how the data is being decoded according to the documentation to obtain the temperature and the humidity values. It is important to keep in mind the mode in which the sensor is configured, in this case since the mode is Timer, the decoding is as follows:

Sample data from Sigfox Sensor: 018b0925092f2035202c

  • 0x01 - Mode Byte #0

  • 0x8b - Interval Byte #1

  • 0x0925 - Temperature 1/2 Bytes #(2 - 3)

  • 0x092f - Temperature 2/2 Bytes #(4 - 5)

  • 0x2035 - Humidity 1/2 Bytes #(6 - 7)

  • 0x202c - Humidity 2/2 Bytes #(8 - 9)

Bytes in Total: 10

NOTE: As you can notice, the temperature and the humidity have two parts of 2 bytes each. This means that in total, the temperature has 4 bytes (same with the humidity) and this data needs to be processed in the following way:

Temperature = (Temperature 1/2 + Temperature 2/2) / 2
Humidity = (Humidity 1/2 + Humidity 2/2) / 2

After the average is done, both Temperature and Humidity need to be multiplied by 0.1 which can be translated to divide the value by 100.

2. Decoding function at Sigfox Plugin

Step 1: Go to the Sigfox plugin and open the Decoder option.

Step 2: Find the Decoding function Section. Here’s where we are going to start decoding the data coming from the UnaSense.

Step 3: Copy and paste the code below into the code editor replacing the decode_data() function:

def decode_data(hex_array):
payload = {}
temperature = (int(hex_array[2:4].hex(), 16) + int(hex_array[4:6].hex(), 16))/2
humidity = (int(hex_array[6:8].hex(), 16) + int(hex_array[8:10].hex(), 16))/2
payload["temperature"] = temperature/100
payload["humidity"] = humidity/100
return payload

Save the code by clicking on the "SAVE & MAKE LIVE" button.

3. Function Testing

After following the previous steps, your decoder should look like the image below, and to test the function, please enter the JSON test payload within the curly braces and click on "TEST RUN".


The result of the TEST RUN can be seen in the console and it should return as an output a 201 HTTP code indicating that the data was successfully decoded. Also, in the log section it should return the values for temperature and humidity.


Other users also found helpful...

Did this answer your question?