Commit 3cf93f02 authored by Eric Duminil's avatar Eric Duminil
Browse files

LoRaWAN seems to work on ESP32

parent c594f2d1
......@@ -10,6 +10,9 @@
#ifdef MQTT
# include "mqtt.h"
#endif
#ifdef LORAWAN
# include "lorawan.h"
#endif
#include "util.h"
#include "wifi_util.h"
......
......@@ -99,7 +99,12 @@ void setup() {
mqtt::initialize("CO2sensors/" + SENSOR_ID);
#endif
}
csv_writer::initialize();
#ifdef LORAWAN
lorawan::initialize();
#endif
}
/*****************************************************************
......@@ -107,6 +112,15 @@ void setup() {
*****************************************************************/
void loop() {
#ifdef LORAWAN
//LMIC Library seems to be very sensitive to timing issues, so run it first.
lorawan::process();
if (lorawan::waiting_for_confirmation) {
// If node is waiting for join confirmation from Gateway, nothing else should run.
return;
}
#endif
//NOTE: Loop should never take more than 1000ms. Split in smaller methods and logic if needed.
//TODO: Restart every day or week, in order to not let t0 overflow?
uint32_t t0 = millis();
......
......@@ -175,11 +175,17 @@ namespace sensor {
}
logToSerial();
//TODO: Move the 3 back to ampel-firmware.ino and remove headers from co2_sensor.h
csv_writer::logIfTimeHasCome(timestamp, co2, temperature, humidity);
#ifdef MQTT
mqtt::publishIfTimeHasCome(timestamp, co2, temperature, humidity);
#endif
#ifdef LORAWAN
lorawan::preparePayloadIfTimehasCome();
#endif
}
if (should_calibrate) {
......
......@@ -13,6 +13,9 @@
#ifdef MQTT
# include "mqtt.h"
#endif
#ifdef LORAWAN
# include "lorawan.h"
#endif
namespace config {
extern uint16_t measurement_timestep; // [s] Value between 2 and 1800 (range for SCD30 sensor)
......
......@@ -24,6 +24,8 @@ namespace ntp {
String getLocalTime();
}
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define seconds() (millis() / 1000UL)
extern uint32_t max_loop_duration;
const extern String SENSOR_ID;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment