use blue led to indicate mqtt connectivity

This commit is contained in:
Nicu Hodos 2024-05-18 09:45:17 +02:00
parent 22add7aea8
commit ddbefdae5d
2 changed files with 13 additions and 8 deletions

View File

@ -3,7 +3,7 @@
#define SEND_PIN 12
#define RECEIVE_PIN 13
#define RED_LED LED_BUILTIN
// #define BLUE_LED 2
#define BLUE_LED 2
using namespace std;
@ -17,6 +17,10 @@ mapswitches onSwitches;
mapswitches offSwitches;
unordered_map<string, Ha::Switch*> p1Switches;
void turnLed(uint8_t led, bool on = true) {
on ? digitalWrite(led, LOW) : digitalWrite(led, HIGH);
}
#include "wifi.h"
namespace Board {
@ -28,19 +32,18 @@ namespace Board {
}
}, &ts);
void turnOffLed(uint8_t led) {
digitalWrite(led, HIGH);
}
void setup() {
// Serial.begin(9600, SERIAL_8N1, SERIAL_TX_ONLY);
pinMode(RED_LED, OUTPUT);
turnOffLed(RED_LED);
// pinMode(BLUE_LED, OUTPUT);
// turnOffLed(BLUE_LED);
pinMode(BLUE_LED, OUTPUT);
turnLed(RED_LED, false);
turnLed(BLUE_LED);
Wifi::setup();
Ota::setup();
Mqtt::setup();
tReadCommand.enable();
}

View File

@ -55,10 +55,12 @@ namespace Mqtt {
client.subscribe(mainTopic, 0);
tReConnect.disable();
Serial.println("Connected to MQTT");
turnLed(BLUE_LED, false);
});
client.onDisconnect([](AsyncMqttClientDisconnectReason reason) {
tReConnect.enableDelayed();
Serial.println("Disconnected from MQTT");
turnLed(BLUE_LED);
});
client.onMessage(onMessage);
client.setServer(MQTT_HOST, MQTT_PORT);