From 368538652d35b2752c2c5e1ee6d80c1b8dc049ea Mon Sep 17 00:00:00 2001 From: Emmanuel Lacour Date: Wed, 22 Dec 2021 22:01:44 +0100 Subject: [PATCH 01/10] Fix wifi reconnect --- station-meteo/station-meteo.ino | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/station-meteo/station-meteo.ino b/station-meteo/station-meteo.ino index 589c4bb..5a96ba8 100644 --- a/station-meteo/station-meteo.ino +++ b/station-meteo/station-meteo.ino @@ -73,10 +73,15 @@ void setup(void) Serial.println(wifi_ssid); // Connect to WPA/WPA2 network WiFi.begin(wifi_ssid, wifi_pass); + delay(500); // attempt to connect to Wifi network: while (WiFi.status() != WL_CONNECTED) { + WiFi.begin(wifi_ssid, wifi_pass); delay(500); + if (WiFi.status() != WL_CONNECTED) { + delay(2000); + } } Serial.println("Connected to wifi"); @@ -92,13 +97,12 @@ void loop(void) { delay(POLL_INT); - // Check wifi connexion - if ( WiFi.status() != WL_CONNECTED ) { - int retry = 0; + // Reconnect if needed + while (WiFi.status() != WL_CONNECTED) { WiFi.begin(wifi_ssid, wifi_pass); - while (retry < 10 || WiFi.status() != WL_CONNECTED) { - retry++; - delay(500); + delay(500); + if (WiFi.status() != WL_CONNECTED) { + delay(2000); } } -- 2.11.0 From 515ce14812a6921cfc8001126726d7851baa5691 Mon Sep 17 00:00:00 2001 From: Emmanuel Lacour Date: Tue, 5 Apr 2022 18:26:43 +0200 Subject: [PATCH 02/10] Switch to DallasTemperature for DS18B20 --- garage/garage.ino | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/garage/garage.ino b/garage/garage.ino index 2467f07..a6c20cc 100644 --- a/garage/garage.ino +++ b/garage/garage.ino @@ -1,9 +1,8 @@ #include #include #include -#include -#include -#include +#include +#include #include #include "garage-config.h" @@ -25,9 +24,12 @@ String location = LOCATION; WiFiUDP Udp; // Temp -#define DHTPIN 19 -#define DHTTYPE DHT22 -DHT_Unified dht(DHTPIN, DHTTYPE); +// GPIO where the DS18B20 is connected to +const int oneWireBus = 19; +// Setup a oneWire instance to communicate with any OneWire devices +OneWire oneWire(oneWireBus); +// Pass our oneWire reference to Dallas Temperature sensor +DallasTemperature sensors(&oneWire); // Uptime timer boolean tick1sec=0;// one for interrupt, don't mess with @@ -66,10 +68,7 @@ void setup() { delay(500); } - dht.begin(); - sensor_t sensor; - dht.temperature().getSensor(&sensor); - dht.humidity().getSensor(&sensor); + sensors.begin(); tinfo.init(TINFO_MODE_STD); tinfo.attachDataStd(DataCallback); @@ -96,20 +95,16 @@ void loop() { if ( WiFi.status() == WL_CONNECTED ) { Serial.println("DEBUG wifi connected, start temp measure"); - sensors_event_t event; + + sensors.requestTemperatures(); + float tempC = sensors.getTempCByIndex(0); - dht.temperature().getEvent(&event); - if (isnan(event.temperature)) { + if(tempC == DEVICE_DISCONNECTED_C) // Error } else { - sendToInfluxDB("temperature,city="+city+",location="+location, "value", String(event.temperature)); - } - dht.humidity().getEvent(&event); - if (isnan(event.relative_humidity)) { - // Error - } else { - sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(event.relative_humidity)); + sendToInfluxDB("temperature,city="+city+",location=serre_semis", "value", String(tempC)); } + sendToInfluxDB("teleinfo,city="+city+",location="+location, "SINSTS", tinfo_SINSTS); sendToInfluxDB("teleinfo,city="+city+",location="+location, "SINSTS1", tinfo_SINSTS1); sendToInfluxDB("teleinfo,city="+city+",location="+location, "SINSTS2", tinfo_SINSTS2); -- 2.11.0 From d42844bdb392e515545d30fca9f2cc52681b215a Mon Sep 17 00:00:00 2001 From: Emmanuel Lacour Date: Tue, 5 Apr 2022 18:27:04 +0200 Subject: [PATCH 03/10] Fix wifi reconnect --- garage/garage.ino | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/garage/garage.ino b/garage/garage.ino index a6c20cc..44f2c49 100644 --- a/garage/garage.ino +++ b/garage/garage.ino @@ -63,9 +63,14 @@ void setup() { WiFi.mode(WIFI_STA); WiFi.begin(WIFI_SSID, WIFI_PASS); - + delay(500); + while (WiFi.status() != WL_CONNECTED) { + WiFi.begin(wifi_ssid, wifi_pass); delay(500); + if (WiFi.status() != WL_CONNECTED) { + delay(2000); + } } sensors.begin(); @@ -82,14 +87,12 @@ void loop() { fulldata = true; previousMillis = millis(); - // Check wifi connexion - if ( WiFi.status() != WL_CONNECTED ) { - int retry = 0; - WiFi.mode(WIFI_STA); + // Reconnect if needed + while (WiFi.status() != WL_CONNECTED) { WiFi.begin(WIFI_SSID, WIFI_PASS); - while (retry < 10 || WiFi.status() != WL_CONNECTED) { - retry++; - delay(500); + delay(500); + if (WiFi.status() != WL_CONNECTED) { + delay(2000); } } -- 2.11.0 From 479c6a499e7ab2649c78f1197e1af2478f944c83 Mon Sep 17 00:00:00 2001 From: Emmanuel Lacour Date: Mon, 4 Jul 2022 22:24:16 +0200 Subject: [PATCH 04/10] Add software debouncing --- station-meteo/station-meteo.ino | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/station-meteo/station-meteo.ino b/station-meteo/station-meteo.ino index 5a96ba8..dc4cc21 100644 --- a/station-meteo/station-meteo.ino +++ b/station-meteo/station-meteo.ino @@ -29,10 +29,8 @@ String location = LOCATION; int rainfall_sensor_pin = 2; float rain_incr = 0.2794; // this is mm/m2 for each sensor tick int rainfall_ticks = 0; - -// Timing -unsigned long previousMillis= 0; -unsigned long previousMillis2= 0; +long debouncing_time = 30; +volatile unsigned long last_micros; // Initiate udp client WiFiUDP udp; @@ -178,5 +176,8 @@ void printWifiStatus() { void getRain () { - rainfall_ticks ++ ; + if((long)(micros() - last_micros) >= debouncing_time * 1000) { + rainfall_ticks ++ ; + last_micros = micros(); + } } -- 2.11.0 From 4c8b87c67b233c5b9690f3c0f5d0a16259738f84 Mon Sep 17 00:00:00 2001 From: Emmanuel Lacour Date: Sun, 4 Dec 2022 12:04:27 +0100 Subject: [PATCH 05/10] Add heater sensors --- garage/garage.ino | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/garage/garage.ino b/garage/garage.ino index 44f2c49..9a663f5 100644 --- a/garage/garage.ino +++ b/garage/garage.ino @@ -100,9 +100,29 @@ void loop() { Serial.println("DEBUG wifi connected, start temp measure"); sensors.requestTemperatures(); - float tempC = sensors.getTempCByIndex(0); + float tempC = sensors.getTempCByIndex(1); + float heater_out_tempC = sensors.getTempCByIndex(0); + float heater_in_tempC = sensors.getTempCByIndex(2); - if(tempC == DEVICE_DISCONNECTED_C) + if(tempC == DEVICE_DISCONNECTED_C) { + // Error + } else { + sendToInfluxDB("temperature,city="+city+",location=serre_semis", "value", String(tempC)); + } + + if(heater_out_tempC == DEVICE_DISCONNECTED_C) { + // Error + } else { + sendToInfluxDB("temperature,city="+city+",location=heater,direction=out", "value", String(heater_out_tempC)); + } + + if(heater_in_tempC == DEVICE_DISCONNECTED_C) { + // Error + } else { + sendToInfluxDB("temperature,city="+city+",location=heater,direction=in", "value", String(heater_in_tempC)); + } + + if(tempC == DEVICE_DISCONNECTED_C) { // Error } else { sendToInfluxDB("temperature,city="+city+",location=serre_semis", "value", String(tempC)); -- 2.11.0 From 3c3433a22cf4e23ad916f4985f4bcfeb53307cad Mon Sep 17 00:00:00 2001 From: Emmanuel Lacour Date: Sun, 4 Dec 2022 14:48:03 +0100 Subject: [PATCH 06/10] Use sensors adresses --- garage/garage.ino | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/garage/garage.ino b/garage/garage.ino index 9a663f5..9fba061 100644 --- a/garage/garage.ino +++ b/garage/garage.ino @@ -27,6 +27,10 @@ WiFiUDP Udp; // GPIO where the DS18B20 is connected to const int oneWireBus = 19; // Setup a oneWire instance to communicate with any OneWire devices +// ROM = 28 31 A7 1D 13 21 1 F6 ROM = 28 15 8E 4B 13 21 1 46 +DeviceAddress sensor_heater_out = {0x28, 0x31, 0xA7, 0x1D, 0x13, 0x21, 0x01, 0xF6}; +DeviceAddress sensor_serre = {0x28, 0x15, 0x8E, 0x4B, 0x13, 0x21, 0x01, 0x46}; +//DeviceAddress sensor_heater_in = {0x28, 0x31, 0xA7, 0x1D, 0x13, 0x21, 0x01, 0xF6}; OneWire oneWire(oneWireBus); // Pass our oneWire reference to Dallas Temperature sensor DallasTemperature sensors(&oneWire); @@ -100,14 +104,14 @@ void loop() { Serial.println("DEBUG wifi connected, start temp measure"); sensors.requestTemperatures(); - float tempC = sensors.getTempCByIndex(1); - float heater_out_tempC = sensors.getTempCByIndex(0); - float heater_in_tempC = sensors.getTempCByIndex(2); + float serre_tempC = sensors.getTempC(sensor_serre); + float heater_out_tempC = sensors.getTempC(sensor_heater_out); + // float heater_in_tempC = sensors.getTempC(sensor_heater_in); - if(tempC == DEVICE_DISCONNECTED_C) { + if(serre_tempC == DEVICE_DISCONNECTED_C) { // Error } else { - sendToInfluxDB("temperature,city="+city+",location=serre_semis", "value", String(tempC)); + sendToInfluxDB("temperature,city="+city+",location=serre_semis", "value", String(serre_tempC)); } if(heater_out_tempC == DEVICE_DISCONNECTED_C) { @@ -116,17 +120,11 @@ void loop() { sendToInfluxDB("temperature,city="+city+",location=heater,direction=out", "value", String(heater_out_tempC)); } - if(heater_in_tempC == DEVICE_DISCONNECTED_C) { - // Error - } else { - sendToInfluxDB("temperature,city="+city+",location=heater,direction=in", "value", String(heater_in_tempC)); - } - - if(tempC == DEVICE_DISCONNECTED_C) { - // Error - } else { - sendToInfluxDB("temperature,city="+city+",location=serre_semis", "value", String(tempC)); - } + //if(heater_in_tempC == DEVICE_DISCONNECTED_C) { + // // Error + //} else { + // sendToInfluxDB("temperature,city="+city+",location=heater,direction=in", "value", String(heater_in_tempC)); + //} sendToInfluxDB("teleinfo,city="+city+",location="+location, "SINSTS", tinfo_SINSTS); sendToInfluxDB("teleinfo,city="+city+",location="+location, "SINSTS1", tinfo_SINSTS1); -- 2.11.0 From 2c31e3fadfad7940d8f5d9de194e07985fe463d7 Mon Sep 17 00:00:00 2001 From: Emmanuel Lacour Date: Sun, 4 Dec 2022 14:48:24 +0100 Subject: [PATCH 07/10] Add sketch to list onewire connected sensors --- getonewireaddrs/getonewireaddr/getonewireaddr.ino | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 getonewireaddrs/getonewireaddr/getonewireaddr.ino diff --git a/getonewireaddrs/getonewireaddr/getonewireaddr.ino b/getonewireaddrs/getonewireaddr/getonewireaddr.ino new file mode 100644 index 0000000..6cfa27f --- /dev/null +++ b/getonewireaddrs/getonewireaddr/getonewireaddr.ino @@ -0,0 +1,32 @@ +/* + * Rui Santos + * Complete Project Details https://randomnerdtutorials.com + */ + +#include + +// Based on the OneWire library example + +OneWire ds(19); //data wire connected to GPIO 4 + +void setup(void) { + Serial.begin(115200); +} + +void loop(void) { + byte i; + byte addr[8]; + + if (!ds.search(addr)) { + Serial.println(" No more addresses."); + Serial.println(); + ds.reset_search(); + delay(250); + return; + } + Serial.print(" ROM ="); + for (i = 0; i < 8; i++) { + Serial.write(' '); + Serial.print(addr[i], HEX); + } +} -- 2.11.0 From db61d93b984bb7d590fed6ca6b6046a73fed77f3 Mon Sep 17 00:00:00 2001 From: Emmanuel Lacour Date: Sun, 4 Dec 2022 15:10:20 +0100 Subject: [PATCH 08/10] Fix typo in location name --- garage/garage.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/garage/garage.ino b/garage/garage.ino index 9fba061..4b807d6 100644 --- a/garage/garage.ino +++ b/garage/garage.ino @@ -111,7 +111,7 @@ void loop() { if(serre_tempC == DEVICE_DISCONNECTED_C) { // Error } else { - sendToInfluxDB("temperature,city="+city+",location=serre_semis", "value", String(serre_tempC)); + sendToInfluxDB("temperature,city="+city+",location=serre-semis", "value", String(serre_tempC)); } if(heater_out_tempC == DEVICE_DISCONNECTED_C) { -- 2.11.0 From d02b9cb2c4647b9d4524bd6c36ce732741873892 Mon Sep 17 00:00:00 2001 From: Emmanuel Lacour Date: Mon, 5 Dec 2022 13:10:28 +0100 Subject: [PATCH 09/10] Add input heater temperature sensor --- garage/garage.ino | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/garage/garage.ino b/garage/garage.ino index 4b807d6..fbe2d77 100644 --- a/garage/garage.ino +++ b/garage/garage.ino @@ -27,10 +27,10 @@ WiFiUDP Udp; // GPIO where the DS18B20 is connected to const int oneWireBus = 19; // Setup a oneWire instance to communicate with any OneWire devices -// ROM = 28 31 A7 1D 13 21 1 F6 ROM = 28 15 8E 4B 13 21 1 46 +// ROM = 28 C6 C9 81 E3 6E 3C C ROM = 28 31 A7 1D 13 21 1 F6 ROM = 28 15 8E 4B 13 21 1 46 No more addresses. DeviceAddress sensor_heater_out = {0x28, 0x31, 0xA7, 0x1D, 0x13, 0x21, 0x01, 0xF6}; DeviceAddress sensor_serre = {0x28, 0x15, 0x8E, 0x4B, 0x13, 0x21, 0x01, 0x46}; -//DeviceAddress sensor_heater_in = {0x28, 0x31, 0xA7, 0x1D, 0x13, 0x21, 0x01, 0xF6}; +DeviceAddress sensor_heater_in = {0x28, 0xC6, 0xC9, 0x81, 0xE3, 0x6E, 0x3C ,0x0C}; OneWire oneWire(oneWireBus); // Pass our oneWire reference to Dallas Temperature sensor DallasTemperature sensors(&oneWire); @@ -106,7 +106,7 @@ void loop() { sensors.requestTemperatures(); float serre_tempC = sensors.getTempC(sensor_serre); float heater_out_tempC = sensors.getTempC(sensor_heater_out); - // float heater_in_tempC = sensors.getTempC(sensor_heater_in); + float heater_in_tempC = sensors.getTempC(sensor_heater_in); if(serre_tempC == DEVICE_DISCONNECTED_C) { // Error @@ -120,11 +120,11 @@ void loop() { sendToInfluxDB("temperature,city="+city+",location=heater,direction=out", "value", String(heater_out_tempC)); } - //if(heater_in_tempC == DEVICE_DISCONNECTED_C) { - // // Error - //} else { - // sendToInfluxDB("temperature,city="+city+",location=heater,direction=in", "value", String(heater_in_tempC)); - //} + if(heater_in_tempC == DEVICE_DISCONNECTED_C) { + // Error + } else { + sendToInfluxDB("temperature,city="+city+",location=heater,direction=in", "value", String(heater_in_tempC)); + } sendToInfluxDB("teleinfo,city="+city+",location="+location, "SINSTS", tinfo_SINSTS); sendToInfluxDB("teleinfo,city="+city+",location="+location, "SINSTS1", tinfo_SINSTS1); -- 2.11.0 From 26d0aa5a3d6ca68c288311beb17017d6e0631da7 Mon Sep 17 00:00:00 2001 From: Emmanuel Lacour Date: Wed, 3 Jan 2024 12:29:20 +0100 Subject: [PATCH 10/10] Add "grande chambre" (using esp8266 nodemcu) --- grande-chambre/grande-chambre-config.h.in | 13 +++++ grande-chambre/grande-chambre.ino | 83 +++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 grande-chambre/grande-chambre-config.h.in create mode 100644 grande-chambre/grande-chambre.ino diff --git a/grande-chambre/grande-chambre-config.h.in b/grande-chambre/grande-chambre-config.h.in new file mode 100644 index 0000000..4a1402d --- /dev/null +++ b/grande-chambre/grande-chambre-config.h.in @@ -0,0 +1,13 @@ +// Enable debug on serial port +#define DEBUG 1 +// Wifi +#define WIFI_SSID "XXXXXX" +#define WIFI_PASS "xxxxxx" +// InfluxDB +#define INFLUXDB_IP {w,x,y,z} +#define INFLUXDB_PORT xxxx +// Polling interval (ms) +#define POLL_INT 10000 +// Location informations +#define CITY "xxxxx" +#define LOCATION "xxxxx" diff --git a/grande-chambre/grande-chambre.ino b/grande-chambre/grande-chambre.ino new file mode 100644 index 0000000..0d36ca5 --- /dev/null +++ b/grande-chambre/grande-chambre.ino @@ -0,0 +1,83 @@ +// Board ESP8266 - NodeMCU 1.0 (ESP-12E module) +#include +#include +#include +#include +#include +#include + +#include "grande-chambre-config.h" + +const char* wifi_ssid = WIFI_SSID; +const char* wifi_pass = WIFI_PASS; + +// Grafana +IPAddress influxdb_ip(INFLUXDB_IP); +long influxdb_port = INFLUXDB_PORT; +unsigned int localPort = 2390; +// MilliSeconds +long unsigned poll_int = POLL_INT; +String city = CITY; +String location = LOCATION; +WiFiUDP Udp; + +// Temp +// 5 = D1 on esp8266 +#define DHTPIN 5 +#define DHTTYPE DHT22 +DHT_Unified dht(DHTPIN, DHTTYPE); + +void setup() { + + Serial.begin(9600); + // Not for esp8266 WiFi.mode(WIFI_STA); + WiFi.begin(WIFI_SSID, WIFI_PASS); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + } + + dht.begin(); + sensor_t sensor; + dht.temperature().getSensor(&sensor); + dht.humidity().getSensor(&sensor); + +} + +void loop() { + delay(POLL_INT); + // Check wifi connexion + if ( WiFi.status() != WL_CONNECTED ) { + int retry = 0; + // Not for esp8266 WiFi.mode(WIFI_STA); + WiFi.begin(WIFI_SSID, WIFI_PASS); + while (retry < 10 || WiFi.status() != WL_CONNECTED) { + retry++; + delay(500); + } + } + + if ( WiFi.status() == WL_CONNECTED ) { + sensors_event_t event; + + dht.temperature().getEvent(&event); + if (isnan(event.temperature)) { + // Error + } else { + sendToInfluxDB("temperature,city="+city+",location="+location, "value", String(event.temperature)); + } + dht.humidity().getEvent(&event); + if (isnan(event.relative_humidity)) { + // Error + } else { + sendToInfluxDB("humidity,city="+city+",location="+location, "value", String(event.relative_humidity)); + } + } +} + +void sendToInfluxDB(String measure, String key, String value) { + String line = measure+" "+key+"="+value; + Udp.begin(localPort); + Udp.beginPacket(influxdb_ip, influxdb_port); + Udp.print(line); + Udp.endPacket(); +} -- 2.11.0