|
@@ -83,12 +83,12 @@ void handleAutoTimingCheck(void) {
|
83
|
83
|
// small light from 20:00 to 10:00
|
84
|
84
|
relais_state[0] = true;
|
85
|
85
|
relais_state[1] = false;
|
86
|
|
- auto_set_state = F("Small Light at Night (") + timeClient.getFormattedTime() + F(")");
|
|
86
|
+ auto_set_state = String(F("Small Light at Night (")) + String(timeClient.getFormattedTime()) + String(F(")"));
|
87
|
87
|
} else {
|
88
|
88
|
// big light from 10:00 to 20:00
|
89
|
89
|
relais_state[0] = false;
|
90
|
90
|
relais_state[1] = true;
|
91
|
|
- auto_set_state = F("Big Light while Daylight (") + timeClient.getFormattedTime() + F(")");
|
|
91
|
+ auto_set_state = String(F("Big Light while Daylight (")) + String(timeClient.getFormattedTime()) + String(F(")"));
|
92
|
92
|
}
|
93
|
93
|
|
94
|
94
|
for (int i = 0; i < RELAIS_COUNT; i++) {
|
|
@@ -128,7 +128,7 @@ void handlePage(int mode = -1, int id = 0) {
|
128
|
128
|
|
129
|
129
|
#ifdef ENABLE_NTP
|
130
|
130
|
message += F("<p>Time from NTP: ");
|
131
|
|
- message += timeClient.getFormattedTime();
|
|
131
|
+ message += String(timeClient.getFormattedTime());
|
132
|
132
|
message += F("</p>\n");
|
133
|
133
|
|
134
|
134
|
message += F("<p>Auto-State: ");
|
|
@@ -141,12 +141,14 @@ void handlePage(int mode = -1, int id = 0) {
|
141
|
141
|
message += F("min</p>\n");
|
142
|
142
|
#endif // ENABLE_NTP
|
143
|
143
|
|
|
144
|
+ message += F("<p><a href=\"/\">Refresh Page</a></p>\n");
|
|
145
|
+
|
144
|
146
|
message += F("\n<p>\n");
|
145
|
147
|
message += F("Version: ");
|
146
|
|
- message += esp_relais_version;
|
|
148
|
+ message += ESP_RELAIS_VERSION;
|
147
|
149
|
message += F("\n<br>\n");
|
148
|
150
|
message += F("Location: ");
|
149
|
|
- message += sensor_location;
|
|
151
|
+ message += SENSOR_LOCATION;
|
150
|
152
|
message += F("\n<br>\n");
|
151
|
153
|
message += F("MAC: ");
|
152
|
154
|
message += WiFi.macAddress();
|
|
@@ -307,7 +309,7 @@ void mqttReconnect() {
|
307
|
309
|
// Once connected, publish an announcement...
|
308
|
310
|
//mqtt.publish("outTopic", "hello world");
|
309
|
311
|
// ... and resubscribe
|
310
|
|
- mqtt.subscribe(sensor_location);
|
|
312
|
+ mqtt.subscribe(SENSOR_LOCATION);
|
311
|
313
|
} else {
|
312
|
314
|
// Wait 5 seconds before retrying
|
313
|
315
|
delay(5000);
|
|
@@ -338,21 +340,26 @@ void setup() {
|
338
|
340
|
|
339
|
341
|
// Build hostname string
|
340
|
342
|
String hostname = SENSOR_HOSTNAME_PREFIX;
|
341
|
|
- hostname += sensor_location;
|
|
343
|
+ hostname += SENSOR_LOCATION;
|
342
|
344
|
|
343
|
345
|
#if defined(ARDUINO_ARCH_ESP8266)
|
344
|
346
|
|
345
|
347
|
// Connect to WiFi AP
|
346
|
|
- Serial.print("Connecting to WiFi");
|
|
348
|
+ Serial.print("Connecting to WiFi ");
|
347
|
349
|
WiFi.hostname(hostname);
|
348
|
350
|
WiFi.mode(WIFI_STA);
|
349
|
|
- WiFi.begin(ssid, password);
|
|
351
|
+ WiFi.begin(WIFI_SSID, WIFI_PASS);
|
350
|
352
|
while (WiFi.status() != WL_CONNECTED) {
|
351
|
|
- Serial.print(".");
|
|
353
|
+ Serial.print(WiFi.status());
|
|
354
|
+ Serial.print(" ");
|
|
355
|
+
|
352
|
356
|
delay(LED_CONNECT_BLINK_INTERVAL);
|
353
|
357
|
digitalWrite(BUILTIN_LED_PIN, !digitalRead(BUILTIN_LED_PIN));
|
354
|
358
|
}
|
355
|
359
|
Serial.println();
|
|
360
|
+
|
|
361
|
+ Serial.print("Got local IP ");
|
|
362
|
+ Serial.println(WiFi.localIP().toString());
|
356
|
363
|
|
357
|
364
|
#elif defined(ARDUINO_ARCH_ESP32)
|
358
|
365
|
|
|
@@ -371,12 +378,15 @@ void setup() {
|
371
|
378
|
}, WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED);
|
372
|
379
|
|
373
|
380
|
// Connect to WiFi AP
|
|
381
|
+ Serial.print("Connecting to WiFi");
|
374
|
382
|
WiFi.mode(WIFI_STA);
|
375
|
|
- WiFi.begin(ssid, password);
|
|
383
|
+ WiFi.begin(WIFI_SSID, WIFI_PASS);
|
376
|
384
|
while (WiFi.status() != WL_CONNECTED) {
|
|
385
|
+ Serial.print(".");
|
377
|
386
|
delay(LED_CONNECT_BLINK_INTERVAL);
|
378
|
387
|
digitalWrite(BUILTIN_LED_PIN, !digitalRead(BUILTIN_LED_PIN));
|
379
|
388
|
}
|
|
389
|
+ Serial.println();
|
380
|
390
|
|
381
|
391
|
// Set hostname workaround
|
382
|
392
|
WiFi.setHostname(hostname.c_str());
|
|
@@ -440,7 +450,7 @@ static boolean writeMeasurement(InfluxData &measurement) {
|
440
|
450
|
void writeDatabase() {
|
441
|
451
|
if (found_bme1) {
|
442
|
452
|
InfluxData measurement("environment");
|
443
|
|
- measurement.addTag("location", sensor_location);
|
|
453
|
+ measurement.addTag("location", SENSOR_LOCATION);
|
444
|
454
|
measurement.addTag("placement", "1");
|
445
|
455
|
measurement.addTag("device", WiFi.macAddress());
|
446
|
456
|
measurement.addTag("sensor", "bme280");
|
|
@@ -453,7 +463,7 @@ void writeDatabase() {
|
453
|
463
|
}
|
454
|
464
|
if (found_bme2) {
|
455
|
465
|
InfluxData measurement("environment");
|
456
|
|
- measurement.addTag("location", sensor_location);
|
|
466
|
+ measurement.addTag("location", SENSOR_LOCATION);
|
457
|
467
|
measurement.addTag("placement", "2");
|
458
|
468
|
measurement.addTag("device", WiFi.macAddress());
|
459
|
469
|
measurement.addTag("sensor", "bme280");
|
|
@@ -467,7 +477,7 @@ void writeDatabase() {
|
467
|
477
|
|
468
|
478
|
if (found_sht) {
|
469
|
479
|
InfluxData measurement("environment");
|
470
|
|
- measurement.addTag("location", sensor_location);
|
|
480
|
+ measurement.addTag("location", SENSOR_LOCATION);
|
471
|
481
|
measurement.addTag("device", WiFi.macAddress());
|
472
|
482
|
measurement.addTag("sensor", "sht21");
|
473
|
483
|
|
|
@@ -481,7 +491,7 @@ void writeDatabase() {
|
481
|
491
|
int moisture = moisture_read(i);
|
482
|
492
|
if (moisture < moisture_max()) {
|
483
|
493
|
InfluxData measurement("moisture");
|
484
|
|
- measurement.addTag("location", sensor_location);
|
|
494
|
+ measurement.addTag("location", SENSOR_LOCATION);
|
485
|
495
|
measurement.addTag("device", WiFi.macAddress());
|
486
|
496
|
measurement.addTag("sensor", String(i + 1));
|
487
|
497
|
|
|
@@ -537,8 +547,8 @@ void loop() {
|
537
|
547
|
digitalWrite(BUILTIN_LED_PIN, !digitalRead(BUILTIN_LED_PIN));
|
538
|
548
|
}
|
539
|
549
|
|
540
|
|
- // reset ESP every 6h to be safe
|
541
|
|
- if (millis() >= (6 * 60 * 60 * 1000)) {
|
|
550
|
+ // reset ESP every 48h to be safe
|
|
551
|
+ if (millis() >= (48 * 60 * 60 * 1000)) {
|
542
|
552
|
ESP.restart();
|
543
|
553
|
}
|
544
|
554
|
}
|