Commit 78d53f38 authored by Eric Duminil's avatar Eric Duminil
Browse files

Not sending MQTT if inactive

parent afa49c20
Pipeline #5772 passed with stage
in 2 minutes and 8 seconds
......@@ -11,15 +11,11 @@
// Needed for offline config too.
#include "web_config.h"
#ifdef AMPEL_CSV
# include "csv_writer.h"
#endif
#include "csv_writer.h"
#ifdef AMPEL_WIFI
# include "wifi_util.h"
# ifdef AMPEL_MQTT
# include "mqtt.h"
# endif
# include "mqtt.h"
# ifdef AMPEL_HTTP
# include "web_server.h"
# endif
......
......@@ -79,9 +79,9 @@ void setup() {
ntp::initialize();
# ifdef AMPEL_MQTT
mqtt::initialize(ampel.sensorId);
# endif
if (config::mqtt_active()) {
mqtt::initialize(ampel.sensorId);
}
Serial.print(F("You can access this sensor via http://"));
Serial.print(ampel.sensorId);
......@@ -166,8 +166,10 @@ void loop() {
csv_writer::logIfTimeHasCome(sensor::timestamp, sensor::co2, sensor::temperature, sensor::humidity);
#endif
#if defined(AMPEL_WIFI) && defined(AMPEL_MQTT)
mqtt::publishIfTimeHasCome(sensor::timestamp, sensor::co2, sensor::temperature, sensor::humidity);
#if defined(AMPEL_WIFI)
if (config::mqtt_active()) {
mqtt::publishIfTimeHasCome(sensor::timestamp, sensor::co2, sensor::temperature, sensor::humidity);
}
#endif
#if defined(AMPEL_LORAWAN) && defined(ESP32)
......@@ -220,9 +222,9 @@ void keepServicesAlive() {
web_config::update();
if (wifi::connected()) {
ntp::update(); // NTP client has its own timer. It will connect to NTP server every 60s.
# ifdef AMPEL_MQTT
mqtt::keepConnection(); // MQTT client has its own timer. It will keep alive every 15s.
# endif
if (config::mqtt_active()) {
mqtt::keepConnection(); // MQTT client has its own timer. It will keep alive every 15s.
}
}
#endif
}
......@@ -42,8 +42,6 @@ namespace mqtt {
char last_successful_publish[23] = "";
void initialize(const char *sensorId) {
Serial.print("MQTT ? ");
Serial.println(config::mqtt_active());
json_sensor_format = PSTR("{\"time\":\"%s\", \"co2\":%d, \"temp\":%.1f, \"rh\":%.1f}");
snprintf(publish_topic, sizeof(publish_topic), "CO2sensors/%s", sensorId);
#if MQTT_ENCRYPTED
......
......@@ -8,7 +8,7 @@
# define esp_get_heap_fragmentation() ESP.getHeapFragmentation()
#elif defined(ESP32)
# define esp_get_max_free_block_size() ESP.getMaxAllocHeap() //largest block of heap that can be allocated.
# define esp_get_heap_fragmentation() "?" // apparently not available for ESP32
# define esp_get_heap_fragmentation() -1 // apparently not available for ESP32
#endif
namespace util {
......
......@@ -10,9 +10,7 @@
#ifdef AMPEL_CSV
# include "csv_writer.h"
#endif
#ifdef AMPEL_MQTT
# include "mqtt.h"
#endif
#include "mqtt.h"
#ifdef AMPEL_LORAWAN
# include "lorawan.h"
#endif
......@@ -112,12 +110,10 @@ namespace web_server {
"<tr><td>Timestep</td><td>%5d s</td></tr>\n"
"<tr><td>Available drive space</td><td>%d kB</td></tr>\n"
#endif
#ifdef AMPEL_MQTT
"<tr><th colspan='2'>MQTT</th></tr>\n"
"<tr><td>Connected?</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"
#endif
#if defined(AMPEL_LORAWAN) && defined(ESP32)
"<tr><th colspan='2'>LoRaWAN</th></tr>\n"
"<tr><td>Connected?</td><td>%s</td></tr>\n"
......@@ -249,9 +245,7 @@ namespace web_server {
#ifdef AMPEL_CSV
csv_writer::last_successful_write, config::csv_interval, csv_writer::getAvailableSpace() / 1024,
#endif
#ifdef AMPEL_MQTT
mqtt::connected ? "Yes" : "No", mqtt::last_successful_publish, config::mqtt_sending_interval,
#endif
#if defined(AMPEL_LORAWAN) && defined(ESP32)
lorawan::connected ? "Yes" : "No", config::lorawan_frequency_plan, lorawan::last_transmission,
config::lorawan_sending_interval,
......
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