Nicolas Lesconnec
Published © GPL3+

Sigfox & Arduino Weather Station

An Arduino weather station, communicating over the Sigfox network.

BeginnerFull instructions provided4,453
Sigfox & Arduino Weather Station

Things used in this project

Hardware components

Akeru [by Snootlab]
×1
Adafruit BME280 - Temperature Humidity Pressure Sensor
×1

Story

Read more

Schematics

Wiring

Code

Arduino sketch

Arduino
#include <Akeru.h>
#include <BME280_MOD-1022.h>
#include <SoftwareSerial.h>
#include <Wire.h>

//Data structure for Sigfox data to populate, and then send
typedef struct {  
  int BMEPres;
  int BMETemp;
  int BMEHumid;
} Payload;

  
void printFormattedFloat(float x, uint8_t precision) {
char buffer[10];
  dtostrf(x, 7, precision, buffer);
  Serial.print(buffer);
}

// Setup Wire and Serial
void setup()
{
  Wire.begin();
  Akeru.begin();   Serial.println("Sigfox Modem");
  Akeru.setPower(4); Serial.println("Max Modem Power");
  Serial.begin(115200);
}

// main loop
void loop()
{
  // need to read the NVM compensation parameters
  BME280.readCompensationParams();
  
  // Need to turn on 1x oversampling, default is os_skipped, which means it doesn't measure anything
  BME280.writeOversamplingPressure(os1x);  // 1x over sampling (ie, just one sample)
  BME280.writeOversamplingTemperature(os1x);
  BME280.writeOversamplingHumidity(os1x);
  
  // example of a forced sample.  After taking the measurement the chip goes back to sleep
  BME280.writeMode(smForced);
  while (BME280.isMeasuring()) {
    Serial.println("Measuring...");
    delay(50);
  }
  Serial.println("Measure done !");
  
  
  Akeru.begin();   Serial.println("Modem SigFox initialised");
  Akeru.setPower(4); Serial.println("Maximum transmit power");
  
  BME280.readMeasurements();
  Payload p;
  p.BMEPres=BME280.getPressure();
  p.BMETemp=BME280.getTemperature();
  p.BMEHumid=BME280.getHumidity();
  
  // Example for "indoor navigation"
  // We'll switch into normal mode for regular automatic samples
  BME280.writeStandbyTime(tsb_0p5ms);        // tsb = 0.5ms
  BME280.writeFilterCoefficient(fc_16);      // IIR Filter coefficient 16
  BME280.writeOversamplingPressure(os16x);    // pressure x16
  BME280.writeOversamplingTemperature(os2x);  // temperature x2
  BME280.writeOversamplingHumidity(os1x);     // humidity x1
  
  BME280.writeMode(smNormal);
   
  while (1) {
    while (BME280.isMeasuring()) {
    }
    
    // read out the data - must do this before calling the getxxxxx routines
    BME280.readMeasurements();
    
   Serial.println(" -> Sigfox sending ...\r\n");
   byte cmd = Serial.read();
      while (!Akeru.isReady()) {
          Serial.println("Modem not ready-");
          delay(1000);
        }
  Serial.println("Values : Pressure/Temperature/Humidity");
  Serial.println(p.BMEPres);
  Serial.println(p.BMETemp);
  Serial.println(p.BMEHumid);
  
        delay(1000);
        Akeru.send(&p, sizeof(p)); //Sending the data via the modem
        Serial.println("Sent");
        digitalWrite(13, HIGH);
        delay(1000);               // wait for a second
        digitalWrite(13, LOW); 
        
        ////  Wait for 10 min.
        for (int second = 0; second < 160; second++) {
          delay(1000);
        }
   }
}

Credits

adrien3d

Thanks to adrien3d.

Comments