Things used in this project

Hardware components:
The AirBoard
×1
Atim Sigbee
×1
Software apps and online services:
Sigfox logo rvb(1)
Sigfox
Artik logo cloud
Samsung IoT ARTIK Cloud for IoT

Code

Code snippet #1Plain text
// ---------------------------------------------------------------------
// This file is a example for use the library armapi with
// The AirBoard using the SigBee shield module
//
// This software send periodically the digital value of the pin D3~ to Sigfox network.
//
// Created date: 06.09.2016
// Author: Louis Moreau
// Adapted from: <a href="https://github.com/atim-radiocommunications/armapi"> https://github.com/atim-radiocommunications/armap...</a>
// ---------------------------------------------------------------------

// ---------------------------------------------------------------------
// Include
// ---------------------------------------------------------------------
#include <arm.h>
#include <avr/sleep.h>
#include <TheAirBoard.h>
// ---------------------------------------------------------------------
// Define
// ---------------------------------------------------------------------
#define GREEN  5             // GREEN LED
#define BLUE   6              // BLUE LED
#define RED    9            // RED LED
#define PIEZO  3             //Digital Pin 
#define TIMEINTERVALL 900000  // 900 sec -> 15 min sleep time

// ---------------------------------------------------------------------
// Global variables
// ---------------------------------------------------------------------
//Instance of  the class Arm
Arm SigFox;

//Instance of the air board class
TheAirBoard board;

bool debug = false;

//The message to send at sigfox - Set the size of your message in bytes within the brackets
uint8_t msg[2];
//downlink received message
uint8_t data[8];

bool blue = false;
bool sigfoxOK = false;
bool trigger = false; 
int downlinkCounter = 0;
int points = 0;
int count = 0;

uint8_t rev;
armType_t armType;


// ---------------------------------------------------------------------
// Implemented functions
// ---------------------------------------------------------------------
void wakeUpNow()        // here the interrupt is handled after wakeup
{
  points++;
}

void setup()
{
  //Pin modes
  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);
  pinMode(RED, OUTPUT);
  pinMode(PIEZO, INPUT);

  resetLeds();

  if(debug){
    Serial.begin(57600);
    digitalWrite(GREEN, HIGH);
  }else{
    //Init Arm and set LED to on if error
  	if (SigFox.Init(&Serial) != ARM_ERR_NONE){
  		digitalWrite(RED, HIGH);
      delay(1000);
      resetLeds();
  	}else{
      digitalWrite(GREEN, HIGH);
      delay(1000);
      resetLeds();
      SigFox.Info(&armType, &rev, 0, 0, 0);
      sigfoxOK=true; 
      SigFox.SetMode(ARM_MODE_SFX);
      //Set Sigfox mode in uplink.
      SigFox.SfxEnableDownlink(false);
      //If downlink
      /*
      if(SigFox.SfxEnableDownlink(true)!= ARM_ERR_NONE){
        digitalWrite(RED, HIGH);
      }else{
        digitalWrite(GREEN, HIGH);
      }
      */
      SigFox.UpdateConfig();
  	}
  }
  delay(1000);
  resetLeds();
  attachInterrupt(1, wakeUpNow, RISING);
}

void sleepNow()         // here we put the device to sleep
{
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);   // sleep mode is set here
 
    sleep_enable();          // enables the sleep bit in the mcucr register
                             // so sleep is possible. just a safety pin
 
    attachInterrupt(1, wakeUpNow, RISING);
 
    sleep_mode();            // here the device is actually put to sleep!!
                             // THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
 
    sleep_disable();         // first thing after waking from sleep:
                             // disable sleep...
    //detachInterrupt(digitalPinToInterrupt(PIEZO)); // disables interrupt so the
                             // wakeUpNow code will not be executed
                             // during normal running time.
 
}

void loop()
{ 
    if(debug){
      Serial.print("Awake for ");
      Serial.print(count);
      Serial.println(" sec");
      Serial.print("Digital value :");
      Serial.println(digitalRead(PIEZO));
      Serial.print("Points :");
      Serial.println(points);
    }
    blinkBlue();
    delay(500);
    count++;
    if(count>10){
      resetLeds();
      if(points>1){ //to avoid sending message when switching on the device + to avoid false positive
        sendMessage();
      }else{
        digitalWrite(RED, HIGH);
      }
      delay(1000);
      resetLeds();
      count = 0;
      points = 0;
      sleepNow();// sleep function called here
    }
  
  
}

void sendMessage(){
  if(sigfoxOK){    
      unsigned int i;
      digitalWrite(BLUE, HIGH);
      msg[0] = board.batteryChk() * 10; 
      msg[1] = points;
      //Only if you want to check the software revision
      /*
      msg[2] = rev;
      msg[3] = armType;
      */
      //Send the message to sigfox
      if(!debug){
        SigFox.Send(msg, sizeof(msg));
        resetLeds();
        //@TODO Ask Atim why downlink doesn't work
        /*SigFox.Receive(&data, sizeof(data), 60000);
        if(data[i]){
          digitalWrite(GREEN, HIGH);
        }else{
          digitalWrite(RED, HIGH);
        }*/
      }
      resetLeds();
      digitalWrite(GREEN, HIGH);   
    }else{
      digitalWrite(RED, HIGH);
    } 
}

void blinkBlue(){
  if(blue){
    digitalWrite(BLUE, LOW);
    blue = false;
  }else{
    digitalWrite(BLUE, HIGH);
    blue = true;
  }
}

void resetLeds(){
  digitalWrite(GREEN, LOW);
  digitalWrite(BLUE, LOW);
  digitalWrite(RED, LOW);
}
Code snippet #2Plain text
{
    "data": {
        "frame": "{data}",
        "ID": "{device}",
        "battery": {customData#battery},
        "points": {customData#points}
    },
    "sdid": "theIdOfYourDeviceYouCopiedBefore",
    "type": "message"
}
Github
https://github.com/theairboard/TheAirBoard/tree/master/arduino/TheAirBoard
Github
https://github.com/luisomoreau/sigfox_connected_target_v2

Credits

Profile
Louis Moreau

Software Engineer - Program Manager at Sigfox Foundation

Contact

Replications

Did you replicate this project? Share it!

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

MicroPython to Python via SigFox and Azure IoT Hub
Intermediate
  • 218
  • 4

Protip

This is to show how to get messages from a SiPy to your computer via SigFox and Azure IoT Hub.

MKRFox1200 Weather Station
Intermediate
  • 6,820
  • 7

Full instructions

What if we built a small weather station lasting for about 6 months with 2x AA, talking to Internet and working anywhere with SIGFOX?

MKRFOX1200 Weather Monitor
Intermediate
  • 10,793
  • 16

Full instructions

Turn your MKRFOX1200 into a battery-powered weather monitor that you can deploy EVERYWHERE.

Solar Smart Greenhouse Using Vertical Aquaponic Towers
Intermediate
  • 9,463
  • 144

Work in progress

Feed your family with 22 sqm greenhousing by combining permaculture, aquaponic vertical towers and IoT.

Smart auto-dispensing pillbox
Intermediate
  • 3,548
  • 21

Creating a smart pillbox in collaboration with Samsung

Water Quality Monitoring using MKR1000 and ARTIK Cloud
Intermediate
  • 2,096
  • 19

Full instructions

Water quality data monitoring for swimming pools, fish aquarium and more!

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Feedback