Commit 1575b514 authored by Eric Duminil's avatar Eric Duminil
Browse files

Is lorawan active?

parent 07ebc466
Pipeline #5777 passed with stage
in 2 minutes and 15 seconds
...@@ -21,9 +21,7 @@ ...@@ -21,9 +21,7 @@
# endif # endif
#endif #endif
#ifdef AMPEL_LORAWAN #include "lorawan.h"
# include "lorawan.h"
#endif
#include "util.h" #include "util.h"
#include "ntp.h" #include "ntp.h"
......
...@@ -122,8 +122,10 @@ void setup() { ...@@ -122,8 +122,10 @@ void setup() {
# endif # endif
#endif #endif
#if defined(AMPEL_LORAWAN) && defined(ESP32) #if defined(ESP32)
if (config::lorawan_active()) {
lorawan::initialize(); lorawan::initialize();
}
#endif #endif
} }
...@@ -138,7 +140,8 @@ void checkSerialInput(); ...@@ -138,7 +140,8 @@ void checkSerialInput();
* Main loop * * Main loop *
*****************************************************************/ *****************************************************************/
void loop() { void loop() {
#if defined(AMPEL_LORAWAN) && defined(ESP32) #if defined(ESP32)
if (config::lorawan_active()) {
//LMIC Library seems to be very sensitive to timing issues, so run it first. //LMIC Library seems to be very sensitive to timing issues, so run it first.
lorawan::process(); lorawan::process();
...@@ -146,6 +149,7 @@ void loop() { ...@@ -146,6 +149,7 @@ void loop() {
// If node is waiting for join confirmation from Gateway, nothing else should run. // If node is waiting for join confirmation from Gateway, nothing else should run.
return; return;
} }
}
#endif #endif
//NOTE: Loop should never take more than 1000ms. Split in smaller methods and logic if needed. //NOTE: Loop should never take more than 1000ms. Split in smaller methods and logic if needed.
//NOTE: Only use millis() for duration comparison, not timestamps comparison. Otherwise, problems happen when millis roll over. //NOTE: Only use millis() for duration comparison, not timestamps comparison. Otherwise, problems happen when millis roll over.
...@@ -170,8 +174,10 @@ void loop() { ...@@ -170,8 +174,10 @@ void loop() {
} }
#endif #endif
#if defined(AMPEL_LORAWAN) && defined(ESP32) #if defined(ESP32)
if (config::lorawan_active()) {
lorawan::preparePayloadIfTimeHasCome(sensor::co2, sensor::temperature, sensor::humidity); lorawan::preparePayloadIfTimeHasCome(sensor::co2, sensor::temperature, sensor::humidity);
}
#endif #endif
} }
......
#include "lorawan.h" #include "lorawan.h"
#if defined(AMPEL_LORAWAN) && defined(ESP32) #if defined(ESP32)
#include "led_effects.h" #include "led_effects.h"
#include "sensor_console.h" #include "sensor_console.h"
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include "config.h" #include "config.h"
# if defined(AMPEL_LORAWAN) && defined(ESP32) # if defined(ESP32)
#include <stdint.h> // For uint32_t & uint16_t #include <stdint.h> // For uint32_t & uint16_t
......
...@@ -67,6 +67,7 @@ namespace web_config { ...@@ -67,6 +67,7 @@ namespace web_config {
/** /**
* LED * LED
*/ */
//NOTE: Could also be optional : for LED 0 / 1
ParameterGroup ledParams = ParameterGroup("LED", "LED"); ParameterGroup ledParams = ParameterGroup("LED", "LED");
IntTParameter<uint8_t> maxBrightnessParam = IntTParameter<uint8_t> maxBrightnessParam =
...@@ -81,10 +82,6 @@ namespace web_config { ...@@ -81,10 +82,6 @@ namespace web_config {
// # define HTTP_USER "co2ampel" // # define HTTP_USER "co2ampel"
// # define HTTP_PASSWORD "my_password" // # define HTTP_PASSWORD "my_password"
// WARNING: If AMPEL_LORAWAN is enabled, you need to modify the 3 following constants!
// This EUI must be in little-endian format, so least-significant-byte first.
// When copying an EUI from ttnctl output, this means to reverse the bytes.
/** /**
* CSV * CSV
*/ */
...@@ -134,13 +131,10 @@ namespace web_config { ...@@ -134,13 +131,10 @@ namespace web_config {
CheckboxTParameter dstParam = CheckboxTParameter dstParam =
Builder<CheckboxTParameter>("dst").label("Daylight Saving Time?").defaultValue(false).build(); Builder<CheckboxTParameter>("dst").label("Daylight Saving Time?").defaultValue(false).build();
/**
* LED
*/
/** /**
* LoRa & Stuff * LoRa & Stuff
*/ */
#if defined(ESP32)
OptionalParameterGroup loraParams = OptionalParameterGroup("LoRaWan", "LoRaWan", AMPEL_LORAWAN); OptionalParameterGroup loraParams = OptionalParameterGroup("LoRaWan", "LoRaWan", AMPEL_LORAWAN);
IntTParameter<uint16_t> loraTimestepParam = IntTParameter<uint16_t> loraTimestepParam =
Builder<IntTParameter<uint16_t>>("lora_timestep").label("LoRa timestep").defaultValue( Builder<IntTParameter<uint16_t>>("lora_timestep").label("LoRa timestep").defaultValue(
...@@ -152,6 +146,7 @@ namespace web_config { ...@@ -152,6 +146,7 @@ namespace web_config {
Builder<TextTParameter<17>>("app_eui").label("App EUI").defaultValue("00EA07...").build(); Builder<TextTParameter<17>>("app_eui").label("App EUI").defaultValue("00EA07...").build();
TextTParameter<32> appKeyParam = TextTParameter<32> appKeyParam =
Builder<TextTParameter<32>>("app_key").label("App key").defaultValue("81CCFE...").build(); Builder<TextTParameter<32>>("app_key").label("App key").defaultValue("81CCFE...").build();
#endif
OptionalGroupHtmlFormatProvider optionalGroupHtmlFormatProvider; OptionalGroupHtmlFormatProvider optionalGroupHtmlFormatProvider;
...@@ -202,18 +197,21 @@ namespace web_config { ...@@ -202,18 +197,21 @@ namespace web_config {
mqttParams.addItem(&mqttEncryptionParam); mqttParams.addItem(&mqttEncryptionParam);
mqttParams.addItem(&mqttCommandsParam); mqttParams.addItem(&mqttCommandsParam);
//TODO: Only for ESP32 #if defined(ESP32)
loraParams.addItem(&loraTimestepParam); loraParams.addItem(&loraTimestepParam);
loraParams.addItem(&deviceEUIParam); loraParams.addItem(&deviceEUIParam);
loraParams.addItem(&appEUIParam); loraParams.addItem(&appEUIParam);
loraParams.addItem(&appKeyParam); loraParams.addItem(&appKeyParam);
#endif
iotWebConf->addParameterGroup(&co2Params); iotWebConf->addParameterGroup(&co2Params);
iotWebConf->addParameterGroup(&ledParams); iotWebConf->addParameterGroup(&ledParams);
iotWebConf->addParameterGroup(&timeParams); iotWebConf->addParameterGroup(&timeParams);
iotWebConf->addParameterGroup(&csvParams); iotWebConf->addParameterGroup(&csvParams);
iotWebConf->addParameterGroup(&mqttParams); iotWebConf->addParameterGroup(&mqttParams);
#if defined(ESP32)
iotWebConf->addParameterGroup(&loraParams); iotWebConf->addParameterGroup(&loraParams);
#endif
sensor_console::defineCommand("reset_config", []() { sensor_console::defineCommand("reset_config", []() {
Serial.println(F("Resetting config...")); Serial.println(F("Resetting config..."));
...@@ -304,4 +302,11 @@ namespace config { ...@@ -304,4 +302,11 @@ namespace config {
uint16_t &mqtt_sending_interval = web_config::mqttTimestepParam.value(); uint16_t &mqtt_sending_interval = web_config::mqttTimestepParam.value();
bool &mqtt_encryption = web_config::mqttEncryptionParam.value(); bool &mqtt_encryption = web_config::mqttEncryptionParam.value();
bool &allow_mqtt_commands = web_config::mqttCommandsParam.value(); bool &allow_mqtt_commands = web_config::mqttCommandsParam.value();
// LORAWAN
#if defined(ESP32)
bool lorawan_active() {
return web_config::loraParams.isActive();
}
#endif
} }
...@@ -40,6 +40,11 @@ namespace config { ...@@ -40,6 +40,11 @@ namespace config {
extern uint16_t &mqtt_sending_interval; // [s] extern uint16_t &mqtt_sending_interval; // [s]
extern bool &mqtt_encryption; // [true / false] extern bool &mqtt_encryption; // [true / false]
extern bool &allow_mqtt_commands; // [true / false] extern bool &allow_mqtt_commands; // [true / false]
// LORAWAN
#if defined(ESP32)
bool lorawan_active(); // also defined for ESP8266, and set to false
#endif
} }
namespace web_config { namespace web_config {
......
...@@ -9,9 +9,7 @@ ...@@ -9,9 +9,7 @@
#include "sensor_console.h" #include "sensor_console.h"
#include "csv_writer.h" #include "csv_writer.h"
#include "mqtt.h" #include "mqtt.h"
#ifdef AMPEL_LORAWAN #include "lorawan.h"
# include "lorawan.h"
#endif
#include <IotWebConf.h> #include <IotWebConf.h>
#include <IotWebConfUsing.h> // This loads aliases for easier class names. #include <IotWebConfUsing.h> // This loads aliases for easier class names.
...@@ -106,7 +104,7 @@ namespace web_server { ...@@ -106,7 +104,7 @@ namespace web_server {
"<tr><td>Connected?</td><td>%s</td></tr>\n" "<tr><td>Connected?</td><td>%s</td></tr>\n"
"<tr><td>Last publish</td><td>%s</td></tr>\n" "<tr><td>Last publish</td><td>%s</td></tr>\n"
"<tr><td>Timestep</td><td>%5d s</td></tr>\n" "<tr><td>Timestep</td><td>%5d s</td></tr>\n"
#if defined(AMPEL_LORAWAN) && defined(ESP32) #if defined(ESP32)
"<tr><th colspan='2'>LoRaWAN</th></tr>\n" "<tr><th colspan='2'>LoRaWAN</th></tr>\n"
"<tr><td>Connected?</td><td>%s</td></tr>\n" "<tr><td>Connected?</td><td>%s</td></tr>\n"
"<tr><td>Frequency</td><td>%s MHz</td></tr>\n" "<tr><td>Frequency</td><td>%s MHz</td></tr>\n"
...@@ -227,7 +225,7 @@ namespace web_server { ...@@ -227,7 +225,7 @@ namespace web_server {
sensor::humidity, sensor::timestamp, config::measurement_timestep, csv_writer::last_successful_write, sensor::humidity, sensor::timestamp, config::measurement_timestep, csv_writer::last_successful_write,
config::csv_interval, csv_writer::getAvailableSpace() / 1024, mqtt::connected ? "Yes" : "No", config::csv_interval, csv_writer::getAvailableSpace() / 1024, mqtt::connected ? "Yes" : "No",
mqtt::last_successful_publish, config::mqtt_sending_interval, mqtt::last_successful_publish, config::mqtt_sending_interval,
#if defined(AMPEL_LORAWAN) && defined(ESP32) #if defined(ESP32)
lorawan::connected ? "Yes" : "No", config::lorawan_frequency_plan, lorawan::last_transmission, lorawan::connected ? "Yes" : "No", config::lorawan_frequency_plan, lorawan::last_transmission,
config::lorawan_sending_interval, config::lorawan_sending_interval,
#endif #endif
......
Markdown is supported
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