First SigFox program with Arduino (Akeru)

Following my previous post, I’ve started to explore Sigfox capacities with a small first project. The idea was to make a low powered GPS tracker. So I’ve just added a 10€ GPS adapter from China and wrote my first sketch.
The idea is to make a simple GPS Traker, ideally not using SMS but being able to send his position from anywhere, with of course very low energy consumption. This first version is just a proof of concept so we are not yet focused on the consumption. The data are then send to the OpenSensorCloud platform (feel free to register! )

photo(2)

The programe is quite simple:
1. initialize everything
2. wait for the GPS to get fix position
3. send it to server through Sigfox network
4. wait 10 min
5. start at 2)

We need to wait 10 minutes before sending another 22 bytes messages, it’s a Sigfox limitation and the tradeoff between low consumption, high coverage, and size. I don’t see this as a big issue for many usage, but for sure, it will add some interesting challenges

In short:

// include the library code:
#include <Akeru.h>
#include <TinyGPS.h>
#include <SoftwareSerial.h>

// initialize the library with the numbers of the interface pins
TinyGPS gps;
SoftwareSerial ss(8, 9);  // GPS RX is set on pin 8

void setup() {

  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  Akeru.begin();  // Not sure it's neded, as I need to call it again later
  delay(1000);
  ss.begin(9600);
  // Init modem
  delay(1000);
}

// int is 16 bits, float is 32 bits. All little endian
typedef struct {
  float lat;
  float lon;
  float alt;
} Payload;


void loop()
{
  Payload p;
  float flat, flon;

  gps.f_get_position(&flat, &flon, &age);
  p.lat=flat;
  p.lon=flon;
  p.alt=gps.f_altitude();
  
  if(flat==TinyGPS::GPS_INVALID_F_ANGLE){
    delay(1000);
  }else{
    // Note Seems that we need to call Akeru.begin() again or
    // further call to isReady or send will be blocked...
    delay(1000);
    Akeru.begin();
    delay(1000);
    Serial.println("is ready:"+String(Akeru.isReady()));
    Serial.println("Sending");
    bool status=Akeru.send(&p,sizeof(p));
    Serial.println("done result:"+String(status));
    // Wait for 10 minutes before sending another one
    for(int i=0;i<600;i++){
       delay(1000);
    }
    Serial.println("wake up");
  }
}

Of course, the program need some improvements, like waiting to have more satellite fixed before seding the first message, but let’s keep it simple.

The full source code is available

I had some minor issue, it seems that the Akeru API needs to be “reseted” before sending new data

The payload is quite simple, just a structure with three float: lat , lon, and alt (the last one might not be the most interesting but it was just a test).

The most interesting things is that now opensensorcloud support Sigfox devices. Sigfox allows you to send data in a limited way. You are allowed only 22 bytes per message, so no way to do ascii or json. So you usually send binary information, typically raw C or C++ structure. Then you have to decode them on the server.
Hopefully, OpenSensorCloud provides full support for such feature:
When creating a sensor for an Akeru enabled device, you just need to specify the format of the payload, this will be automatically converted to corresponding sensor values.
SigFoxConf

Make sure that your sigfox device id is well defined
Format are described in a generic json way, for instance, in may case, the payload contained 3 float field, so format is the following:

[
  {'name':"lat",'type':'float'},
  {'name':"lon",'type':'float'},
  {'name':"alt",'type':'float'}
]

As I wanted to map this to a “Position” object, and not to thre sensors, I ad to add a little bit of definition


[{'name':'pos',
  'type':'position',
  'struct':[
   {'name':"lat",'type':'float'},
   {'name':"lon",'type':'float'},
   {'name':"alt",'type':'float'}
  ]
 }
]

As a Sigfox callback, put the URL of the OpenSensorCloud callback, like this

http://api.opensensorcloud.com/device/sigfox?api_key=YOUR_API_KEY


Replace with the value of the platform.
OpenSensorCloud expect two extra parameters: device value, with the device_id you’ve just entered before, and data with the binary payload.

The API_KEY is visible on your profile,
And let’s go

The map location appears on the platform

You can see the result on the
Real Time Dashboard live
capture

In next part, we will add geofencing and twitter features thanks to the Trigger functions of the OpenSensorCloud platform…

One thought on “First SigFox program with Arduino (Akeru)”

Leave a Reply to Victor Cancel reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>