Connect your devices to the Cloud through Sigfox

You decided to connect your “things” to the “internet” using the long range Sigfox network and that’s a great idea! You can collect your thousands of devices data at a very low cost using this disruptive IoT operator. It’s now time to ingest those data into an hyperscale, enterprise grade cloud solution to enable the creation of value added scenarii.

Hopefully, the Sigfox team and the Microsoft team worked together on the ease of integration with Microsoft Azure.

Microsoft Loves Sigfox

There are several ways to do this but we’ll detail the most effective one to connect the Sigfox backend to the Azure data ingestion component called Event Hub. Let’s see how easy it is using a detailed step by step tutorial.

The Microsoft Azure part

We’re going to create the Azure Event Hub. Go to the Azure portal http://manage.windowsazure.com and login.

New Event Hub
Click on “New” / “App services” / “Service Bus”, choose “Event Hub”
New Event Hub
Select the “Quick create” option
New Event Hub
The “Event Hub Name” and “Namespace name” has to be unique. You’ll get something like https://myeventhubns.servicebus.windows.net/myeventhub
New Event Hub
It may take a couple of minutes for Microsoft Azure to provision the new resource
New Event Hub
Select the newly created “Service Bus”
New Event Hub
This page shows you the detail of your Event Hub
New Event Hub
Select the “Event Hubs” tab and open the Event Hub you just created
New Event Hub
The Event Hub dashboard will display some metrics like incoming messages from your devices
New Event Hub
At the bottom right of the dashboard, you’ll find the URI of your Event Hub. You will need it soon.
NewEventHub9
Select the configure tab of the Event Hub page
New Event Hub
At the bottom of the page, type a name of a policy (ex: “sigfoxbackend”) and choose the associated rights. “Send” will fit our need.
New Event Hub
You can select the policy and copy the associated key

Create the Shared Access Signature token

SASTokenGenerator
Goto http://danvy.tv/sas-token-generator.html
Fill the form : Copy/paste the full URI of your Event Hub + “publishers/” + name of the publishers + “/messages” (ex : https://myeventhubNS.Windows.net/myeventhub/publishers/mydevice/messages), the key name (ex : sigfoxbackend) and the key value. Notice that you should use a long TTL as the Sigfox backend does not dynamically update it at the moment. Copy the generated token

 

The Sigfox backend setup

Sigfox Backend
Go to http://backend.sigfox.com and log in.
Sigfox Backend
Enter the “Device type” section
SigfoxBackend3
Edit the “Device type”
Sigfox Backend
Select the “Callbacks” entry
Sigfox Backend
Click the “New” button to add a new callback to the device type
Sigfox Backend
FIll the callback details using the following instructions

Set type to “Data” & “Uplink”.
Channel to “URL”.
In this example, my devices are sending a temperature & voltage embedded in the payload.
Use the “Custom payload config” to map the payload data to new variables. Check the help page about “how to customize the device type” https://backend.sigfox.com/cms/section/5374b6d39336709575bba099/info
Set the URL pattern to the full Event Hub URL. ex : https://mynamespace.servicebus.windows.com/myeventhub/publisher/mydevice/messages
Check Use HTTP Post.
Add a new HTTP header named “Authorization” and paste the Shared Access Signature Token we calculated earlier.

Sigfox Backend
Second part of the callback form

Set the content type to “application/json”.
And finally set the content to
{
“device” : “{device}”,
“data” : “{data}”,
“temp” : “{customData#temp}”,
“voltage” : “{customData#voltage}”,
“time” : {time},
“duplicate” : “{duplicate}”,
“snr” : “{snr}”,
“station” : “{station}”,
“avgSignal” : “{avgSignal}”,
“lat” : “{lat}”,
“lng” : “{lng}”,
“rssi” : “{rssi}”,
“seqNumber” : “{seqNumber}”
}
Don’t forget to use your very own customData variables.
You’re done, save your callback.

Troubleshooting

If you follow rigorously this tutorial, your system should work fine but hey, you know that we love our developer spicy life filled of unexpected things. In other words, you might face some problems so here are some tools to go through them.

Check that your devices are sending data to the Sigfox backend.

Sigfox Backend
Select the “Device type” section, then the “Statistics” menu to check that the backend is getting your devices data

Check that your data are sent to Microsoft Azure Event Hub

Sigfox Backend
In the “Device” section, select the “Messages” menu
Sigfox Backend
All messages are listed. Verify that the callback is working as expected. green arrows when it’s ok, red arrow when the callback doesn’t work
Sigfox Backend
The Event Hub should send back a 201 return code
Sigfox Backend
If you get a red dot, check the return code. The most common error is the 401. It means that there is an authentication issue. Double check the SAS token in the callback header.

Check that the Event Hub is getting the data

Event Hub Dashboard
Goto to “Service Bus”, open your service then open the Event Hub and display the dashboard. You should see messages incoming. Refresh from time to time.

Adding more value

Having your data in cloud is only the very beginning of a nice journey. You will find all the components to fit your IoT needs in Microsoft Azure. You can add real time analytics with Stream Analytics, you can store your data in several formats depending on your objectives. One of my favorite feature is PowerBI. It allows you to create live dashboards in minutes.

Leave a Reply

Your email address will not be published. Required fields are marked *