Within this article, I will explain how to connect your MKRFox 1200 board to our Cloud. The firsts thing you must have is already activated board on sigfox backend. This tutorial covers all the steps in case you need to do that. Now, let's get started with connecting the board to our IoT Cloud. 

Introduction

Would there be a meaning to receive only temperature data somewhere on the backend? Of course not, it's nothing of value if you don't visualise data to be able for post analysis. For instance, data visualisation is of great importance when building weather stations, where just a quick look on the value can already be a notification for the critical state. I'll give you my short, but nice example. When I finished building temperature and humidity sensor in my living room, slight (but also sudden) temperature rise in the winter time was indication that someone was home and turned the heating on. That was the concrete information that I'll enter into the warm environment at once. 🙂

Now, related to MKRFox 1200, it has the internal temperature sensor integrated on the board. Therefore, I'll provide you with the code to send this data to the Sigfox backend, which would then be transferred to our Cloud. Just follow the next steps and everything should work in a blink of an eye!

Effort estimate

* Intermediate tutorials require basic understanding of programming & familiarity with command line interface. 

What you will need

Create a new device on the Cloud

First steps first. To be able to connect your device through the backend, you need to create a new device within our Cloud, which will have concrete assets (sensor's data). The best is to read this article since it is a complete tutorial, but I'll explain it here in short:

  1. Log-in to the AllThingsTalk Maker,

  2. Click on "Playground" if you are on this page (skip if you're in DEVICES page),

  3. Click on "DEVICES" on the left sidebar and then "+NEW DEVICE" ,

  4. Choose "Your own device",

  5. Pick a name you want for this project (e.g. H/T Project), then click on "CONNECT",

  6. Now you have your device created.

The next important steps are:

  1. Click on the newly created Device from the previous steps (e.g. H/T Project),

  2. Now click on the "SETTINGS" gear button on the right side and enable the Data storage. If storing device activity is set to OFF, you'll not be able to track the historical data or to have working graphs,

  3. Now click on "Authentication" and copy both "Device ID" and "Device Token" somewhere. You'll need them to configure the callback service on Sigfox.

Configure Callback on Sigfox backend

Having device created on our Cloud, now go back to the Sigfox backend and follow these steps:

  1. At the top ribbon, click on "DEVICE" tab,

  2. Under the "Device type", click on the name that was activated with ID and PAC,

  3. On the left sidebar click on "CALLBACKS",

  4. Since you already have existing callback from activating the board Tutorial, click on the button under "Edit" on the right side,

  5. Configure the callback as instructed:

  • Type: DATA | UPLINK

  • Channel: URL

  • Custom payload config: internaltemperature::float:32:little-endian

  • URL pattern: https://api.allthingstalk.io/device/XXXXXXXXXXXXXXX/state (X is the Device ID taken from our Cloud - Authentication page)

  • Use HTTP Method: PUT

  • Headers: Authorization  |  Bearer maker: YYYYYYYYYYYYYYY (Y is Device token taken from our Cloud - Authentication page)

  • Content type: application/json

  • Body: 

{
  "internaltemperature":{"value":{customData#internaltemperature}}
}

On the backend, it looks like this:

6. Once you've typed everything needed, click "OK" on the bottom of the page.

Now go back to the DEVICE tab, click on the number under "Id" field (6 digits number with letters) of your activated board and after it opens, click on the left sidebar - MESSAGES. It will show all the messages received. You should see the green button that will show "Callback - OK" when hovering over it. Click on that callback and you'll see the text box containing all details about that message, along with the latest "internaltemperature" reading.

You have successfully configured the callback to our Cloud. Great job! 👌

Configure Assets on our Cloud

Now, go back to our Cloud and click on "DEVICES" tab in sidebar. On the page that opens, choose the device you've created for this purpose (e.g. H/T Project). Now:

  1. Click on the button "CREATE ASSET",

  2. Under Name, write: internaltemperature,

  3. Under Profile, Choose type: Number,

  4. Click on CREATE ASSET,

  5. Restart your MKRFox either with RST button or unplug > plug in the USB cable.

You've got it! This tutorial will enable you to measure the MKRFox's internal temperature, go to sleep for 15 minutes, take and send another reading and go back to sleep. Quite simple, but reliable thing, ain't it? 😃

From this point, you can create Pinboard (button on the upper right corner) and more widget-alike pins. This will add up to the project seriousness, as it can have a graph (historical) data, different types of pins and more! Read how to do that here.  

Code

#include <SigFox.h>
#include <ArduinoLowPower.h>
#include <RTCZero.h>

#define SLEEPTIME     10 * 60 * 1000   // Delay: X minutes (X min x 60 seconds x 1000 milliseconds)

float internaltemperature;
volatile int alarm_source = 0;  //variable for sleep mode

void setup() {
  Serial.begin(115200);
  LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, alarmEvent0, CHANGE);  //interrupt for wake-up from sleep

  SigFox.begin();
    if (!SigFox.begin()) {
       Serial.println("Something is wrong, try rebooting device");
       SigFox.reset();
    while(1);
    }    
}

void alarmEvent0() {  // Interrupt to wake-up Device from SLEEP    
  alarm_source = 0;
}

void loop() {
  SigFox.begin();
  SigFox.status();
  Serial.println("Starting to measure internal temperature");
  internaltemperature = SigFox.internalTemperature();
        if (isnan(internaltemperature)) {   // Check if reading T/H was okay
            Serial.println("Failed to read the internal temperature!");
            return;
        }    
   SigFox.beginPacket();               // Start sending the Sigfox message
   SigFox.write(internaltemperature);  // Send the temperature to backend.sigfox.com          
   SigFox.endPacket(false);
   SigFox.end();  
   
   LowPower.sleep(SLEEPTIME);          // Send device back to sleep
}  
Did this answer your question?