The SiPy is a multi-network (Sigfox, WiFi and BLE) development platform. It is programmable with MicroPython and the Pymakr IDE for fast IoT application development, easy programming in-field and extra resilience with network failover. It's a good mix of speed to deployment and access to new LPWAN networks rolling out across the globe.

Requirements

Get started with your SiPy

1. Hardware set up.

On the following link you will find all the configurations that you have to do before starting with your SiPy and Ubidots.

To ensure your device has been provisioned with Device ID and PAC number, please update to the latest firmware.

NOTE:  Don't forget to connect the antenna to the board. 

2. Using Pymakr

To make it as easy as possible, the Pycom Team developed Pymakr, a tool that will allow you to connect to and program your Pycom devices. You can download Pymakr from here.

If you have any trouble connecting over USB using Pymakr, make sure you have the proper  FTDI drivers installed.

3. Initial configuration:

  • Open Pymakr.
  • Connect the expansion board with the cable micro-USB to the computer.
  • In the menu, go to Settings > Preferences (Pymakr > Preferences).
  • In the left list look for Pycom Device.
  • Select the assigned port for the board.
  • Type the username and password; the default username and password are micro and python, respectively.
  • Click OK

That’s it! In the lower portion of the screen you should see the console with the connection process taking place. At the end of it, you’ll get a ‘connected’ message and a colored ">>>" prompt, indicating that you are connected:

Registering the SiPy with Sigfox

In order to send a Sigfox message, you will need to register your SiPy with the Sigfox Backend. Navigate to https://backend.sigfox.com/activate and you will find a list of Sigfox enabled development kits. Select Pycom to proceed.

Next you will need to choose a Sigfox Operator for the country in which you will be activating your SiPy. Find your country and select the operator to continue.

Go to the Pycom doc to know how to get the Device ID and PAC number. 

Once your device is registered in the Sigfox backend you should see it on the Device section as shown on the image below:

Setting up the Sigfox callback to the Ubidots Cloud

The management of the data between Sigfox and Ubidots goes through a "Callback". The Sigfox device will be in charge to read the sensors and send the values to Sigfox, the message will be decoded using the custom payload config at the callback configurations to build the request to uplink the message to Ubidots.

Now it is time to set up the callback. Go to the Device section and click on the registered device:

Next, verify your device information and select "CALLBACKS" from the menu on the left of the page, as you can see below:

Sigfox callbacks allow you to report data to an external system like Ubidots. To setup a callback to Ubidots API, use these parameters:

  • Type: DATA - UPLINK
  • Channel: URL
  • Custom payload config: temperature::float:32:little-endian pressure::uint:8
  • Url pattern: 
http://things.ubidots.com/api/v1.6/devices/{device}/?token={Put_Your_Ubidots_TOKEN_here}
  • Use HTTP method: POST
  • Content Type: application/json
  • Body:
{
  "snr" : "{snr}",
  "avgSnr" : "{avgSnr}",
  "rssi" : "{rssi}",
  "position":{"value":0,"context":{"lat":"{lat}","lng":"{lng}"}},
  "temperature" : {"value":"{customData#temperature}"},
  "pressure" : {"value":"{customData#pressure}"}
}

IMPORTANT NOTE: The field "custom payload config" allows you to specify how you would like Sigfox to decode your device's payload. You might for example wish to decode an incoming byte as an unsigned integer. An example of this is the first line of the sample below:

int1::uint:8 // Unsigned integer of 8 bits with name int1
str::char:6 // Character String of 6 letters with name str
b1::bool:7 // Boolean based on value of bit in position 7 with name b1

Where "int1" is the name of the value, "uint:8" specifies the datatype and the number of bits, respectively. To know more about how to build the custom payload config, please reference to the sigfox documentation pressing the question icon to display help.

The Sigfox payload will decode the message and it will be received on the Ubidots side without matter the format used on it, but take in count that you have to set the same format into your device's code because if not, the data will not be received by Sigfox. To verify if the message is received at Sigfox go to the Device section, then select the device's ID:

Next, at the left menu select "message" to visualize the messages received:

Please note the "customData#..." from the body field will contain the actual sensor information, in the example shown as "temperature"and "pressure". If you desire send more values, you have to assign it at the custom payload config, them assign it at the body following the same structure.

Following this guide, we configured two variables "temperature" as float and "pressure" as uint; You can use the format that you desire but take in count that the device have to send the values using the same format assigned by you at the custom payload config

  • The temperature is configured as "float" which can be either 16, 32 or 64 bits, optionally the endianness for multi-bytes floats, and optionally the bit offset where to start the reading of the first byte. Depending of the bits that you assigns you will be able to send 2 values(16 bits) and 4 values (32 bits) 

temperature::float:32:little-endian 

  • The pressure is configured as "uint" the parameters are the number of bits to include in the value, optionally the endianness for multi-bytes integers, and optionally the bit offset where to start the reading of the first byte. Using this configuration you will be able to send 12 values.

pressure::uint:8 


NOTE:
To know more about how to build the custom payload config, please reference to the sigfox documentation pressing the question icon to display help.


After configuring the callback, it should look like this:

Once you verify the callback, press "OK". Now your callback is ready and enabled to post to the Ubidots Cloud.

Coding your SiPy

Go back to the Pymakr and paste the code below, then press run to start sending the data: 

from network import Sigfox
import socket
import struct

# init Sigfox for RCZ1 (Europe)
sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ4)

# create a Sigfox socket
s = socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW)

# make the socket blocking
s.setblocking(True)

# configure it as DOWNLINK specified by 'True'
s.setsockopt(socket.SOL_SIGFOX, socket.SO_RX, True)

# send values as little-endian and int, request DOWNLINK
s.send(struct.pack("<f",  23.2)+struct.pack("<B",  45))

# await DOWNLINK message
s.recv(32)

NOTE: As you can see last part of the code the values are sent following the same format assigned at the custom payload config

  • Code: s.send(struct.pack("<f",  23.2)+struct.pack("<B",  45)) 
  • Custom payload config:  temperature::float:32:little-endian pressure::uint:8 

Go to your Ubidots account to visualize the new device created with the variables.

Please note that the "API Label" will be the same as the Sigfox {device} field.

Result

Now it is time to create a dashboard to control and manage the variables of your Sigfox device. To learn more about Ubidots widgets and events, check out these video tutorials.

Did this answer your question?