Blog

How to Send Data from an Arduino MKRFox1200 to Wia

Hi All,
In this tutorial you’ll learn how to send data packets from your Arduino MKRFox1200 device to Wia. This will allow your devices to communicate remotely through the SigFox platform. To do this, you’ll have to download the Arduino IDE and do a little bit of coding.

Installing the SigFox Library

Open the Arduino IDE and go to Sketch > Include Libraries > Manage Libraries.

Type “SigFox” into the search bar and click the first option. A button will appear in the bottom right of the box that will allow you to install the library.

The Code

Using commands from the SigFox Library (more info here) is very simple and makes it easy to send a packet from your device to SigFox.

#include <SigFox.h>   // must include the SigFox library
void setup() {
  Serial.begin(9600); 
  while(!Serial) {}; //waits for Serial to be available
  if (!SigFox.begin()) { //ensures SigFox is connected
    Serial.println("Shield error or not present!");
    return;
  }
  Serial.print("sending");
  SigFox.begin();
  SigFox.beginPacket();
  SigFox.print("letters"); //content of the packet
  SigFox.endPacket();
  Serial.print("sent");
}
void loop() {
  while(1);
}

The SigFox.begin() command initializes the SigFox library and allows you to then use other commands from the library. To create a packet, you must use the SigFox.beginPacket() and SigFox.endPacket() commands to identify which parts of the code will affect the packet that you intend to send. Between these lines, use the SigFox.print() command to print a message to your packet. Note: The largest packets that you can send through SigFox are 12 bytes. Any packet over 12 bytes will be incomplete and only the first 12 bytes will be sent.

Receiving the Message on SigFox

To check if the message was properly sent and received, go to your SigFox account and click the Device tab at the top of the screen. Then, click on the ID of the device you were testing.

sigfox-mkr-tut-1

Then click on Messages on the left side to bring up the most recent messages that SigFox has received from your device. SigFox will display the time, content, and quality of the message. The content will be displayed in hexadecimal numbers so don’t be alarmed if the content looks different from the packet you sent.

sigfox-mkr-tut-2

As shown in the image above, the most recent packet has a hexadecimal value of 0x6c657474657273. Translating this hex value into a string of characters produces an output which is equivalent to “letters”—the original message typed into the packet.

Connecting to Wia

Now to send your data from Sigfox to Wia. Follow the tutorial here to learn how to sync your devices and here to setup callbacks.

That’s all for now folks!

EW

Ready to get started?
Talk to our sales team or setup an account.