fixed auto reconnect and resubscribe inside mqtt wrapper loop
This commit is contained in:
13
src/main.cpp
13
src/main.cpp
@@ -34,12 +34,11 @@ void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
LOG_ATTACH_SERIAL(Serial);
|
||||
conf.init();
|
||||
conf.init(); // read the configuration from internal flash
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
const uint8_t baseRegister(0x00);
|
||||
uint16_t k(0);
|
||||
uint8_t sensors(0);
|
||||
bool buzzing(false);
|
||||
@@ -66,10 +65,17 @@ void loop()
|
||||
auto mqtt = MQTTwrapper();
|
||||
//////////////// NETWORK ////////////////
|
||||
|
||||
std::function<void(const ArduinoJson::JsonDocument &)> mycallback =
|
||||
[&io](const ArduinoJson::JsonDocument &doc) {
|
||||
io.digitalIOWrite(0, doc["stat"].as<bool>());
|
||||
io.digitalIOWrite(15, doc["stat"].as<bool>());
|
||||
};
|
||||
|
||||
|
||||
//////////////// NETWORK ////////////////
|
||||
/////////////// CALLBACK ////////////////
|
||||
Network.onEvent(
|
||||
[ð, &rtc, &mqtt, &buzzer, &led](arduino_event_id_t event, arduino_event_info_t info) -> void
|
||||
[ð, &rtc, &mqtt, &buzzer, &led, &mycallback](arduino_event_id_t event, arduino_event_info_t info) -> void
|
||||
{
|
||||
eth.onEvent(event, info); // Arduino Ethernet event handler
|
||||
if (!eth.isConnected())
|
||||
@@ -95,6 +101,7 @@ void loop()
|
||||
if (mqtt.connect())
|
||||
{
|
||||
mqtt.subscribe("test/esp32-in", testAction);
|
||||
mqtt.subscribe("test/esp32-functional", mycallback);
|
||||
break;
|
||||
}
|
||||
delay(100);
|
||||
|
||||
Reference in New Issue
Block a user