Following this guide, you will be able to decode the data from the UnaMotion sensor to count and detect human movement within its scope of monitoring.
The functionality of the UnaMotion depends on its Mode configuration, it can be:
Timer mode: Count the number of Human movements over a period of time.
Event mode: Detect Human Movement.
Requirements
An active Ubidots account
An active Sigfox account.
UnaMotion sensor already transmitting data to Sigfox and Ubidots (See Plugins: Connect Sigfox with Ubidots)
1. Understanding the data
Here’s how the data is being decoded according to the documentation to count the number of movements or to detect motion. It is important to keep in mind that the decoding depends on the mode in which the sensor is configured.
1.1. Timer mode data
The following payload structure is an example of the data being sent from Sigfox to Ubidots specifically for an UnaMotion sensor configured for Timer Mode.
{
"device_id": "41DAD4"
"data": "018b05050707050605060102",
}
Sample data from Sigfox Sensor: 018b05050707050605060102
0x01
- Mode Byte #00x8b
- Interval Byte #10x05
- Movement 1/10 Byte #20x05
- Movement 2/10 Byte #30x07
- Movement 3/10 Byte #40x07
- Movement 4/10 Byte #50x05
- Movement 5/10 Byte #60x06
- Movement 6/10 Byte #70x05
- Movement 7/10 Byte #80x06
- Movement 8/10 Byte #90x01
- Movement 9/10 Byte #100x02
- Movement 10/10 Byte #11
Bytes in Total: 12
1.2. Event mode data
The following payload structure is an example of the data being sent from Sigfox to Ubidots specifically for an UnaMotion sensor configured for Event Mode.
{
"device_id": "41DAD4"
"data": "0201",
}
Sample data from Sigfox Sensor: 0201
0x02
- Mode Byte #00x01
- State Byte #1
Bytes in Total: 2
NOTE: The state byte represents a way to detect motion, It can be:
0x00
: No motion detected0x01
: Motion detected
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 UnaMotion.
Step 3: Copy and paste the code below into the code editor replacing the decode_data()
function.
def decode_data(hex_array):
payload = {}
status = hex_array[0]
if status == 0 or status == 4:
voltage = (int(hex_array[1:3].hex(), 16))/1000
payload["voltage"] = voltage
elif status == 1:
payload["motion_count"] = int(hex_array[2:12].hex(), 16)
elif status == 2:
payload["state"] = int(hex_array[1:2].hex(),16)
return payload
Save the code by clicking on the "SAVE & MAKE LIVE" button.