IoT with SigFox and AWS

February 17, 2019 - Reading time: 4 minutes

A little while back I was lucky enough to get an XKit development kit at one of the excellent IoT Perth meetups.

The kit consists of an Arduino UNO board with a Thinxtra shield which contains a few sensors (pressure, light, shock, 3D accelerometer) and a LPWAN transceiver. Running on the SigFox low power WAN in the RCZ4 region (AsiaPac - 920.8Mhz Uplink, 922.3Mhz Downlink), there is pretty good coverage in the Perth metro region.

Image description

I was interested to see how easy it would be to feed sensor data from this board into AWS where it could be processed further. It turned out that with the support offered by the SigFox backend, this was actually super easy. The SigFox backend allows you to define a callback, triggered on the reception of a message from the board. There are a few choices on what to do with the callback (unfortunately all documentation is only available to users authenticated on SigFox backend), including sending an e-mail, or triggering an HTTP request.

Defining the HTTP callback in the SigFox backend is very simple - in addition to specifying the endpoint to call, you are able to specify the configuration of the custom message payload received from the transmitter, including data type and endianess of the data.

temp::uint:16:little-endian pressure::uint:16:little-endian photo::uint:16:little-endian AccX::uint:16:little-endian AccY::uint:16:little-endian AccZ::uint:16:little-endian

In addition to the custom message variables, a set of standard variables (e.g. snr, time, rssi are available to include in the payload of the message to send as part of the HTTP call.

Using a combination of standard and custom message data, the payload of the HTTP call was defined thus

    "device": "{device}",
    "time": {time},
    "station": "{station}",
    "snr": {snr},
    "rssi": {rssi},
    "data": "{data}",
    "temp": {customData#temp},
    "pressure": {customData#pressure},
    "photo": {customData#photo},
    "AccX": {customData#AccX},
    "AccY": {customData#AccY},
    "AccZ": {customData#AccZ}

With that in mind, the high-level design looks like this

Image description

Device code

The code that runs ont the Uno board hosting the Thinxtra shield is super simple, and simply based on a example available from Thinxtra here. I use the Arduino IDE to write, compile, and load the code to the board.

Cloud code

Since I wanted to get the data from the board into AWS (specifically S3, where it could be queried via Aurora, using the Glue data catalog), I created an API-gateway fronted Lambda that processed HTTP requests from the SigFox backend, and published the incoming data to an AWS IoT MQTT topic. An IoT action was then defined on the same topic that persisted the data to an S3 bucket. The architecture of how the data sent by the SigFox backend is shown below

Image description

The Lambda is a simple Python script, and the entire cloud infrastructure is built from a serverless script available on GitHub.