Created
February 22, 2020 01:58
-
-
Save yoronneko/c9662f4388ee7929dac1fa40094d9c8f to your computer and use it in GitHub Desktop.
Measurement of temperature, humidity, air pressure, and accelerations with Sigfox Una Shield V2S
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
#include <SPI.h> | |
#include <Adafruit_Sensor.h> | |
#include <Adafruit_BME280.h> | |
#include <Adafruit_MMA8451.h> | |
#include <SIGFOX.h> | |
/* | |
#define BME_SCK 13 | |
#define BME_MISO 12 | |
#define BME_MOSI 11 | |
#define BME_CS 10 | |
*/ | |
Adafruit_BME280 bme; | |
Adafruit_MMA8451 mma = Adafruit_MMA8451(); | |
static const String device = ""; | |
static const bool useEmulator = false; | |
static const bool echo = true; | |
static const Country country = COUNTRY_JP; | |
static UnaShieldV2S transceiver(country, useEmulator, device, echo); | |
void setup() { | |
Serial.begin(9600); | |
if (!bme.begin(0x76)) stop("BME280 is missing."); | |
if (!mma.begin(0x1c)) stop("MMA8451 is missing."); | |
mma.setRange(MMA8451_RANGE_2_G); | |
if (!transceiver.begin()) stop("Unable to init SIGFOX module."); | |
} | |
void loop() { | |
float Temp = bme.readTemperature(); | |
float Press = bme.readPressure() / 100.0F; | |
float Humid = bme.readHumidity(); | |
sensors_event_t event; | |
mma.getEvent(&event); | |
float x = event.acceleration.x; | |
float y = event.acceleration.y; | |
float z = event.acceleration.z; | |
static int counter = 0; | |
word sTemp = Temp * 1.0; | |
word sHumid = Humid * 1.0; | |
word sPress = Press * 1.0; | |
word sx = x * 10.0; | |
word sy = y * 10.0; | |
word sz = z * 10.0; | |
Serial.print("Temp = "); Serial.print(sTemp); Serial.println(" degC"); | |
Serial.print("Humid = "); Serial.print(sHumid); Serial.println(" %"); | |
Serial.print("Press = "); Serial.print(sPress); Serial.println(" hPa"); | |
Serial.print("x = "); Serial.print(sx); Serial.println(" x 10^(-1) m/s^2"); | |
Serial.print("y = "); Serial.print(sy); Serial.println(" x 10^(-1) m/s^2"); | |
Serial.print("z = "); Serial.print(sz); Serial.println(" x 10^(-1) m/s^2"); | |
// format: | |
// temp::int:16:little-endian humid::int:16:little-endian \ | |
// press::int:16:little-endian x::int:16:little-endian \ | |
// y::int:16:little-endian z::int:16:little-endian | |
String msg = transceiver.toHex(sTemp) | |
+ transceiver.toHex(sHumid) | |
+ transceiver.toHex(sPress) | |
+ transceiver.toHex(sx) | |
+ transceiver.toHex(sy) | |
+ transceiver.toHex(sz) ; | |
Serial.println(msg); | |
if (!transceiver.sendMessage(msg)) Serial.println("Send failed."); | |
counter++; | |
Serial.println("Waiting 15 minutes..."); delay(900000); | |
} | |
/* | |
Temp = 25 degC | |
Humid = 35 % | |
Press = 990 hPa | |
x = 8 x 10^(-1) m/s^2 | |
y = 4 x 10^(-1) m/s^2 | |
z = 97 x 10^(-1) m/s^2 | |
19002300de03080004006100 | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment