Pārlūkot izejas kodu

log mqtt tx msgs. fix bug missing some ui toggles.

Thomas Buck 5 mēnešus atpakaļ
vecāks
revīzija
632d3971be
1 mainītis faili ar 33 papildinājumiem un 16 dzēšanām
  1. 33
    16
      src/mqtt.cpp

+ 33
- 16
src/mqtt.cpp Parādīt failu

@@ -98,7 +98,7 @@ static void mqttCallback(char* topic, byte* payload, unsigned int length) {
98 98
         ps += c;
99 99
     }
100 100
 
101
-    debug.print(F("MQTT Rx @ \""));
101
+    debug.print(F("MQTT <Rx  @ \""));
102 102
     debug.print(ts);
103 103
     debug.print(F("\" = \""));
104 104
     debug.print(ps);
@@ -241,24 +241,41 @@ void runMQTT() {
241 241
 #ifdef FEATURE_UI
242 242
 static struct ui_status prev_status = ui_status;
243 243
 
244
+static void mqttPublish(const char* ts, const char *ps, bool retained) {
245
+    debug.print(F("MQTT  Tx> @ \""));
246
+    debug.print(ts);
247
+    debug.print(F("\" = \""));
248
+    debug.print(ps);
249
+    debug.println(F("\""));
250
+    mqtt.publish(ts, ps, retained);
251
+}
252
+
244 253
 void writeMQTT_UI(void) {
245 254
     struct ui_status curr_status = ui_status;
255
+
246 256
     if (curr_status.light_amp != prev_status.light_amp) {
247
-        mqtt.publish("livingroom/light_amp", curr_status.light_amp ? "on" : "off", true);
248
-    } else if (curr_status.light_bench != prev_status.light_bench) {
249
-        mqtt.publish("livingroom/light_bench", curr_status.light_bench ? "on" : "off", true);
250
-    } else if (curr_status.light_box != prev_status.light_box) {
251
-        mqtt.publish("livingroom/light_box", curr_status.light_box ? "on" : "off", true);
252
-    } else if (curr_status.light_corner != prev_status.light_corner) {
253
-        mqtt.publish("livingroom/light_corner/cmnd/POWER", curr_status.light_corner ? "on" : "off", true);
254
-    } else if (curr_status.light_kitchen != prev_status.light_kitchen) {
255
-        mqtt.publish("livingroom/light_kitchen", curr_status.light_kitchen ? "on" : "off", true);
256
-    } else if (curr_status.light_pc != prev_status.light_pc) {
257
-        mqtt.publish("livingroom/light_pc", curr_status.light_pc ? "on" : "off", true);
258
-    } else if (curr_status.light_workspace != prev_status.light_workspace) {
259
-        mqtt.publish("livingroom/workbench/cmnd/POWER", curr_status.light_workspace ? "on" : "off", true);
260
-    } else if (curr_status.sound_amplifier != prev_status.sound_amplifier) {
261
-        mqtt.publish("livingroom/amp/cmnd/POWER", curr_status.sound_amplifier ? "on" : "off", true);
257
+        mqttPublish("livingroom/light_amp", curr_status.light_amp ? "on" : "off", true);
258
+    }
259
+    if (curr_status.light_bench != prev_status.light_bench) {
260
+        mqttPublish("livingroom/light_bench", curr_status.light_bench ? "on" : "off", true);
261
+    }
262
+    if (curr_status.light_box != prev_status.light_box) {
263
+        mqttPublish("livingroom/light_box", curr_status.light_box ? "on" : "off", true);
264
+    }
265
+    if (curr_status.light_corner != prev_status.light_corner) {
266
+        mqttPublish("livingroom/light_corner/cmnd/POWER", curr_status.light_corner ? "on" : "off", true);
267
+    }
268
+    if (curr_status.light_kitchen != prev_status.light_kitchen) {
269
+        mqttPublish("livingroom/light_kitchen", curr_status.light_kitchen ? "on" : "off", true);
270
+    }
271
+    if (curr_status.light_pc != prev_status.light_pc) {
272
+        mqttPublish("livingroom/light_pc", curr_status.light_pc ? "on" : "off", true);
273
+    }
274
+    if (curr_status.light_workspace != prev_status.light_workspace) {
275
+        mqttPublish("livingroom/workbench/cmnd/POWER", curr_status.light_workspace ? "on" : "off", true);
276
+    }
277
+    if (curr_status.sound_amplifier != prev_status.sound_amplifier) {
278
+        mqttPublish("livingroom/amp/cmnd/POWER", curr_status.sound_amplifier ? "on" : "off", true);
262 279
     }
263 280
 
264 281
     prev_status = curr_status;

Notiek ielāde…
Atcelt
Saglabāt