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

Maker Intern @ Sigfox

Replications

Did you replicate this project? Share it!

I made one

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

Give feedback

Comments

Similar projects you might like

Face Lock Deadbolts
Intermediate
  • 1,206
  • 12

Work in progress

Using 3D RealSense facial recognition to unlock deadbolt doors through ARTIK Cloud

Smart auto-dispensing pillbox
Intermediate
  • 2,830
  • 21

Creating a smart pillbox in collaboration with Samsung

Water Quality Monitoring using MKR1000 and ARTIK Cloud
Intermediate
  • 1,403
  • 17

Full instructions

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

Publish Hexiwear sensor data onto ARTIK with Evothings
Intermediate
  • 465
  • 7

Full instructions

With Evothings, you can publish Hexiwear sensors onto ARTIK cloud uisng Javascript.

ARTIK + MKR1000 + DHT11 + MQTT
Intermediate
  • 1,462
  • 9

Full instructions

An IOT app which make uses of ARTIK Cloud, Genuino MKR1000, DHT11 temperature and humidity sensor and MQTT protocol.

Cold Chain Monitoring and Smart Tracking
Intermediate
  • 498
  • 8

Work in progress

IoT based solution for control the temperature and make delivery of temperature sensitive perishable products more efficient

ProjectsCommunitiesContestsLiveJobsBetaFree StoreBlogAdd projectSign up / Login
Respect project