|
@@ -15,6 +15,10 @@
|
15
|
15
|
#include <Adafruit_BME280.h>
|
16
|
16
|
#include <SHT2x.h>
|
17
|
17
|
|
|
18
|
+#ifdef ENABLE_CCS811
|
|
19
|
+#include <Adafruit_CCS811.h>
|
|
20
|
+#endif // ENABLE_CCS811
|
|
21
|
+
|
18
|
22
|
#if defined(ARDUINO_ARCH_ESP8266)
|
19
|
23
|
|
20
|
24
|
#include <ESP8266WiFi.h>
|
|
@@ -35,6 +39,7 @@
|
35
|
39
|
|
36
|
40
|
#include "config.h"
|
37
|
41
|
#include "moisture.h"
|
|
42
|
+#include "relais.h"
|
38
|
43
|
|
39
|
44
|
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
40
|
45
|
|
|
@@ -46,6 +51,13 @@
|
46
|
51
|
UPDATE_WEB_SERVER server(80);
|
47
|
52
|
SimpleUpdater updater;
|
48
|
53
|
|
|
54
|
+#ifdef ENABLE_MQTT
|
|
55
|
+#include <PubSubClient.h>
|
|
56
|
+WiFiClient mqttClient;
|
|
57
|
+PubSubClient mqtt(mqttClient);
|
|
58
|
+unsigned long last_mqtt_reconnect_time = 0;
|
|
59
|
+#endif // ENABLE_MQTT
|
|
60
|
+
|
49
|
61
|
#elif defined(ARDUINO_ARCH_AVR)
|
50
|
62
|
|
51
|
63
|
#define ESP_PLATFORM_NAME "Uno WiFi"
|
|
@@ -69,6 +81,8 @@ int error_count = 0;
|
69
|
81
|
#define SHT_I2C_ADDRESS HTDU21D_ADDRESS
|
70
|
82
|
#define BME_I2C_ADDRESS_1 0x76
|
71
|
83
|
#define BME_I2C_ADDRESS_2 0x77
|
|
84
|
+#define CCS811_ADDRESS_1 0x5A
|
|
85
|
+#define CCS811_ADDRESS_2 0x5B
|
72
|
86
|
|
73
|
87
|
#if defined(ARDUINO_ARCH_ESP8266)
|
74
|
88
|
|
|
@@ -92,43 +106,27 @@ SHT2x sht(SHT_I2C_ADDRESS, &Wire);
|
92
|
106
|
|
93
|
107
|
#endif
|
94
|
108
|
|
95
|
|
-//#define ENABLE_RELAIS_TEST
|
96
|
|
-
|
97
|
109
|
Adafruit_BME280 bme1, bme2;
|
98
|
110
|
|
99
|
111
|
bool found_bme1 = false;
|
100
|
112
|
bool found_bme2 = false;
|
101
|
113
|
bool found_sht = false;
|
102
|
114
|
|
|
115
|
+#ifdef ENABLE_CCS811
|
|
116
|
+Adafruit_CCS811 ccs1, ccs2;
|
|
117
|
+bool found_ccs1 = false;
|
|
118
|
+bool found_ccs2 = false;
|
|
119
|
+bool ccs1_data_valid = false;
|
|
120
|
+bool ccs2_data_valid = false;
|
|
121
|
+int ccs1_error_code = 0;
|
|
122
|
+int ccs2_error_code = 0;
|
|
123
|
+#endif // ENABLE_CCS811
|
|
124
|
+
|
103
|
125
|
unsigned long last_server_handle_time = 0;
|
104
|
126
|
unsigned long last_db_write_time = 0;
|
105
|
127
|
unsigned long last_led_blink_time = 0;
|
106
|
128
|
|
107
|
|
-#ifdef ENABLE_RELAIS_TEST
|
108
|
|
-
|
109
|
|
-#include "relais.h"
|
110
|
|
-
|
111
|
|
-static void relaisTest() {
|
112
|
|
- for (int i = 0; i < 10; i++) {
|
113
|
|
- relais_enable(i, 400 + (i * 1000));
|
114
|
|
- delay(100);
|
115
|
|
- }
|
116
|
|
-}
|
117
|
|
-
|
118
|
|
-void handleRelaisTest() {
|
119
|
|
- String message = F("<html><head>");
|
120
|
|
- message += F("<title>" ESP_PLATFORM_NAME " Environment Sensor</title>");
|
121
|
|
- message += F("</head><body>");
|
122
|
|
- message += F("<p>Relais Test started!</p>");
|
123
|
|
- message += F("<p><a href=\"/\">Return to Home</a></p>");
|
124
|
|
- message += F("</body></html>");
|
125
|
|
-
|
126
|
|
- server.send(200, "text/html", message);
|
127
|
|
-
|
128
|
|
- relaisTest();
|
129
|
|
-}
|
130
|
|
-
|
131
|
|
-#endif // ENABLE_RELAIS_TEST
|
|
129
|
+void writeDatabase();
|
132
|
130
|
|
133
|
131
|
static float bme1_temp(void) {
|
134
|
132
|
while (1) {
|
|
@@ -258,10 +256,48 @@ static float sht_humid(void) {
|
258
|
256
|
return 0.0;
|
259
|
257
|
}
|
260
|
258
|
|
|
259
|
+#ifdef ENABLE_CCS811
|
|
260
|
+
|
|
261
|
+static float ccs1_eco2(void) {
|
|
262
|
+ return ccs1.geteCO2();
|
|
263
|
+}
|
|
264
|
+
|
|
265
|
+static float ccs1_tvoc(void) {
|
|
266
|
+ return ccs1.getTVOC();
|
|
267
|
+}
|
|
268
|
+
|
|
269
|
+static float ccs2_eco2(void) {
|
|
270
|
+ return ccs2.geteCO2();
|
|
271
|
+}
|
|
272
|
+
|
|
273
|
+static float ccs2_tvoc(void) {
|
|
274
|
+ return ccs2.getTVOC();
|
|
275
|
+}
|
|
276
|
+
|
|
277
|
+#endif // ENABLE_CCS811
|
|
278
|
+
|
|
279
|
+#if defined(ARDUINO_ARCH_AVR)
|
|
280
|
+#define ARDUINO_SEND_PARTIAL_PAGE() do { \
|
|
281
|
+ size_t len = message.length(), off = 0; \
|
|
282
|
+ while (off < len) { \
|
|
283
|
+ if ((len - off) >= 50) { \
|
|
284
|
+ client.write(message.c_str() + off, 50); \
|
|
285
|
+ off += 50; \
|
|
286
|
+ } else { \
|
|
287
|
+ client.write(message.c_str() + off, len - off); \
|
|
288
|
+ off = len; \
|
|
289
|
+ } \
|
|
290
|
+ } \
|
|
291
|
+ message = ""; \
|
|
292
|
+ } while (false);
|
|
293
|
+#else
|
|
294
|
+#define ARDUINO_SEND_PARTIAL_PAGE() while (false) { }
|
|
295
|
+#endif
|
|
296
|
+
|
261
|
297
|
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
262
|
|
-void handleRoot() {
|
|
298
|
+void handlePage(int mode = -1, int id = 0) {
|
263
|
299
|
#else
|
264
|
|
-void handleRoot(WiFiClient &client) {
|
|
300
|
+void handlePage(WiFiClient &client, int mode = -1, int id = 0) {
|
265
|
301
|
#endif
|
266
|
302
|
String message;
|
267
|
303
|
|
|
@@ -271,10 +307,10 @@ void handleRoot(WiFiClient &client) {
|
271
|
307
|
message += F("<h1>" ESP_PLATFORM_NAME " Environment Sensor</h1>");
|
272
|
308
|
message += F("\n<p>\n");
|
273
|
309
|
message += F("Version: ");
|
274
|
|
- message += esp_env_version;
|
|
310
|
+ message += ESP_ENV_VERSION;
|
275
|
311
|
message += F("\n<br>\n");
|
276
|
312
|
message += F("Location: ");
|
277
|
|
- message += sensor_location;
|
|
313
|
+ message += SENSOR_LOCATION;
|
278
|
314
|
|
279
|
315
|
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
280
|
316
|
message += F("\n<br>\n");
|
|
@@ -284,21 +320,7 @@ void handleRoot(WiFiClient &client) {
|
284
|
320
|
|
285
|
321
|
message += F("\n</p>\n");
|
286
|
322
|
|
287
|
|
-#if defined(ARDUINO_ARCH_AVR)
|
288
|
|
- do {
|
289
|
|
- size_t len = message.length(), off = 0;
|
290
|
|
- while (off < len) {
|
291
|
|
- if ((len - off) >= 50) {
|
292
|
|
- client.write(message.c_str() + off, 50);
|
293
|
|
- off += 50;
|
294
|
|
- } else {
|
295
|
|
- client.write(message.c_str() + off, len - off);
|
296
|
|
- off = len;
|
297
|
|
- }
|
298
|
|
- }
|
299
|
|
- message = "";
|
300
|
|
- } while (false);
|
301
|
|
-#endif
|
|
323
|
+ ARDUINO_SEND_PARTIAL_PAGE();
|
302
|
324
|
|
303
|
325
|
#if defined(ARDUINO_ARCH_ESP8266)
|
304
|
326
|
|
|
@@ -376,6 +398,8 @@ void handleRoot(WiFiClient &client) {
|
376
|
398
|
}
|
377
|
399
|
message += F("\n</p>\n");
|
378
|
400
|
|
|
401
|
+ ARDUINO_SEND_PARTIAL_PAGE();
|
|
402
|
+
|
379
|
403
|
message += F("\n<p>\n");
|
380
|
404
|
if (found_sht) {
|
381
|
405
|
message += F("SHT21:");
|
|
@@ -390,22 +414,59 @@ void handleRoot(WiFiClient &client) {
|
390
|
414
|
}
|
391
|
415
|
message += F("\n</p>\n");
|
392
|
416
|
|
393
|
|
-#if defined(ARDUINO_ARCH_AVR)
|
394
|
|
- do {
|
395
|
|
- size_t len = message.length(), off = 0;
|
396
|
|
- while (off < len) {
|
397
|
|
- if ((len - off) >= 50) {
|
398
|
|
- client.write(message.c_str() + off, 50);
|
399
|
|
- off += 50;
|
400
|
|
- } else {
|
401
|
|
- client.write(message.c_str() + off, len - off);
|
402
|
|
- off = len;
|
403
|
|
- }
|
|
417
|
+#ifdef ENABLE_CCS811
|
|
418
|
+
|
|
419
|
+ message += F("\n<p>\n");
|
|
420
|
+ if (found_ccs1) {
|
|
421
|
+ message += F("CCS811 Low:");
|
|
422
|
+ message += F("\n<br>\n");
|
|
423
|
+ message += F("eCO2: ");
|
|
424
|
+ message += String(ccs1_eco2());
|
|
425
|
+ message += F("ppm");
|
|
426
|
+ message += F("\n<br>\n");
|
|
427
|
+ message += F("TVOC: ");
|
|
428
|
+ message += String(ccs1_tvoc());
|
|
429
|
+ message += F("ppb");
|
|
430
|
+
|
|
431
|
+ if (!ccs1_data_valid) {
|
|
432
|
+ message += F("\n<br>\n");
|
|
433
|
+ message += F("Data invalid (");
|
|
434
|
+ message += String(ccs1_error_code);
|
|
435
|
+ message += F(")!");
|
404
|
436
|
}
|
405
|
|
- message = "";
|
406
|
|
- } while (false);
|
407
|
|
-#endif
|
|
437
|
+ } else {
|
|
438
|
+ message += F("CCS811 (Low) not connected!");
|
|
439
|
+ }
|
|
440
|
+ message += F("\n</p>\n");
|
|
441
|
+
|
|
442
|
+ message += F("\n<p>\n");
|
|
443
|
+ if (found_ccs2) {
|
|
444
|
+ message += F("CCS811 High:");
|
|
445
|
+ message += F("\n<br>\n");
|
|
446
|
+ message += F("eCO2: ");
|
|
447
|
+ message += String(ccs2_eco2());
|
|
448
|
+ message += F("ppm");
|
|
449
|
+ message += F("\n<br>\n");
|
|
450
|
+ message += F("TVOC: ");
|
|
451
|
+ message += String(ccs2_tvoc());
|
|
452
|
+ message += F("ppb");
|
|
453
|
+
|
|
454
|
+ if (!ccs2_data_valid) {
|
|
455
|
+ message += F("\n<br>\n");
|
|
456
|
+ message += F("Data invalid (");
|
|
457
|
+ message += String(ccs2_error_code);
|
|
458
|
+ message += F(")!");
|
|
459
|
+ }
|
|
460
|
+ } else {
|
|
461
|
+ message += F("CCS811 (High) not connected!");
|
|
462
|
+ }
|
|
463
|
+ message += F("\n</p>\n");
|
408
|
464
|
|
|
465
|
+#endif // ENABLE_CCS811
|
|
466
|
+
|
|
467
|
+ ARDUINO_SEND_PARTIAL_PAGE();
|
|
468
|
+
|
|
469
|
+#ifdef FEATURE_MOISTURE
|
409
|
470
|
for (int i = 0; i < moisture_count(); i++) {
|
410
|
471
|
int moisture = moisture_read(i);
|
411
|
472
|
if (moisture < moisture_max()) {
|
|
@@ -427,6 +488,36 @@ void handleRoot(WiFiClient &client) {
|
427
|
488
|
message += F("\n</p>\n");
|
428
|
489
|
}
|
429
|
490
|
|
|
491
|
+ ARDUINO_SEND_PARTIAL_PAGE();
|
|
492
|
+#endif // FEATURE_MOISTURE
|
|
493
|
+
|
|
494
|
+#ifdef FEATURE_RELAIS
|
|
495
|
+ message += F("\n<p>\n");
|
|
496
|
+ for (int i = 0; i < relais_count(); i++) {
|
|
497
|
+ message += String(F("<a href=\"/on?id=")) + String(i) + String(F("\">Relais ")) + String(i) + String(F(" On (")) + relais_name(i) + String(F(")</a><br>\n"));
|
|
498
|
+ message += String(F("<a href=\"/off?id=")) + String(i) + String(F("\">Relais ")) + String(i) + String(F(" Off (")) + relais_name(i) + String(F(")</a><br>\n"));
|
|
499
|
+ }
|
|
500
|
+ message += String(F("<a href=\"/on?id=")) + String(relais_count()) + String(F("\">All Relais On</a><br>\n"));
|
|
501
|
+ message += String(F("<a href=\"/off?id=")) + String(relais_count()) + String(F("\">All Relais Off</a><br>\n"));
|
|
502
|
+ message += F("</p>\n");
|
|
503
|
+
|
|
504
|
+ if (mode >= 0) {
|
|
505
|
+ message += F("<p>");
|
|
506
|
+ message += F("Turned Relais ");
|
|
507
|
+ message += (id < relais_count()) ? String(id) : String(F("1-4"));
|
|
508
|
+ message += (mode ? String(F(" On")) : String(F(" Off")));
|
|
509
|
+ message += F("</p>\n");
|
|
510
|
+ }
|
|
511
|
+
|
|
512
|
+ message += F("\n<p>\n");
|
|
513
|
+ for (int i = 0; i < relais_count(); i++) {
|
|
514
|
+ message += String(F("Relais ")) + String(i) + String(F(" (")) + relais_name(i) + String(F(") = ")) + (relais_get(i) ? String(F("On")) : String(F("Off"))) + String(F("<br>\n"));
|
|
515
|
+ }
|
|
516
|
+ message += F("</p>\n");
|
|
517
|
+
|
|
518
|
+ ARDUINO_SEND_PARTIAL_PAGE();
|
|
519
|
+#endif // FEATURE_RELAIS
|
|
520
|
+
|
430
|
521
|
#if ! defined(ARDUINO_ARCH_AVR)
|
431
|
522
|
message += F("<p>");
|
432
|
523
|
message += F("Try <a href=\"/update\">/update</a> for OTA firmware updates!");
|
|
@@ -445,37 +536,192 @@ void handleRoot(WiFiClient &client) {
|
445
|
536
|
message += F("InfluxDB logging not enabled!");
|
446
|
537
|
#endif
|
447
|
538
|
message += F("</p>");
|
448
|
|
-
|
449
|
|
-#ifdef ENABLE_RELAIS_TEST
|
450
|
|
- message += F("<p><a href=\"/relaistest\">Relais Test</a></p>");
|
451
|
|
-#endif // ENABLE_RELAIS_TEST
|
452
|
539
|
|
453
|
540
|
message += F("</body></html>");
|
454
|
541
|
|
455
|
542
|
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
456
|
543
|
server.send(200, "text/html", message);
|
457
|
544
|
#else
|
458
|
|
- do {
|
459
|
|
- size_t len = message.length(), off = 0;
|
460
|
|
- while (off < len) {
|
461
|
|
- if ((len - off) >= 50) {
|
462
|
|
- client.write(message.c_str() + off, 50);
|
463
|
|
- off += 50;
|
464
|
|
- } else {
|
465
|
|
- client.write(message.c_str() + off, len - off);
|
466
|
|
- off = len;
|
467
|
|
- }
|
|
545
|
+ ARDUINO_SEND_PARTIAL_PAGE();
|
|
546
|
+#endif
|
|
547
|
+}
|
|
548
|
+
|
|
549
|
+#ifdef FEATURE_RELAIS
|
|
550
|
+
|
|
551
|
+#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
|
552
|
+void handleOn() {
|
|
553
|
+#else
|
|
554
|
+void handleOn(WiFiClient &client) {
|
|
555
|
+#endif
|
|
556
|
+ String id_string = server.arg("id");
|
|
557
|
+ int id = id_string.toInt();
|
|
558
|
+
|
|
559
|
+ if ((id >= 0) && (id < relais_count())) {
|
|
560
|
+ relais_set(id, 1);
|
|
561
|
+ } else {
|
|
562
|
+ for (int i = 0; i < relais_count(); i++) {
|
|
563
|
+ relais_set(i, 1);
|
468
|
564
|
}
|
469
|
|
- } while (false);
|
|
565
|
+ }
|
|
566
|
+
|
|
567
|
+#ifdef ENABLE_INFLUXDB_LOGGING
|
|
568
|
+ writeDatabase();
|
|
569
|
+#endif // ENABLE_INFLUXDB_LOGGING
|
|
570
|
+
|
|
571
|
+#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
|
572
|
+ handlePage(1, id);
|
|
573
|
+#else
|
|
574
|
+ handlePage(client, 1, id);
|
470
|
575
|
#endif
|
471
|
576
|
}
|
472
|
577
|
|
|
578
|
+#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
|
579
|
+void handleOff() {
|
|
580
|
+#else
|
|
581
|
+void handleOff(WiFiClient &client) {
|
|
582
|
+#endif
|
|
583
|
+ String id_string = server.arg("id");
|
|
584
|
+ int id = id_string.toInt();
|
|
585
|
+
|
|
586
|
+ if ((id >= 0) && (id < relais_count())) {
|
|
587
|
+ relais_set(id, 0);
|
|
588
|
+ } else {
|
|
589
|
+ for (int i = 0; i < relais_count(); i++) {
|
|
590
|
+ relais_set(i, 0);
|
|
591
|
+ }
|
|
592
|
+ }
|
|
593
|
+
|
|
594
|
+#ifdef ENABLE_INFLUXDB_LOGGING
|
|
595
|
+ writeDatabase();
|
|
596
|
+#endif // ENABLE_INFLUXDB_LOGGING
|
|
597
|
+
|
|
598
|
+#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
|
599
|
+ handlePage(0, id);
|
|
600
|
+#else
|
|
601
|
+ handlePage(client, 0, id);
|
|
602
|
+#endif
|
|
603
|
+}
|
|
604
|
+
|
|
605
|
+#endif // FEATURE_RELAIS
|
|
606
|
+
|
|
607
|
+#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
|
608
|
+void handleRoot() {
|
|
609
|
+ handlePage();
|
|
610
|
+#else
|
|
611
|
+void handleRoot(WiFiClient &client) {
|
|
612
|
+ handlePage(client);
|
|
613
|
+#endif
|
|
614
|
+}
|
|
615
|
+
|
|
616
|
+#ifdef ENABLE_MQTT
|
|
617
|
+void writeMQTT() {
|
|
618
|
+ if (!mqtt.connected()) {
|
|
619
|
+ return;
|
|
620
|
+ }
|
|
621
|
+
|
|
622
|
+ if (found_bme1) {
|
|
623
|
+ mqtt.publish(SENSOR_LOCATION "/temperature", String(bme1_temp()).c_str());
|
|
624
|
+ mqtt.publish(SENSOR_LOCATION "/humidity", String(bme1_humid()).c_str());
|
|
625
|
+ mqtt.publish(SENSOR_LOCATION "/pressure", String(bme1_pressure()).c_str());
|
|
626
|
+ } else if (found_bme2) {
|
|
627
|
+ mqtt.publish(SENSOR_LOCATION "/temperature", String(bme2_temp()).c_str());
|
|
628
|
+ mqtt.publish(SENSOR_LOCATION "/humidity", String(bme2_humid()).c_str());
|
|
629
|
+ mqtt.publish(SENSOR_LOCATION "/pressure", String(bme2_pressure()).c_str());
|
|
630
|
+ } else if (found_sht) {
|
|
631
|
+ mqtt.publish(SENSOR_LOCATION "/temperature", String(sht_temp()).c_str());
|
|
632
|
+ mqtt.publish(SENSOR_LOCATION "/humidity", String(sht_humid()).c_str());
|
|
633
|
+ }
|
|
634
|
+
|
|
635
|
+#ifdef ENABLE_CCS811
|
|
636
|
+ if (found_ccs1) {
|
|
637
|
+ mqtt.publish(SENSOR_LOCATION "/eco2", String(ccs1_eco2()).c_str());
|
|
638
|
+ mqtt.publish(SENSOR_LOCATION "/tvoc", String(ccs1_tvoc()).c_str());
|
|
639
|
+ } else if (found_ccs2) {
|
|
640
|
+ mqtt.publish(SENSOR_LOCATION "/eco2", String(ccs2_eco2()).c_str());
|
|
641
|
+ mqtt.publish(SENSOR_LOCATION "/tvoc", String(ccs2_tvoc()).c_str());
|
|
642
|
+ }
|
|
643
|
+#endif // ENABLE_CCS811
|
|
644
|
+}
|
|
645
|
+
|
|
646
|
+void mqttCallback(char* topic, byte* payload, unsigned int length) {
|
|
647
|
+#ifdef FEATURE_RELAIS
|
|
648
|
+ int state = 0;
|
|
649
|
+ int id = -1;
|
|
650
|
+
|
|
651
|
+ String ts(topic), ps((char *)payload);
|
|
652
|
+
|
|
653
|
+ String our_topic(SENSOR_LOCATION);
|
|
654
|
+ our_topic += "/";
|
|
655
|
+
|
|
656
|
+ if (!ts.startsWith(our_topic)) {
|
|
657
|
+ Serial.print(F("Unknown MQTT room "));
|
|
658
|
+ Serial.println(ts);
|
|
659
|
+ return;
|
|
660
|
+ }
|
|
661
|
+
|
|
662
|
+ String ids = ts.substring(our_topic.length());
|
|
663
|
+ for (int i = 0; i < relais_count(); i++) {
|
|
664
|
+ if (ids == relais_name(i)) {
|
|
665
|
+ id = i;
|
|
666
|
+ break;
|
|
667
|
+ }
|
|
668
|
+ }
|
|
669
|
+
|
|
670
|
+ if (id < 0) {
|
|
671
|
+ Serial.print(F("Unknown MQTT topic "));
|
|
672
|
+ Serial.println(ts);
|
|
673
|
+ return;
|
|
674
|
+ }
|
|
675
|
+
|
|
676
|
+ if (ps.indexOf("on") != -1) {
|
|
677
|
+ state = 1;
|
|
678
|
+ } else if (ps.indexOf("off") != -1) {
|
|
679
|
+ state = 0;
|
|
680
|
+ } else {
|
|
681
|
+ return;
|
|
682
|
+ }
|
|
683
|
+
|
|
684
|
+ if ((id >= 0) && (id < relais_count())) {
|
|
685
|
+ relais_set(id, state);
|
|
686
|
+
|
|
687
|
+#ifdef ENABLE_INFLUXDB_LOGGING
|
|
688
|
+ writeDatabase();
|
|
689
|
+#endif // ENABLE_INFLUXDB_LOGGING
|
|
690
|
+ }
|
|
691
|
+#endif // FEATURE_RELAIS
|
|
692
|
+}
|
|
693
|
+
|
|
694
|
+void mqttReconnect() {
|
|
695
|
+ // Create a random client ID
|
|
696
|
+ String clientId = F("ESP-" SENSOR_LOCATION "-");
|
|
697
|
+ clientId += String(random(0xffff), HEX);
|
|
698
|
+
|
|
699
|
+ // Attempt to connect
|
|
700
|
+#if defined(MQTT_USER) && defined(MQTT_PASS)
|
|
701
|
+ if (mqtt.connect(clientId.c_str(), MQTT_USER, MQTT_PASS)) {
|
|
702
|
+#else
|
|
703
|
+ if (mqtt.connect(clientId.c_str())) {
|
|
704
|
+#endif
|
|
705
|
+ // Once connected, publish an announcement...
|
|
706
|
+ mqtt.publish(SENSOR_LOCATION, "sensor online");
|
|
707
|
+
|
|
708
|
+ // ... and resubscribe
|
|
709
|
+#ifdef FEATURE_RELAIS
|
|
710
|
+ mqtt.subscribe(SENSOR_LOCATION);
|
|
711
|
+ for (int i = 0; i < relais_count(); i++) {
|
|
712
|
+ String topic(SENSOR_LOCATION);
|
|
713
|
+ topic += String("/") + relais_name(i);
|
|
714
|
+ mqtt.subscribe(topic.c_str());
|
|
715
|
+ }
|
|
716
|
+#endif // FEATURE_RELAIS
|
|
717
|
+ }
|
|
718
|
+}
|
|
719
|
+#endif // ENABLE_MQTT
|
|
720
|
+
|
473
|
721
|
void setup() {
|
474
|
722
|
pinMode(BUILTIN_LED_PIN, OUTPUT);
|
475
|
723
|
|
476
|
|
-#ifdef ENABLE_RELAIS_TEST
|
477
|
|
- relais_init();
|
478
|
|
-#endif // ENABLE_RELAIS_TEST
|
|
724
|
+ Serial.begin(115200);
|
479
|
725
|
|
480
|
726
|
// Blink LED for init
|
481
|
727
|
for (int i = 0; i < 2; i++) {
|
|
@@ -484,45 +730,78 @@ void setup() {
|
484
|
730
|
digitalWrite(BUILTIN_LED_PIN, HIGH); // LED off
|
485
|
731
|
delay(LED_INIT_BLINK_INTERVAL);
|
486
|
732
|
}
|
|
733
|
+
|
|
734
|
+ Serial.print(F("Relais"));
|
|
735
|
+ relais_init();
|
487
|
736
|
|
|
737
|
+ Serial.print(F("Moisture"));
|
488
|
738
|
moisture_init();
|
489
|
739
|
|
490
|
740
|
// Init I2C and try to connect to sensors
|
491
|
741
|
#if defined(ARDUINO_ARCH_ESP8266)
|
492
|
742
|
|
|
743
|
+ Serial.print(F("Wire2"));
|
493
|
744
|
Wire2.begin(I2C_SDA_PIN, I2C_SCL_PIN);
|
|
745
|
+
|
|
746
|
+ Serial.print(F("BME"));
|
494
|
747
|
found_bme1 = (!bme1.begin(BME_I2C_ADDRESS_1, &Wire2)) ? false : true;
|
495
|
748
|
found_bme2 = (!bme2.begin(BME_I2C_ADDRESS_2, &Wire2)) ? false : true;
|
496
|
749
|
|
|
750
|
+#ifdef ENABLE_CCS811
|
|
751
|
+ Serial.print(F("CCS"));
|
|
752
|
+ found_ccs1 = ccs1.begin(CCS811_ADDRESS_1, &Wire2);
|
|
753
|
+ found_ccs2 = ccs2.begin(CCS811_ADDRESS_2, &Wire2);
|
|
754
|
+#endif // ENABLE_CCS811
|
|
755
|
+
|
497
|
756
|
#elif defined(ARDUINO_ARCH_ESP32)
|
498
|
757
|
|
|
758
|
+ Serial.print(F("Wire"));
|
499
|
759
|
Wire.begin();
|
|
760
|
+
|
|
761
|
+ Serial.print(F("BME"));
|
500
|
762
|
found_bme1 = (!bme1.begin(BME_I2C_ADDRESS_1, &Wire)) ? false : true;
|
501
|
763
|
found_bme2 = (!bme2.begin(BME_I2C_ADDRESS_2, &Wire)) ? false : true;
|
502
|
764
|
|
|
765
|
+#ifdef ENABLE_CCS811
|
|
766
|
+ Serial.print(F("CCS"));
|
|
767
|
+ found_ccs1 = ccs1.begin(CCS811_ADDRESS_1, &Wire);
|
|
768
|
+ found_ccs2 = ccs2.begin(CCS811_ADDRESS_2, &Wire);
|
|
769
|
+#endif // ENABLE_CCS811
|
|
770
|
+
|
503
|
771
|
#elif defined(ARDUINO_ARCH_AVR)
|
504
|
772
|
|
|
773
|
+ Serial.print(F("BME"));
|
505
|
774
|
found_bme1 = (!bme1.begin(BME_I2C_ADDRESS_1, &Wire)) ? false : true;
|
506
|
775
|
found_bme2 = (!bme2.begin(BME_I2C_ADDRESS_2, &Wire)) ? false : true;
|
507
|
776
|
|
|
777
|
+#ifdef ENABLE_CCS811
|
|
778
|
+ Serial.print(F("CCS"));
|
|
779
|
+ found_ccs1 = ccs1.begin(CCS811_ADDRESS_1, &Wire);
|
|
780
|
+ found_ccs2 = ccs2.begin(CCS811_ADDRESS_2, &Wire);
|
|
781
|
+#endif // ENABLE_CCS811
|
|
782
|
+
|
508
|
783
|
#endif
|
509
|
784
|
|
|
785
|
+ Serial.print(F("SHT"));
|
510
|
786
|
found_sht = sht.GetAlive();
|
511
|
787
|
|
512
|
788
|
// Build hostname string
|
513
|
789
|
String hostname = SENSOR_HOSTNAME_PREFIX;
|
514
|
|
- hostname += sensor_location;
|
|
790
|
+ hostname += SENSOR_LOCATION;
|
515
|
791
|
|
516
|
792
|
#if defined(ARDUINO_ARCH_ESP8266)
|
517
|
793
|
|
518
|
794
|
// Connect to WiFi AP
|
|
795
|
+ Serial.print(F("Connecting WiFi"));
|
519
|
796
|
WiFi.hostname(hostname);
|
520
|
797
|
WiFi.mode(WIFI_STA);
|
521
|
|
- WiFi.begin(ssid, password);
|
|
798
|
+ WiFi.begin(WIFI_SSID, WIFI_PASS);
|
522
|
799
|
while (WiFi.status() != WL_CONNECTED) {
|
523
|
800
|
delay(LED_CONNECT_BLINK_INTERVAL);
|
524
|
801
|
digitalWrite(BUILTIN_LED_PIN, !digitalRead(BUILTIN_LED_PIN));
|
|
802
|
+ Serial.print(F("."));
|
525
|
803
|
}
|
|
804
|
+ Serial.println(F("\nWiFi connected!"));
|
526
|
805
|
|
527
|
806
|
#elif defined(ARDUINO_ARCH_ESP32)
|
528
|
807
|
|
|
@@ -541,25 +820,27 @@ void setup() {
|
541
|
820
|
}, WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED);
|
542
|
821
|
|
543
|
822
|
// Connect to WiFi AP
|
|
823
|
+ Serial.print(F("Connecting WiFi"));
|
544
|
824
|
WiFi.mode(WIFI_STA);
|
545
|
|
- WiFi.begin(ssid, password);
|
|
825
|
+ WiFi.begin(WIFI_SSID, WIFI_PASS);
|
546
|
826
|
while (WiFi.status() != WL_CONNECTED) {
|
547
|
827
|
delay(LED_CONNECT_BLINK_INTERVAL);
|
548
|
828
|
digitalWrite(BUILTIN_LED_PIN, !digitalRead(BUILTIN_LED_PIN));
|
|
829
|
+ Serial.print(F("."));
|
549
|
830
|
}
|
|
831
|
+ Serial.println(F("\nWiFi connected!"));
|
550
|
832
|
|
551
|
833
|
// Set hostname workaround
|
552
|
834
|
WiFi.setHostname(hostname.c_str());
|
553
|
835
|
|
554
|
836
|
#elif defined(ARDUINO_ARCH_AVR)
|
555
|
837
|
|
556
|
|
- Serial.begin(115200);
|
557
|
838
|
Serial1.begin(115200);
|
558
|
839
|
|
559
|
840
|
WiFi.init(&Serial1);
|
560
|
841
|
|
561
|
842
|
Serial.print(F("Connecting WiFi"));
|
562
|
|
- WiFi.begin(ssid, password);
|
|
843
|
+ WiFi.begin(WIFI_SSID, WIFI_PASS);
|
563
|
844
|
while (WiFi.status() != WL_CONNECTED) {
|
564
|
845
|
delay(LED_CONNECT_BLINK_INTERVAL);
|
565
|
846
|
digitalWrite(BUILTIN_LED_PIN, !digitalRead(BUILTIN_LED_PIN));
|
|
@@ -569,20 +850,31 @@ void setup() {
|
569
|
850
|
|
570
|
851
|
#endif
|
571
|
852
|
|
|
853
|
+ Serial.println(F("Seeding"));
|
|
854
|
+ randomSeed(micros());
|
|
855
|
+
|
|
856
|
+#ifdef ENABLE_MQTT
|
|
857
|
+ Serial.println(F("MQTT"));
|
|
858
|
+ mqtt.setServer(MQTT_HOST, MQTT_PORT);
|
|
859
|
+ mqtt.setCallback(mqttCallback);
|
|
860
|
+#endif // ENABLE_MQTT
|
|
861
|
+
|
572
|
862
|
#ifdef ENABLE_INFLUXDB_LOGGING
|
573
|
|
- // Setup InfluxDB Client
|
|
863
|
+ Serial.println(F("Influx"));
|
574
|
864
|
influx.setDb(INFLUXDB_DATABASE);
|
575
|
865
|
#endif // ENABLE_INFLUXDB_LOGGING
|
576
|
866
|
|
577
|
867
|
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
578
|
868
|
// Setup HTTP Server
|
|
869
|
+ Serial.println(F("HTTP"));
|
579
|
870
|
MDNS.begin(hostname.c_str());
|
580
|
871
|
updater.setup(&server);
|
581
|
872
|
server.on("/", handleRoot);
|
582
|
873
|
|
583
|
|
-#ifdef ENABLE_RELAIS_TEST
|
584
|
|
- server.on("/relaistest", handleRelaisTest);
|
585
|
|
-#endif
|
|
874
|
+#ifdef FEATURE_RELAIS
|
|
875
|
+ server.on("/on", handleOn);
|
|
876
|
+ server.on("/off", handleOff);
|
|
877
|
+#endif // FEATURE_RELAIS
|
586
|
878
|
|
587
|
879
|
MDNS.addService("http", "tcp", 80);
|
588
|
880
|
#endif
|
|
@@ -614,7 +906,10 @@ void http_server() {
|
614
|
906
|
client.println(F("Content-Type: text/html"));
|
615
|
907
|
client.println(F("Connection: close"));
|
616
|
908
|
client.println();
|
|
909
|
+
|
|
910
|
+ // TODO parse path and handle different pages
|
617
|
911
|
handleRoot(client);
|
|
912
|
+
|
618
|
913
|
break;
|
619
|
914
|
}
|
620
|
915
|
|
|
@@ -680,7 +975,7 @@ void writeDatabase() {
|
680
|
975
|
InfluxData measurement("environment");
|
681
|
976
|
#endif
|
682
|
977
|
|
683
|
|
- measurement.addTag("location", sensor_location);
|
|
978
|
+ measurement.addTag("location", SENSOR_LOCATION);
|
684
|
979
|
measurement.addTag("placement", "1");
|
685
|
980
|
measurement.addTag("sensor", "bme280");
|
686
|
981
|
|
|
@@ -705,7 +1000,7 @@ void writeDatabase() {
|
705
|
1000
|
InfluxData measurement("environment");
|
706
|
1001
|
#endif
|
707
|
1002
|
|
708
|
|
- measurement.addTag("location", sensor_location);
|
|
1003
|
+ measurement.addTag("location", SENSOR_LOCATION);
|
709
|
1004
|
measurement.addTag("placement", "2");
|
710
|
1005
|
measurement.addTag("sensor", "bme280");
|
711
|
1006
|
|
|
@@ -730,7 +1025,7 @@ void writeDatabase() {
|
730
|
1025
|
InfluxData measurement("environment");
|
731
|
1026
|
#endif
|
732
|
1027
|
|
733
|
|
- measurement.addTag("location", sensor_location);
|
|
1028
|
+ measurement.addTag("location", SENSOR_LOCATION);
|
734
|
1029
|
measurement.addTag("sensor", "sht21");
|
735
|
1030
|
|
736
|
1031
|
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
|
@@ -744,7 +1039,66 @@ void writeDatabase() {
|
744
|
1039
|
writeMeasurement(measurement);
|
745
|
1040
|
Serial.println(F("Done!"));
|
746
|
1041
|
}
|
747
|
|
-
|
|
1042
|
+
|
|
1043
|
+#ifdef ENABLE_CCS811
|
|
1044
|
+
|
|
1045
|
+ if (found_ccs1) {
|
|
1046
|
+#if defined(ARDUINO_ARCH_AVR)
|
|
1047
|
+ measurement.clear();
|
|
1048
|
+ measurement.setName("environment");
|
|
1049
|
+#else
|
|
1050
|
+ InfluxData measurement("environment");
|
|
1051
|
+#endif
|
|
1052
|
+
|
|
1053
|
+ measurement.addTag("location", SENSOR_LOCATION);
|
|
1054
|
+ measurement.addTag("placement", "1");
|
|
1055
|
+ measurement.addTag("sensor", "ccs811");
|
|
1056
|
+
|
|
1057
|
+ String err(ccs1_error_code);
|
|
1058
|
+ measurement.addTag("error", err);
|
|
1059
|
+
|
|
1060
|
+#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
|
1061
|
+ measurement.addTag("device", WiFi.macAddress());
|
|
1062
|
+#endif
|
|
1063
|
+
|
|
1064
|
+ measurement.addValue("eco2", ccs1_eco2());
|
|
1065
|
+ measurement.addValue("tvoc", ccs1_tvoc());
|
|
1066
|
+
|
|
1067
|
+ Serial.println(F("Writing ccs1"));
|
|
1068
|
+ writeMeasurement(measurement);
|
|
1069
|
+ Serial.println(F("Done!"));
|
|
1070
|
+ }
|
|
1071
|
+
|
|
1072
|
+ if (found_ccs2) {
|
|
1073
|
+#if defined(ARDUINO_ARCH_AVR)
|
|
1074
|
+ measurement.clear();
|
|
1075
|
+ measurement.setName("environment");
|
|
1076
|
+#else
|
|
1077
|
+ InfluxData measurement("environment");
|
|
1078
|
+#endif
|
|
1079
|
+
|
|
1080
|
+ measurement.addTag("location", SENSOR_LOCATION);
|
|
1081
|
+ measurement.addTag("placement", "2");
|
|
1082
|
+ measurement.addTag("sensor", "ccs811");
|
|
1083
|
+
|
|
1084
|
+ String err(ccs2_error_code);
|
|
1085
|
+ measurement.addTag("error", err);
|
|
1086
|
+
|
|
1087
|
+#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
|
1088
|
+ measurement.addTag("device", WiFi.macAddress());
|
|
1089
|
+#endif
|
|
1090
|
+
|
|
1091
|
+ measurement.addValue("eco2", ccs2_eco2());
|
|
1092
|
+ measurement.addValue("tvoc", ccs2_tvoc());
|
|
1093
|
+
|
|
1094
|
+ Serial.println(F("Writing ccs2"));
|
|
1095
|
+ writeMeasurement(measurement);
|
|
1096
|
+ Serial.println(F("Done!"));
|
|
1097
|
+ }
|
|
1098
|
+
|
|
1099
|
+#endif // ENABLE_CCS811
|
|
1100
|
+
|
|
1101
|
+#ifdef FEATURE_MOISTURE
|
748
|
1102
|
for (int i = 0; i < moisture_count(); i++) {
|
749
|
1103
|
int moisture = moisture_read(i);
|
750
|
1104
|
if (moisture < moisture_max()) {
|
|
@@ -755,7 +1109,7 @@ void writeDatabase() {
|
755
|
1109
|
InfluxData measurement("moisture");
|
756
|
1110
|
#endif
|
757
|
1111
|
|
758
|
|
- measurement.addTag("location", sensor_location);
|
|
1112
|
+ measurement.addTag("location", SENSOR_LOCATION);
|
759
|
1113
|
String sensor(i + 1, DEC);
|
760
|
1114
|
measurement.addTag("sensor", sensor);
|
761
|
1115
|
|
|
@@ -772,29 +1126,89 @@ void writeDatabase() {
|
772
|
1126
|
Serial.println(F("Done!"));
|
773
|
1127
|
}
|
774
|
1128
|
}
|
|
1129
|
+#endif // FEATURE_MOISTURE
|
|
1130
|
+
|
|
1131
|
+#ifdef FEATURE_RELAIS
|
|
1132
|
+ for (int i = 0; i < relais_count(); i++) {
|
|
1133
|
+ InfluxData measurement("relais");
|
|
1134
|
+ measurement.addTag("location", SENSOR_LOCATION);
|
|
1135
|
+ measurement.addTag("id", String(i));
|
|
1136
|
+ measurement.addTag("name", relais_name(i));
|
|
1137
|
+
|
|
1138
|
+#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
|
1139
|
+ measurement.addTag("device", WiFi.macAddress());
|
|
1140
|
+#endif
|
|
1141
|
+
|
|
1142
|
+ measurement.addValue("state", relais_get(i));
|
|
1143
|
+ writeMeasurement(measurement);
|
|
1144
|
+ }
|
|
1145
|
+#endif // FEATURE_RELAIS
|
775
|
1146
|
|
776
|
1147
|
Serial.println(F("All Done!"));
|
777
|
1148
|
}
|
778
|
1149
|
#endif // ENABLE_INFLUXDB_LOGGING
|
779
|
1150
|
|
|
1151
|
+#ifdef ENABLE_CCS811
|
|
1152
|
+void ccs_update() {
|
|
1153
|
+ if (found_ccs1) {
|
|
1154
|
+ if (ccs1.available()) {
|
|
1155
|
+ ccs1_error_code = ccs1.readData();
|
|
1156
|
+ ccs1_data_valid = (ccs1_error_code == 0);
|
|
1157
|
+
|
|
1158
|
+ if (found_bme1) {
|
|
1159
|
+ ccs1.setEnvironmentalData(bme1_humid(), bme1_temp());
|
|
1160
|
+ } else if (found_bme2) {
|
|
1161
|
+ ccs1.setEnvironmentalData(bme2_humid(), bme2_temp());
|
|
1162
|
+ } else if (found_sht) {
|
|
1163
|
+ ccs1.setEnvironmentalData(sht_humid(), sht_temp());
|
|
1164
|
+ }
|
|
1165
|
+ }
|
|
1166
|
+ }
|
|
1167
|
+
|
|
1168
|
+ if (found_ccs2) {
|
|
1169
|
+ if (ccs2.available()) {
|
|
1170
|
+ ccs2_error_code = ccs2.readData();
|
|
1171
|
+ ccs2_data_valid = (ccs2_error_code == 0);
|
|
1172
|
+
|
|
1173
|
+ if (found_bme1) {
|
|
1174
|
+ ccs2.setEnvironmentalData(bme1_humid(), bme1_temp());
|
|
1175
|
+ } else if (found_bme2) {
|
|
1176
|
+ ccs2.setEnvironmentalData(bme2_humid(), bme2_temp());
|
|
1177
|
+ } else if (found_sht) {
|
|
1178
|
+ ccs2.setEnvironmentalData(sht_humid(), sht_temp());
|
|
1179
|
+ }
|
|
1180
|
+ }
|
|
1181
|
+ }
|
|
1182
|
+}
|
|
1183
|
+#endif // ENABLE_CCS811
|
|
1184
|
+
|
780
|
1185
|
void loop() {
|
781
|
1186
|
unsigned long time = millis();
|
782
|
1187
|
|
783
|
|
-#ifdef ENABLE_RELAIS_TEST
|
784
|
|
- relais_run();
|
785
|
|
-#endif // ENABLE_RELAIS_TEST
|
|
1188
|
+#ifdef ENABLE_CCS811
|
|
1189
|
+ if (found_ccs1 || found_ccs2) {
|
|
1190
|
+ ccs_update();
|
|
1191
|
+ }
|
|
1192
|
+#endif // ENABLE_CCS811
|
786
|
1193
|
|
787
|
1194
|
if ((time - last_server_handle_time) >= SERVER_HANDLE_INTERVAL) {
|
788
|
1195
|
last_server_handle_time = time;
|
789
|
1196
|
handleServers();
|
790
|
1197
|
}
|
791
|
1198
|
|
792
|
|
-#ifdef ENABLE_INFLUXDB_LOGGING
|
793
|
1199
|
if ((time - last_db_write_time) >= DB_WRITE_INTERVAL) {
|
794
|
1200
|
last_db_write_time = time;
|
|
1201
|
+
|
|
1202
|
+#ifdef ENABLE_INFLUXDB_LOGGING
|
795
|
1203
|
writeDatabase();
|
|
1204
|
+#endif // ENABLE_INFLUXDB_LOGGING
|
|
1205
|
+
|
|
1206
|
+#ifdef ENABLE_MQTT
|
|
1207
|
+ writeMQTT();
|
|
1208
|
+#endif // ENABLE_MQTT
|
796
|
1209
|
}
|
797
|
1210
|
|
|
1211
|
+#ifdef ENABLE_INFLUXDB_LOGGING
|
798
|
1212
|
#ifdef INFLUX_MAX_ERRORS_RESET
|
799
|
1213
|
if (error_count >= INFLUX_MAX_ERRORS_RESET) {
|
800
|
1214
|
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
|
@@ -804,6 +1218,15 @@ void loop() {
|
804
|
1218
|
#endif // INFLUX_MAX_ERRORS_RESET
|
805
|
1219
|
#endif // ENABLE_INFLUXDB_LOGGING
|
806
|
1220
|
|
|
1221
|
+#ifdef ENABLE_MQTT
|
|
1222
|
+ if (!mqtt.connected() && ((millis() - last_mqtt_reconnect_time) >= MQTT_RECONNECT_INTERVAL)) {
|
|
1223
|
+ last_mqtt_reconnect_time = millis();
|
|
1224
|
+ mqttReconnect();
|
|
1225
|
+ }
|
|
1226
|
+
|
|
1227
|
+ mqtt.loop();
|
|
1228
|
+#endif // ENABLE_MQTT
|
|
1229
|
+
|
807
|
1230
|
// blink heartbeat LED
|
808
|
1231
|
if ((time - last_led_blink_time) >= LED_BLINK_INTERVAL) {
|
809
|
1232
|
last_led_blink_time = time;
|
|
@@ -811,10 +1234,9 @@ void loop() {
|
811
|
1234
|
}
|
812
|
1235
|
|
813
|
1236
|
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
814
|
|
- // reset ESP every 6h to be safe
|
815
|
|
- if (time >= (6 * 60 * 60 * 1000)) {
|
|
1237
|
+ // reset ESP every 3d to be safe
|
|
1238
|
+ if (time >= (3UL * 24UL * 60UL * 60UL * 1000UL)) {
|
816
|
1239
|
ESP.restart();
|
817
|
1240
|
}
|
818
|
1241
|
#endif
|
819
|
1242
|
}
|
820
|
|
-
|