|
|
@@ -502,19 +502,19 @@ void checkBootButton() {
|
|
|
// 状态 LED
|
|
|
// =====================================================
|
|
|
|
|
|
-unsigned long lastStatusLedToggle = 0;
|
|
|
-bool statusLedState = false;
|
|
|
-
|
|
|
void updateStatusLed() {
|
|
|
- bool connected = (useMQTT && wifiConnected) ? (WiFi.status() == WL_CONNECTED) : bleDeviceConnected;
|
|
|
- if (connected) {
|
|
|
- digitalWrite(STATUS_PIN, LOW);
|
|
|
- return;
|
|
|
- }
|
|
|
- if (millis() - lastStatusLedToggle >= 500) {
|
|
|
- statusLedState = !statusLedState;
|
|
|
- digitalWrite(STATUS_PIN, statusLedState ? LOW : HIGH);
|
|
|
- lastStatusLedToggle = millis();
|
|
|
+ if (useMQTT) {
|
|
|
+ if (wifiConnected) {
|
|
|
+ digitalWrite(STATUS_PIN, LOW);
|
|
|
+ } else {
|
|
|
+ digitalWrite(STATUS_PIN, HIGH);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (bleDeviceConnected) {
|
|
|
+ digitalWrite(STATUS_PIN, LOW);
|
|
|
+ } else {
|
|
|
+ digitalWrite(STATUS_PIN, HIGH);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -657,7 +657,10 @@ bool connectMQTT() {
|
|
|
}
|
|
|
|
|
|
void checkMQTTConnection() {
|
|
|
- if (useMQTT && !mqttClient.connected()) { Serial.println("MQTT reconnecting..."); connectMQTT(); }
|
|
|
+ if (useMQTT && !mqttClient.connected()) {
|
|
|
+ Serial.println("MQTT reconnecting...");
|
|
|
+ connectMQTT();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -717,6 +720,7 @@ void loop() {
|
|
|
if (useMQTT && wifiConnected) {
|
|
|
if (WiFi.status() != WL_CONNECTED) {
|
|
|
Serial.println("WiFi lost, reconnecting...");
|
|
|
+ wifiConnected = false;
|
|
|
wifiConnected = connectWiFi();
|
|
|
if (!wifiConnected) {
|
|
|
Serial.println("WiFi failed. BLE config mode active.");
|