The Sigfox Arduino – Part 2 – Program To Send A Message

In the first part of this series on the Mkrfox 1200 Arduino that comes with a Sigfox chip and a 2 year network subscription I’ve taken a look at what is required to get going, how to send a first message from the module to the network and how that message can be forwarded to a server on the Internet. In total it was a 30 minutes exercise, i.e. very easy to do. In this part, I’ll have a closer look at the code that is required to accomplish the task.

Setting Up The Software In A Virtual Machine

Like all Arduinos the Mkrfox is programmed in C/C++ in the a very easy to use Arduino graphical development environment (IDE). It doesn’t offer a million bells and whistles as it addresses first-time users and rapid prototyping of ideas. As described in the previous post, installing the IDE, the board support package and a few software libraries only takes a few minutes. As I like to keep my host system clean I installed the Arduino software in a Virtualbox Ubuntu 16.04 guest OS and mapped the USB device that is created when the Mkrfox board is plugged-in into the virtual machine.

For downloading the code, the board is reset by the IDE and restarted with a different USB device and USB ID so one has to map this second USB ID into the virtual machine as well. It is best to automate the process as the IDE is quick to time out if the board is not found quickly after the reset. The second screenshot on the left shows the two fixed USB mappings I’ve created in the Virtualbox manager. I configured the first mapping after connecting the board to the PC for the first time and the second mapping after downloading the code initially failed.

The Code To Send A Sigfox Message

One of the installed libraries contains everything that is required to communicate from the ARM Cortex M0 based microcontroller via a serial SPI interface with the Sigfox chip. The Sigfox library encapsulates all overhead and details of the serial interface so sending a message only requires a few Sigfox library API calls such as Sigfox.begin(), .status(), .beginPacket(), .print(message), .endPacket() and .end().

All of this is again encapsulated in a single function that can be included in a program and hence, sending a message from anywhere in the code can be done with a single function call: ‘sendString(message)’. ‘Message’ is a string variable and the first 12 characters (bytes) contained in the variable are sent over the Sigfox network.

Exploring the Sigfox Library

When you browse the web for Sigfox demo code you’ll find a lot of sources in which ‘AT-commands’ are used to communicate with the Sigfox chip. AT-commands have been a popular method for many decades to communicate from a PC to external modems so it’s not surprising to find it being reused for this application as well. The Sigfox chip used on the Mkrfox board, however, does not use a UART (Universal Asynchronous Transciever) and AT-commands but a more modern SPI interface and command packet approach. If one has used AT commands for decades, the SPI interface looks a bit more complicated and abstract. It doesn’t really matter in practice as it is abstracted by the Arduino Sigfox library anyway. A good thing about this library is that it is also written in C++ so it’s not very difficult to find out how this way of communicating with the Sigfox chip works. The library is actually quite compact but not documented so the datasheets of the SAMD-21 microcontroller that runs the user program and the AT8520E Sigfox module, both from Atmel, are a great help to understand what the library is doing.

Summary

The Arduino folks have made it incredibly easy for programs to send and receive data over the Sigfox network, a single function call is all it takes. Perfect to get things up and running quickly. In the next episode I will take a closer look at how data is sent and received over the Sigfox network so it will become clear why Sigfox messages are limited to a length of 12 bytes and why only a similar amount of data can be received from the network per message as well.