diff --git a/esp32/Readme.md b/esp32/Readme.md index 5844bb5..3d408c7 100644 --- a/esp32/Readme.md +++ b/esp32/Readme.md @@ -75,10 +75,6 @@ DS18B20 one wire temp sensor * alle Pumpen & Sensoren deaktiviert ## Masterplan 2.0 - * kein WLAN - * Bewässerung muss immer laufen - * Timeout um nicht ewig aufs WLAN zu warten - * Nicht mehrere Messungen vom Temp-Sensor nur warten, bis wir einen Wert bekommen * Partitionslayout * OW-search address in topic nutzen * Wifi bei timout deaktivieren (damit wir entweder wlan spielen oder fallback: nur pflanzen giessen) diff --git a/esp32/include/ControllerConfiguration.h b/esp32/include/ControllerConfiguration.h index af57873..462b6ab 100644 --- a/esp32/include/ControllerConfiguration.h +++ b/esp32/include/ControllerConfiguration.h @@ -97,7 +97,8 @@ #define MAX_CONFIG_SETTING_ITEMS 50 /**< Parameter, that can be configured in Homie */ #define TEMPERATUR_TIMEOUT 3000 /**< 3 Seconds timeout for the temperatur sensors */ -#define TEMP_SENSOR_MEASURE_SERIES 5 +#define DS18B20_RESOLUTION 9 /**< 9bit temperature resolution -> 0.5°C steps */ + /* @} */ #endif \ No newline at end of file diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index aa75e13..02d97c6 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -193,30 +193,10 @@ void readDistance() */ void readSensors() { + int sensorCount = sensors.getDS18Count(); Serial << "Read Sensors" << endl; /* activate all sensors */ digitalWrite(OUTPUT_ENABLE_SENSOR, HIGH); - /* wait before reading something */ - delay(20); - - int timeoutTemp = millis() + TEMPERATUR_TIMEOUT; - uint8_t sensorCount = 0U; - - /* Required to read the temperature at least once */ - while ((sensorCount == 0 || !battery.isFound()) && millis() < timeoutTemp) - { - sensors.begin(); - battery.begin(); - sensorCount = sensors.getDS18Count(); - delay(50); - } - - Serial << "One wire count: " << sensorCount << " found in " << (millis() - timeoutTemp) << "ms" << endl; - /* Measure temperature */ - if (sensorCount > 0) - { - sensors.requestTemperatures(); - } for (uint8_t i = 0; i < sensorCount; i++) { @@ -428,6 +408,26 @@ void setup() Serial << "Limits.hpp" << endl; } + /************************* Start One-Wire bus ***************/ + int timeoutTemp = millis() + TEMPERATUR_TIMEOUT; + uint8_t sensorCount = 0U; + + /* Required to read the temperature at least once */ + while ((sensorCount == 0 || !battery.isFound()) && millis() < timeoutTemp) + { + sensors.begin(); + battery.begin(); + sensorCount = sensors.getDS18Count(); + delay(50); + } + + Serial << "One wire count: " << sensorCount << " found in " << (millis() - timeoutTemp) << "ms" << endl; + /* Measure temperature TODO idea: move this into setup */ + if (sensorCount > 0) + { + sensors.setResolution(DS18B20_RESOLUTION); + sensors.requestTemperatures(); + } /************************* Start Homie Framework ***************/ WiFi.mode(WIFI_STA);