One wire is initialized directly after start

This commit is contained in:
Ollo 2021-04-07 22:10:26 +02:00
parent b8b8cf84d5
commit 31229594fe
3 changed files with 23 additions and 26 deletions

View File

@ -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)

View File

@ -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

View File

@ -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);