The UnaBell is a smart battery-powered smart button that can last up to 10,000 presses without a charge. Following this guide, you will be able decode the data from the UnaBell to detect and count short/long presses.

The functionality of the UnaBell depends on its Mode configuration, it can be:

  • Timer mode: Count the number of short/long presses over a period of time.

  • Event mode: Detect short and long presses.

Requirements

Table of contents

1. Understanding the data
1.1. Timer mode data
1.2. Event mode data

2. Decoding function at Sigfox Plugin
2.1. Timer mode decoder
2.2. Event mode decoder

1. Understanding the data

Here’s how the data is being decoded according to the documentation to obtain the number of presses. 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 UnaBell sensor configured for Timer Mode.

{
"device_id": "416A7B"
"data": "018b0b0a0b0b0a0202030201"
}

Sample data from Sigfox Sensor:

  • 0x01 - Mode Byte #0

  • 0x8b - Interval Byte #1

  • 0x0bShort Press 1/5 Byte #2

  • 0x0a - Short Press 2/5 Byte #3

  • 0x0b - Short Press 3/5 Byte #4

  • 0x0b - Short Press 4/5 Byte #5

  • 0x0a - Short Press 5/5 Byte #6

  • 0x02 - Long Press 1/5 Byte #7

  • 0x02 - Long Press 2/5 Byte #8

  • 0x03 - Long Press 3/5 Byte #9

  • 0x02- Long Press 4/5 Byte #10

  • 0x01 - Long Press 5/5 Byte #11

Bytes in Total: 12

NOTE: As you can notice, the short press and the long press have five parts of 1 byte each. This means that in total, the short press has 5 bytes and same applies for the long press.


1.2. Event mode data

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

{
"device_id": "416A7B"
"data": "0201",
}

Sample data from Sigfox Sensor: 0201

  • 0x02 - Mode Byte #0

  • 0x01 - State Byte #1

Bytes in Total: 2

NOTE: The state of the press represents a way to define what kind of press (short or long) was detected, It can be:

  • 0x00: Short press

  • 0x01 : Long press

2. Decoding function at Sigfox Plugin

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

image.png

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

image.png

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["short_press"] = int(hex_array[2:7].hex(), 16)
payload["long_press"] = int(hex_array[7: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.

Other users also found helpful...

Did this answer your question?