Quellcode durchsuchen

Added debug log output to web with history buffer

Thomas Buck vor 3 Jahren
Ursprung
Commit
2e2bf09f49
10 geänderte Dateien mit 215 neuen und 71 gelöschten Zeilen
  1. 36
    0
      include/DebugLog.h
  2. 3
    1
      include/WifiStuff.h
  3. 2
    0
      platformio.ini
  4. 61
    0
      src/DebugLog.cpp
  5. 31
    28
      src/Functionality.cpp
  6. 8
    4
      src/Keymatrix.cpp
  7. 11
    10
      src/Plants.cpp
  8. 3
    2
      src/Statemachine.cpp
  9. 51
    18
      src/WifiStuff.cpp
  10. 9
    8
      src/main.cpp

+ 36
- 0
include/DebugLog.h Datei anzeigen

@@ -0,0 +1,36 @@
1
+#ifndef _DEBUG_LOG_H_
2
+#define _DEBUG_LOG_H_
3
+
4
+#include <Arduino.h>
5
+
6
+#ifdef PLATFORM_ESP
7
+#include <CircularBuffer.h>
8
+#define DEBUG_LOG_HISTORY_SIZE 1024
9
+#endif // PLATFORM_ESP
10
+
11
+class DebugLog {
12
+public:
13
+#ifdef PLATFORM_ESP
14
+    String getBuffer(void);
15
+#endif // PLATFORM_ESP
16
+    
17
+    void print(String s);
18
+    void print(int n);
19
+    
20
+    void println(void);
21
+    void println(String s);
22
+    void println(int n);
23
+    
24
+private:
25
+    void sendToTargets(String s);
26
+    
27
+#ifdef PLATFORM_ESP
28
+    void addToBuffer(String s);
29
+    
30
+    CircularBuffer<char, DEBUG_LOG_HISTORY_SIZE> buffer;
31
+#endif // PLATFORM_ESP
32
+};
33
+
34
+extern DebugLog debug;
35
+
36
+#endif // _DEBUG_LOG_H_

+ 3
- 1
include/WifiStuff.h Datei anzeigen

@@ -8,7 +8,9 @@ void wifi_run();
8 8
 
9 9
 void wifi_set_message_buffer(String a, String b, String c, String d);
10 10
 void wifi_schedule_websocket(void);
11
-void wifi_send_websocket(void);
11
+void wifi_send_status_broadcast(void);
12
+
13
+void wifi_send_websocket(String s);
12 14
 
13 15
 #endif
14 16
 

+ 2
- 0
platformio.ini Datei anzeigen

@@ -19,6 +19,7 @@ build_flags = -D PLATFORM_ESP -D FUNCTION_CONTROL
19 19
 lib_deps =
20 20
     Wire
21 21
     https://github.com/Links2004/arduinoWebSockets
22
+    https://github.com/rlogiacco/CircularBuffer
22 23
 
23 24
 [env:esp32_main]
24 25
 platform = espressif32
@@ -30,6 +31,7 @@ upload_port = /dev/ttyUSB1
30 31
 lib_deps =
31 32
     Wire
32 33
     https://github.com/Links2004/arduinoWebSockets
34
+    https://github.com/rlogiacco/CircularBuffer
33 35
 
34 36
 [env:arduino_ui]
35 37
 platform = atmelavr

+ 61
- 0
src/DebugLog.cpp Datei anzeigen

@@ -0,0 +1,61 @@
1
+#include <Arduino.h>
2
+
3
+#ifdef PLATFORM_ESP
4
+#include "WifiStuff.h"
5
+#endif // PLATFORM_ESP
6
+
7
+#include "DebugLog.h"
8
+
9
+DebugLog debug;
10
+
11
+#ifdef PLATFORM_ESP
12
+
13
+String DebugLog::getBuffer(void) {
14
+    String r;
15
+    for (unsigned int i = 0; i < buffer.size(); i++) {
16
+        r += buffer[i];
17
+    }
18
+    return r;
19
+}
20
+
21
+void DebugLog::addToBuffer(String s) {
22
+    for (unsigned int i = 0; i < s.length(); i++) {
23
+        buffer.push(s[i]);
24
+    }
25
+}
26
+
27
+#endif // PLATFORM_ESP
28
+
29
+void DebugLog::sendToTargets(String s) {
30
+    Serial.print(s);
31
+    
32
+#ifdef PLATFORM_ESP
33
+    s = "log:" + s;
34
+    wifi_send_websocket(s);
35
+#endif // PLATFORM_ESP
36
+}
37
+
38
+void DebugLog::print(String s) {
39
+#ifdef PLATFORM_ESP
40
+    addToBuffer(s);
41
+#endif // PLATFORM_ESP
42
+    
43
+    sendToTargets(s);
44
+}
45
+
46
+void DebugLog::print(int n) {
47
+    print(String(n));
48
+}
49
+
50
+void DebugLog::println(void) {
51
+    print(String('\n'));
52
+}
53
+
54
+void DebugLog::println(String s) {
55
+    s += '\n';
56
+    print(s);
57
+}
58
+
59
+void DebugLog::println(int n) {
60
+    println(String(n));
61
+}

+ 31
- 28
src/Functionality.cpp Datei anzeigen

@@ -2,6 +2,7 @@
2 2
 
3 3
 #include "config.h"
4 4
 #include "config_pins.h"
5
+#include "DebugLog.h"
5 6
 #include "Functionality.h"
6 7
 
7 8
 #ifdef FUNCTION_UI
@@ -199,7 +200,7 @@ void ui_i2c_request(void) {
199 200
         return;
200 201
     }
201 202
     
202
-    Serial.print("ui_i2c_request: ");
203
+    debug.print("ui_i2c_request: ");
203 204
     
204 205
     while (!keybuffer.isEmpty()) {
205 206
         int n = keybuffer.shift();
@@ -211,13 +212,13 @@ void ui_i2c_request(void) {
211 212
             n = -3;
212 213
         }
213 214
         
214
-        Serial.print(n);
215
-        Serial.print(", ");
215
+        debug.print(n);
216
+        debug.print(", ");
216 217
         
217 218
         Wire.write(n);
218 219
     }
219 220
     
220
-    Serial.println();
221
+    debug.println();
221 222
 }
222 223
 
223 224
 void ui_i2c_receive(int count) {
@@ -231,27 +232,27 @@ void ui_i2c_receive(int count) {
231 232
     }
232 233
     
233 234
     if (count <= 0) {
234
-        Serial.println("ui_i2c_receive: count is 0");
235
+        debug.println("ui_i2c_receive: count is 0");
235 236
         return;
236 237
     }
237 238
     
238 239
     if (buff[0] == 0x01) {
239 240
         if (count < 3) {
240
-            Serial.println("ui_i2c_receive: blink lcd too short");
241
+            debug.println("ui_i2c_receive: blink lcd too short");
241 242
             return;
242 243
         }
243 244
         
244 245
         int n = buff[1];
245 246
         int wait = buff[2] * 10;
246 247
         
247
-        Serial.println("ui_i2c_receive: blink lcd command");
248
+        debug.println("ui_i2c_receive: blink lcd command");
248 249
         blink_lcd(n, wait);
249 250
     } else if (buff[0] == 0x02) {
250
-        Serial.println("ui_i2c_receive: backspace command");
251
+        debug.println("ui_i2c_receive: backspace command");
251 252
         backspace();
252 253
     } else if (buff[0] == 0x03) {
253 254
         if (count < 3) {
254
-            Serial.println("ui_i2c_receive: display far too short");
255
+            debug.println("ui_i2c_receive: display far too short");
255 256
             return;
256 257
         }
257 258
         
@@ -262,22 +263,22 @@ void ui_i2c_receive(int count) {
262 263
             s += buff[3 + i];
263 264
         }
264 265
         
265
-        Serial.println("ui_i2c_receive: display command");
266
+        debug.println("ui_i2c_receive: display command");
266 267
         linebuffer[line] = s;
267 268
     } else if (buff[0] == 0x04) {
268 269
         if (count < 2) {
269
-            Serial.println("ui_i2c_receive: num input too short");
270
+            debug.println("ui_i2c_receive: num input too short");
270 271
             return;
271 272
         }
272 273
         
273 274
         int8_t num_input = buff[1];
274 275
         
275
-        Serial.println("ui_i2c_receive: num input");
276
+        debug.println("ui_i2c_receive: num input");
276 277
         write_to_all(linebuffer[0].c_str(), linebuffer[1].c_str(),
277 278
                      linebuffer[2].c_str(), linebuffer[3].c_str(),
278 279
                      num_input);
279 280
     } else {
280
-        Serial.println("ui_i2c_receive: unknown command");
281
+        debug.println("ui_i2c_receive: unknown command");
281 282
         return;
282 283
     }
283 284
 }
@@ -287,7 +288,7 @@ void ui_i2c_receive(int count) {
287 288
 void ui_setup(void) {
288 289
     keys.setPins(keymatrix_pins);
289 290
     
290
-    Serial.println("Setting up LCD, please wait");
291
+    debug.println("Setting up LCD, please wait");
291 292
     delay(1000); // give LCD some time to boot
292 293
     lcd.init();
293 294
     
@@ -300,7 +301,7 @@ void ui_setup(void) {
300 301
 #endif // DEBUG_WAIT_FOR_SERIAL_CONN
301 302
     
302 303
 #ifndef FUNCTION_CONTROL
303
-    Serial.println("Initializing I2C Slave");
304
+    debug.println("Initializing I2C Slave");
304 305
     Wire.begin(OWN_I2C_ADDRESS);
305 306
     Wire.onReceive(ui_i2c_receive);
306 307
     Wire.onRequest(ui_i2c_request);
@@ -330,12 +331,12 @@ void input_keypad(void) {
330 331
             }
331 332
             
332 333
             int n = ke.getNum();
333
-            Serial.print("Got keypad input: \"");
334
+            debug.print("Got keypad input: \"");
334 335
             
335 336
             if (n < 0) {
336
-                Serial.print((n == -1) ? '*' : '#');
337
+                debug.print((n == -1) ? '*' : '#');
337 338
             } else {
338
-                Serial.print(n);
339
+                debug.print(n);
339 340
                 
340 341
                 if (doing_multi_input) {
341 342
                     char s[2] = { (char)(n + '0'), '\0' };
@@ -343,7 +344,7 @@ void input_keypad(void) {
343 344
                 }
344 345
             }
345 346
             
346
-            Serial.println("\"");
347
+            debug.println("\"");
347 348
             
348 349
             blink_lcd(1, 100);
349 350
             handle_input(n);
@@ -432,12 +433,12 @@ void control_setup(void) {
432 433
     
433 434
 #ifndef FUNCTION_UI
434 435
     
435
-    Serial.println("Initializing I2C Master");
436
+    debug.println("Initializing I2C Master");
436 437
     Wire.setClock(I2C_BUS_SPEED);
437 438
     Wire.begin();
438 439
     
439 440
 #ifdef DEBUG_WAIT_FOR_SERIAL_CONN
440
-    Serial.println("Wait for Serial");
441
+    debug.println("Wait for Serial");
441 442
     while (!Serial);
442 443
 #endif // DEBUG_WAIT_FOR_SERIAL_CONN
443 444
     
@@ -455,6 +456,9 @@ void control_run(void) {
455 456
     while (Wire.available()) {
456 457
         char c = Wire.read();
457 458
         
459
+            debug.print("control_run: got input '");
460
+            debug.print(c);
461
+            debug.println("'");
458 462
         // for some reason it seems as if we always get -1 here,
459 463
         // so we cant send our input (-2 to 9) as is.
460 464
         // so -4 is no-data, -3 is -1, and the rest as-is.
@@ -463,9 +467,6 @@ void control_run(void) {
463 467
                 c = -1;
464 468
             }
465 469
         
466
-            Serial.print("control_run: got input '");
467
-            Serial.print((int)c);
468
-            Serial.println("'");
469 470
         
470 471
             sm.input(c);
471 472
         }
@@ -481,7 +482,7 @@ void control_run(void) {
481 482
 #ifndef FUNCTION_UI
482 483
 
483 484
 void blink_lcd(int n, int wait) {
484
-    Serial.println("blink_lcd i2c");
485
+    debug.println("blink_lcd i2c");
485 486
     
486 487
     Wire.beginTransmission(OWN_I2C_ADDRESS);
487 488
     Wire.write(0x01); // blink command
@@ -491,7 +492,7 @@ void blink_lcd(int n, int wait) {
491 492
 }
492 493
 
493 494
 void backspace(void) {
494
-    Serial.println("backspace i2c");
495
+    debug.println("backspace i2c");
495 496
     
496 497
     Wire.beginTransmission(OWN_I2C_ADDRESS);
497 498
     Wire.write(0x02); // backspace command
@@ -502,7 +503,7 @@ void write_to_all(const char *a, const char *b,
502 503
                   const char *c, const char *d, int num_input) {
503 504
     const char *lines[4] = { a, b, c, d };
504 505
     
505
-    Serial.println("write_to_all i2c");
506
+    debug.println("write_to_all i2c");
506 507
     
507 508
     for (int i = 0; i < 4; i++) {
508 509
         Wire.beginTransmission(OWN_I2C_ADDRESS);
@@ -527,8 +528,10 @@ void write_to_all(const char *a, const char *b,
527 528
     
528 529
     write_lcd_to_serial(a, b, c, d);
529 530
     
531
+#ifdef PLATFORM_ESP
530 532
     wifi_set_message_buffer(a, b, c, d);
531
-    wifi_send_websocket();
533
+    wifi_send_status_broadcast();
534
+#endif // PLATFORM_ESP
532 535
 }
533 536
 
534 537
 #endif // ! FUNCTION_UI

+ 8
- 4
src/Keymatrix.cpp Datei anzeigen

@@ -5,6 +5,10 @@
5 5
 
6 6
 //#define DEBUG_PRINT_MATRIX_STATE
7 7
 
8
+#ifdef DEBUG_PRINT_MATRIX_STATE
9
+#include "DebugLog.h"
10
+#endif // DEBUG_PRINT_MATRIX_STATE
11
+
8 12
 Keymatrix::Event::Event(EventType _type, int _row, int _col) {
9 13
     type = _type;
10 14
     row = _row;
@@ -119,14 +123,14 @@ void Keymatrix::scan(void) {
119 123
     
120 124
 #ifdef DEBUG_PRINT_MATRIX_STATE
121 125
     for (int i = 0; i < buttons; i++) {
122
-        Serial.print(pressed[i] ? "1" : "0");
126
+        debug.print(pressed[i] ? "1" : "0");
123 127
         if (i < (buttons - 1)) {
124
-            Serial.print(" ");
128
+            debug.print(" ");
125 129
         } else {
126
-            Serial.println();
130
+            debug.println();
127 131
         }
128 132
     }
129
-#endif
133
+#endif // DEBUG_PRINT_MATRIX_STATE
130 134
     
131 135
     for (int i = 0; i < buttons; i++) {
132 136
         // debounce - compare to previous state

+ 11
- 10
src/Plants.cpp Datei anzeigen

@@ -1,4 +1,5 @@
1 1
 #include <Arduino.h>
2
+#include "DebugLog.h"
2 3
 #include "Plants.h"
3 4
     
4 5
 // valves: no of plants + 1 for water inlet
@@ -60,12 +61,12 @@ Plants::Waterlevel Plants::getWaterlevel(void) {
60 61
 }
61 62
 
62 63
 void Plants::openWaterInlet(void) {
63
-    Serial.println("Plants::openWaterInlet");
64
+    debug.println("Plants::openWaterInlet");
64 65
     valves.setPin(countPlants(), true);
65 66
 }
66 67
 
67 68
 void Plants::closeWaterInlet(void) {
68
-    Serial.println("Plants::closeWaterInlet");
69
+    debug.println("Plants::closeWaterInlet");
69 70
     valves.setPin(countPlants(), false);
70 71
 }
71 72
 
@@ -74,8 +75,8 @@ int Plants::countFertilizers(void) {
74 75
 }
75 76
 
76 77
 void Plants::startFertilizer(int id) {
77
-    Serial.print("Plants::startFertilizer ");
78
-    Serial.println(id);
78
+    debug.print("Plants::startFertilizer ");
79
+    debug.println(id);
79 80
     
80 81
     if ((id >= 0) && (id < countFertilizers())) {
81 82
         pumps.setPin(id, true);
@@ -83,8 +84,8 @@ void Plants::startFertilizer(int id) {
83 84
 }
84 85
 
85 86
 void Plants::stopFertilizer(int id) {
86
-    Serial.print("Plants::stopFertilizer ");
87
-    Serial.println(id);
87
+    debug.print("Plants::stopFertilizer ");
88
+    debug.println(id);
88 89
     
89 90
     if ((id >= 0) && (id < countFertilizers())) {
90 91
         pumps.setPin(id, false);
@@ -102,8 +103,8 @@ int Plants::countPlants(void) {
102 103
 }
103 104
 
104 105
 void Plants::startPlant(int id) {
105
-    Serial.print("Plants::startPlant ");
106
-    Serial.println(id);
106
+    debug.print("Plants::startPlant ");
107
+    debug.println(id);
107 108
     
108 109
     if ((id >= 0) && (id < countPlants())) {
109 110
         valves.setPin(id, true);
@@ -111,8 +112,8 @@ void Plants::startPlant(int id) {
111 112
 }
112 113
 
113 114
 void Plants::stopPlant(int id) {
114
-    Serial.print("Plants::stopPlant ");
115
-    Serial.println(id);
115
+    debug.print("Plants::stopPlant ");
116
+    debug.println(id);
116 117
     
117 118
     if ((id >= 0) && (id < countPlants())) {
118 119
         valves.setPin(id, false);

+ 3
- 2
src/Statemachine.cpp Datei anzeigen

@@ -1,4 +1,5 @@
1 1
 #include "Plants.h"
2
+#include "DebugLog.h"
2 3
 #include "Statemachine.h"
3 4
 #include "config.h"
4 5
 
@@ -395,8 +396,8 @@ uint32_t Statemachine::number_input(void) {
395 396
     uint32_t n = db.getNumber();
396 397
     db.clear();
397 398
     
398
-    Serial.print("Whole number input: ");
399
-    Serial.println(n);
399
+    debug.print("Whole number input: ");
400
+    debug.println(n);
400 401
     
401 402
     return n;
402 403
 }

+ 51
- 18
src/WifiStuff.cpp Datei anzeigen

@@ -23,6 +23,7 @@
23 23
 #include "config_pins.h"
24 24
 #include "Functionality.h"
25 25
 #include "SimpleUpdater.h"
26
+#include "DebugLog.h"
26 27
 #include "WifiStuff.h"
27 28
 
28 29
 UPDATE_WEB_SERVER server(80);
@@ -47,7 +48,7 @@ void wifi_schedule_websocket(void) {
47 48
     last_websocket_update_time = 0;
48 49
 }
49 50
 
50
-void wifi_send_websocket(void) {
51
+void wifi_send_status_broadcast(void) {
51 52
     String a = message_buffer_a ;
52 53
     String b = message_buffer_b;
53 54
     String c = message_buffer_c;
@@ -117,7 +118,11 @@ void wifi_send_websocket(void) {
117 118
     ws += "\"\n";
118 119
     ws += "}";
119 120
     
120
-    socket.broadcastTXT(ws);
121
+    wifi_send_websocket(ws);
122
+}
123
+
124
+void wifi_send_websocket(String s) {
125
+    socket.broadcastTXT(s);
121 126
 }
122 127
 
123 128
 void handleRoot() {
@@ -181,6 +186,20 @@ void handleRoot() {
181 186
     message += F("font-family: monospace;\n");
182 187
     message += F("}\n");
183 188
     
189
+    message += F(".log {\n");
190
+    message += F("max-height: 300px;\n");
191
+    message += F("padding: 0 1.0em;\n");
192
+    message += F("margin: 1em 0;\n");
193
+    message += F("border: 1px dashed black;\n");
194
+    message += F("font-family: monospace;\n");
195
+    message += F("overflow-y: scroll;\n");
196
+    message += F("word-break: break-all;\n");
197
+    message += F("}\n");
198
+    
199
+    message += F("#logbuf {\n");
200
+    message += F("white-space: break-spaces;\n");
201
+    message += F("}\n");
202
+    
184 203
     message += F(".pad {\n");
185 204
     message += F("background: black;\n");
186 205
     message += F("border: 3px solid black;\n");
@@ -376,12 +395,26 @@ void handleRoot() {
376 395
     message += F("<p>Try <a href='/update'>/update</a> for OTA firmware updates!</p>\n");
377 396
     message += F("<p>Made by <a href='https://xythobuz.de'>xythobuz</a></p>\n");
378 397
     message += F("<p><a href='https://git.xythobuz.de/thomas/giess-o-mat'>Project Repository</a></p>\n");
379
-    message += F("</div>\n");
380
-    message += F("</div></body>\n");
398
+    message += F("</div></div>\n");
399
+    
400
+    message += F("<div class='log'><pre id='logbuf'>\n");
401
+    message += debug.getBuffer();
402
+    message += F("</pre></div>\n");
403
+    message += F("</body>\n");
381 404
     
382 405
     message += F("<script type='text/javascript'>\n");
383 406
     message += F("var socket = new WebSocket('ws://' + window.location.hostname + ':81');\n");
384 407
     message += F("socket.onmessage = function(e) {\n");
408
+    message += F(    "if (e.data.startsWith('log:')) {\n");
409
+    message += F(        "var log = document.getElementById('logbuf');\n");
410
+    message += F(        "var div = document.getElementsByClassName('log')[0];\n");
411
+    message += F(        "log.innerHTML += e.data.substring(4);\n");
412
+    message += F(        "if (log.innerHTML.length > (1024 * 1024)) {\n");
413
+    message += F(            "log.innerHTML = log.innerHTML.substring(1024 * 1024);\n");
414
+    message += F(        "}\n");
415
+    message += F(        "div.scrollTop = div.scrollHeight;\n");
416
+    message += F(        "return;\n");
417
+    message += F(    "}\n");
385 418
     message += F(    "var msg = JSON.parse(e.data);\n");
386 419
     message += F(    "var str = msg.a + '\\n' + msg.b + '\\n' + msg.c + '\\n' + msg.d;\n");
387 420
     message += F(    "console.log(str);\n");
@@ -462,29 +495,29 @@ void wifi_setup() {
462 495
 #if defined(ARDUINO_ARCH_ESP8266)
463 496
 
464 497
     // Connect to WiFi AP
465
-    Serial.println("WiFi: initializing");
498
+    debug.println("WiFi: initializing");
466 499
     WiFi.hostname(hostname);
467 500
     WiFi.mode(WIFI_STA);
468 501
     
469
-    Serial.print("WiFi: connecting");
502
+    debug.print("WiFi: connecting");
470 503
     WiFi.begin(WIFI_SSID, WIFI_PW);
471 504
     while (WiFi.status() != WL_CONNECTED) {
472
-        Serial.print(".");
505
+        debug.print(".");
473 506
         delay(LED_CONNECT_BLINK_INTERVAL);
474 507
         digitalWrite(BUILTIN_LED_PIN, !digitalRead(BUILTIN_LED_PIN));
475 508
     }
476
-    Serial.println();
509
+    debug.println();
477 510
     
478 511
 #elif defined(ARDUINO_ARCH_ESP32)
479 512
 
480 513
     // Set hostname workaround
481
-    Serial.println("WiFi: set hostname");
514
+    debug.println("WiFi: set hostname");
482 515
     WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE);
483 516
     WiFi.setHostname(hostname.c_str());
484 517
     
485 518
     // Workaround for WiFi connecting only every 2nd reset
486 519
     // https://github.com/espressif/arduino-esp32/issues/2501#issuecomment-513602522
487
-    Serial.println("WiFi: connection work-around");
520
+    debug.println("WiFi: connection work-around");
488 521
     WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
489 522
         if (info.disconnected.reason == 202) {
490 523
             esp_sleep_enable_timer_wakeup(10);
@@ -494,25 +527,25 @@ void wifi_setup() {
494 527
     }, WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED);
495 528
 
496 529
     // Connect to WiFi AP
497
-    Serial.println("WiFi: SSID=" WIFI_SSID);
498
-    Serial.print("WiFi: connecting");
530
+    debug.println("WiFi: SSID=" WIFI_SSID);
531
+    debug.print("WiFi: connecting");
499 532
     WiFi.mode(WIFI_STA);
500 533
     WiFi.begin(WIFI_SSID, WIFI_PW);
501 534
     while (WiFi.status() != WL_CONNECTED) {
502
-        Serial.print(".");
535
+        debug.print(".");
503 536
         delay(LED_CONNECT_BLINK_INTERVAL);
504 537
         digitalWrite(BUILTIN_LED_PIN, !digitalRead(BUILTIN_LED_PIN));
505 538
     }
506
-    Serial.println();
539
+    debug.println();
507 540
     
508 541
     // Set hostname workaround
509
-    Serial.println("WiFi: set hostname work-around");
542
+    debug.println("WiFi: set hostname work-around");
510 543
     WiFi.setHostname(hostname.c_str());
511 544
 
512 545
 #endif
513 546
 
514 547
     // Setup HTTP Server
515
-    Serial.println("WiFi: initializing HTTP server");
548
+    debug.println("WiFi: initializing HTTP server");
516 549
     MDNS.begin(hostname.c_str());
517 550
     updater.setup(&server);
518 551
     server.on("/", handleRoot);
@@ -522,7 +555,7 @@ void wifi_setup() {
522 555
     socket.begin();
523 556
     socket.onEvent(webSocketEvent);
524 557
     
525
-    Serial.println("WiFi: setup done");
558
+    debug.println("WiFi: setup done");
526 559
 }
527 560
 
528 561
 void wifi_run() {
@@ -538,7 +571,7 @@ void wifi_run() {
538 571
     
539 572
     if ((millis() - last_websocket_update_time) >= WEBSOCKET_UPDATE_INTERVAL) {
540 573
         last_websocket_update_time = millis();
541
-        wifi_send_websocket();
574
+        wifi_send_status_broadcast();
542 575
     }
543 576
     
544 577
     // reset ESP every 6h to be safe

+ 9
- 8
src/main.cpp Datei anzeigen

@@ -2,6 +2,7 @@
2 2
 
3 3
 #include "Functionality.h"
4 4
 #include "WifiStuff.h"
5
+#include "DebugLog.h"
5 6
 #include "config.h"
6 7
 #include "config_pins.h"
7 8
 
@@ -12,36 +13,36 @@ void setup() {
12 13
     digitalWrite(BUILTIN_LED_PIN, HIGH);
13 14
     
14 15
     Serial.begin(115200);
15
-    Serial.println("Initializing Giess-o-mat");
16
-    Serial.println("Version: " FIRMWARE_VERSION);
16
+    debug.println("Initializing Giess-o-mat");
17
+    debug.println("Version: " FIRMWARE_VERSION);
17 18
 
18 19
 #ifdef FUNCTION_UI
19
-    Serial.println("Initializing UI");
20
+    debug.println("Initializing UI");
20 21
     ui_setup();
21 22
 #endif // FUNCTION_UI
22 23
     
23 24
 #ifdef FUNCTION_CONTROL
24
-    Serial.println("Initializing Control");
25
+    debug.println("Initializing Control");
25 26
     control_setup();
26 27
 #endif // FUNCTION_CONTROL
27 28
     
28 29
 #ifdef PLATFORM_ESP
29
-    Serial.println("Initializing WiFi");
30
+    debug.println("Initializing WiFi");
30 31
     wifi_setup();
31 32
 #endif // PLATFORM_ESP
32 33
     
33
-    Serial.println("Ready, starting main loop");
34
+    debug.println("Ready, starting main loop");
34 35
     digitalWrite(BUILTIN_LED_PIN, LOW);
35 36
     
36 37
 #ifdef FUNCTION_CONTROL
37 38
     
38 39
 #ifndef FUNCTION_UI
39 40
     // give ui unit some time to initialize
40
-    Serial.println("Waiting for UI to boot");
41
+    debug.println("Waiting for UI to boot");
41 42
     delay(3000);
42 43
 #endif // ! FUNCTION_UI
43 44
     
44
-    Serial.println("Starting state machine");
45
+    debug.println("Starting state machine");
45 46
     control_begin();
46 47
     
47 48
 #endif // FUNCTION_CONTROL

Laden…
Abbrechen
Speichern