sigfox + arduino mkrfox workshop

Post on 21-Jan-2018

322 Views

Category:

Engineering

6 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Sigfox & ArduinoWorkshop

Cape Town, November 8th, 2017

Contact

Head of Technology Adoption @Sigfox

nicolas.lesconnec@sigfox.com

Twitter : @nlesconnec

About the MKRFOXArduino+Sigfox starter kit

Overview

Product released spring 2017Full sigfox service includedCortex M0 MCUSigfox chipset : Atmel/Microchip ATA8520

Atmel/Microchip ATA8520

Compatible with Sigfox RC1 (Europe + S.Africa)Adressed using SPIDatasheet : http://atmel.com

Setup the Arduino IDE

Select your board using the Tools > Port menuSet the board as Arduino MKRFOX1200

Retrieve your board information

Copy the code from http://github.com/sigfox/mkrfox-init

Upload to your board & open the monitor

Online onboarding

http://backend.sigfox.com/activate/arduino/

Provider: Arduino

Country : !South Africa

ID/PAC : Retrieved before

Getting started with Sigfox

Finding your way

The Sigfox Cloud is organized around 3 concepts :• Group : Contract & User rights• Device Type : Family of devices sharing the same

properties• Device : A unique device

List of your device types

Devices associated to a device type

Device information

Hello Worldhttps://github.com/nicolsc/mkrfox-hello-world-bool

#include <SigFox.h>

void setup() {

Serial.begin(9600);while (!Serial){}

SigFox.debug();

Serial.println("Device ID\t" + SigFox.ID());

delay(100);

SigFox.sendBit(1);

}

void loop(){}

Check device messages

Hello World (again)https://github.com/nicolsc/mkrfox-hello-world

#include <SigFox.h>

void setup() {

SigFox.begin();

short valA = 7700;

float valB = 654.32;

SigFox.beginPacket();

SigFox.write(valA);

//SigFox.write(valB);

SigFox.endPacket();

}

void loop(){}

Set Callback (device type)

Advanced features

Topics

Downlink callback

API Access

Event monitoring

Geolocation callback

Advanced callbacks with custom payloads

Frame parsing

Sigfox payload display feature

Using a « simple » grammar, you can ask Sigfox to parse your incoming dataThis is done at the device type level

Parsing the Hello World sampleModify the sketch to send 3 values in a same message short valA = 7700; short valB = 128;

float valC = 654.32;

SigFox.beginPacket();

SigFox.write(valA);

SigFox.write(valB);

SigFox.write(valC);

SigFox.endPacket();

Set a custom grammer

valA & valB are shorts : 16 bytesvalC is a 32 bytes floatvalA::uint:16:little-endian

valB::uint:16:little-endian

valC::float:32:little-endian

Downlink

How does it work?

Downlink flag included in Sigfox message

20 sec after first frame transmission, the chipset wakes up and waits for downlink response (25 sec window)

Downlink setup

Automatic callback: Device Type > Informations > Edit

Set Downlink mode to DIRECT

Enter an 8 bytes value

Sample code

Simple change

SigFox.endPacket(); to SigFox.endPacket(true);

This will request a response from the network

Handle the response

https://github.com/nicolsc/mkrfox-downlink

void loop(){

while (SigFox.available()) {

Serial.print("0x");

Serial.println(SigFox.read(), HEX);

}

}

Downlink callback

To send the response from your own server, change the Downlink mode to CALLBACK

Then create a DATA > BIDIR callback

Make sure you comply with the expected JSON format

API Access

Create credentials

Credentials are handled at the Group levelIn your group, select API Access in the left panelClick the New button in the top right cornerSelect the rights (read, write) to grant

API Documentation

You now have an « API Documentation » link next to your API CredentialsDocumentation is tailored to the user rights associated to each credential pair

API credentials

Get Device messages

GET Request to

https://backend.sigfox.com/api/devices/{device}/messages

Curl example

curl -X GET \

https://backend.sigfox.com/api/devices/2C01C2/messages \

--user {apiLogin}:{apiPassword}

Curl example

{"data":[{"device":"2C01C2","time":1491779962,"data":"0123cafe","snr":"46.59","linkQuality":"EXCELLENT","seqNumber":5,"rinfos":[{"tap":"10FC","delay":1.6480000019073486,"lat":"-23.0","lng":"-43.0"},{"tap":"10E9","delay":0.7059999704360962,"lat":"-23.0","lng":"-43.0"}]}]}

Event monitoring

Monitor break in sequence number

New Event: Device > Event Configuration > New

Select Event Type « Out of message sequence »

Select « EMAIL » as channel and enter your email address and email content

Monitor break in sequence number

Remove the antenna to simulate a coverage issue

Send a message

Re-attach the antenna and send a new message

Check reception of email notification

Geolocation Callback

Geolocation Callback⚠Under deployment in South Africa. Availability Q1

2018

Create a new Service > Geoloc callback

Use following URL to center the map: https://maps.googleapis.com/maps/api/staticmap?center={lat},{lng}&zoom=13&scale=1&size=600x300

Advanced Callbacks with IFTTT

Advanced Callbacks

Goal: Save chipset temperature in a Google Drive spreadsheet

How: Transfer message to IFTTT webhook and save content to a linked GDrive spreadsheet

IFTTT?

IF this THEN that

Free service to create conditional statements (no coding)

IFTTT Applet

Create new applet « IF Webhooks THEN Google Spreadsheet »

Webhook: custom URL to listen to HTTP requests

IFTTT Applet

IFTTT Applet

IFTTT Applet

Value[1-3] are variables forwarded by webhook

Value1 will contain Temp

Value2 will contain Light

Callback Configuration

Retrieve your IFTTT webhook URL here:

https://ifttt.com/maker_webhooks > Documentation

Callback Configuration

Create a new Custom Callback (> Device Type)

Configure custom payload , URL pattern and JSON content

Running Demo App

Send a message

Check your Google Doc has been created/updated

top related