diff --git a/esp32/Readme.md b/esp32/Readme.md index b0d18de..7e8720d 100644 --- a/esp32/Readme.md +++ b/esp32/Readme.md @@ -82,5 +82,6 @@ DS18B20 one wire temp sensor * 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/src/main.cpp b/esp32/src/main.cpp index b41a0ed..7737ef3 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -46,8 +46,8 @@ int readTemp(); ******************************************************************************/ //only relevant if mode2 did start pumping before -RTC_DATA_ATTR int lastPumpRunning = 0; /**< store last successfully waterd plant */ -RTC_DATA_ATTR long lastWaterValue = 0; /**< to calculate the used water per plant */ +RTC_DATA_ATTR int lastPumpRunning = 0; /**< store last successfully waterd plant */ +RTC_DATA_ATTR long lastWaterValue = 0; /**< to calculate the used water per plant */ RTC_DATA_ATTR int gBootCount = 0; @@ -192,12 +192,6 @@ void mode2MQTT() sensorLipo.setProperty("CCA").send(String(battery.getCCA())); sensorSolar.setProperty("volt").send(String(mSolarVoltage)); - sensorTemp.setProperty(TEMPERATUR_SENSOR_LIPO).send(String(mTempLipo)); - Serial << "Lipo Temperatur " << mTempLipo << " °C " << endl; - - sensorTemp.setProperty(TEMPERATUR_SENSOR_WATER).send(String(mTempWater)); - Serial << "Water Temperatur " << mTempWater << " °C " << endl; - sensorTemp.setProperty(TEMPERATUR_SENSOR_CHIP).send(String(mChipTemp)); Serial << "Chip Temperatur " << mChipTemp << " °C " << endl; @@ -252,7 +246,7 @@ void readDistance() for (int i = 0; i < AMOUNT_SENOR_QUERYS; i++) { unsigned long duration = 0; - + digitalWrite(SENSOR_TANK_TRG, HIGH); delayMicroseconds(20); cli(); @@ -260,10 +254,13 @@ void readDistance() duration = pulseIn(SENSOR_TANK_ECHO, HIGH); sei(); - int mmDis = duration * 0.3432 / 2; - if(mmDis > MAX_TANK_DEPTH){ + int mmDis = duration * 0.3432 / 2; + if (mmDis > MAX_TANK_DEPTH) + { waterRawSensor.add(0); - } else { + } + else + { waterRawSensor.add(mmDis); } } @@ -276,13 +273,13 @@ void readDistance() void readSensors() { Serial << "Read Sensors" << endl; - /* activate all sensors */ + /* activate all sensors */ digitalWrite(OUTPUT_ENABLE_SENSOR, HIGH); /* wait before reading something */ delay(20); int timeoutTemp = millis() + TEMPERATUR_TIMEOUT; - int sensorCount = 0; + uint8_t sensorCount = 0U; /* Required to read the temperature at least once */ while ((sensorCount == 0 || !battery.isFound()) && millis() < timeoutTemp) @@ -300,10 +297,33 @@ void readSensors() sensors.requestTemperatures(); } - for (int i = 0; i < sensorCount; i++) { - float temp = sensors.getTempCByIndex(i); + for (uint8_t i = 0; i < sensorCount; i++) + { + DeviceAddress ds18b20Address; + sensors.getAddress(ds18b20Address, i); + float temp = sensors.getTempC(ds18b20Address); Serial << "OneWire sensor " << i << " has value " << temp << endl; - /** FIXME: handle via address */ + char buf[sizeof(DeviceAddress) * 2]; + snprintf(buf, sizeof(buf), "%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X", + ds18b20Address[0], + ds18b20Address[1], + ds18b20Address[2], + ds18b20Address[3], + ds18b20Address[4], + ds18b20Address[5], + ds18b20Address[6], + ds18b20Address[7]); + + if (String(lipoSensorAddr.get()).compareTo(String(buf))) { + sensorTemp.setProperty(TEMPERATUR_SENSOR_LIPO).send(String(temp)); + Serial << "Lipo Temperatur " << temp << " °C " << endl; + } else if (String(waterSensorAddr.get()).compareTo(String(buf))) { + sensorTemp.setProperty(TEMPERATUR_SENSOR_WATER).send(String(temp)); + Serial << "Water Temperatur " << temp << " °C " << endl; + } + /* Always send the sensor address with the temperatur value */ + sensorTemp.setProperty(String(buf)).send(String(temp)); + Serial << "Temperatur " << String(buf) << " : " << temp << " °C " << endl; } // Update battery chip data @@ -455,8 +475,8 @@ void systemInit() // Set default values //in seconds - deepSleepTime.setDefaultValue(600).setValidator([] (long candidate) { - return (candidate > 0) && (candidate < (60 * 60 * 2) /** 2h max sleep */ ); + deepSleepTime.setDefaultValue(600).setValidator([](long candidate) { + return (candidate > 0) && (candidate < (60 * 60 * 2) /** 2h max sleep */); }); deepSleepNightTime.setDefaultValue(600); wateringDeepSleep.setDefaultValue(5); diff --git a/esp32test/Esp32DeepSleepTest/platformio.ini b/esp32test/Esp32DeepSleepTest/platformio.ini index 69e6ffc..e18a7df 100644 --- a/esp32test/Esp32DeepSleepTest/platformio.ini +++ b/esp32test/Esp32DeepSleepTest/platformio.ini @@ -15,3 +15,5 @@ framework = arduino build_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY lib_deps = OneWire DallasTemperature + +upload_port = /dev/ttyUSB1 diff --git a/esp32test/Esp32DeepSleepTest/src/main.cpp b/esp32test/Esp32DeepSleepTest/src/main.cpp index a6bf26d..d4d7ffa 100644 --- a/esp32test/Esp32DeepSleepTest/src/main.cpp +++ b/esp32test/Esp32DeepSleepTest/src/main.cpp @@ -110,9 +110,29 @@ void setup() { Serial.print("Bat I"); Serial.print("\t"); Serial.println("Temp/10"); + } void loop() { + static int loop=1; + + + DeviceAddress t; + for(int i=0; i < sizeof(t); i++) { + t[i] = loop + i*2; + } + char buf[sizeof(DeviceAddress)*2]; + snprintf(buf, sizeof(buf), "%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X", t[0], t[1], t[2], t[3], t[4], t[5], t[6], t[7]); +/* + %X -> linksbündige hexzahl + %2X -> 2Stellige hexzahl ... dynamisch erweitert + %0.2X -> 2stellige hexzahl mit führerder "0" + */ + printf("Print: %s\n", buf); + loop++; + delay(500); + return; + whatever = !whatever; digitalWrite(OUTPUT_PUMP, HIGH); delay(500);