Publish only temperatur values, if a sensor was found

This commit is contained in:
Ollo 2020-11-01 14:30:26 +01:00
parent 6ba2f92fa7
commit e094221298

View File

@ -208,10 +208,15 @@ void mode2MQTT(){
sensorSolar.setProperty("percent").send(String((100 * solarRawSensor.getAverage() ) / 4095)); sensorSolar.setProperty("percent").send(String((100 * solarRawSensor.getAverage() ) / 4095));
sensorSolar.setProperty("volt").send( String(getSolarVoltage()) ); sensorSolar.setProperty("volt").send( String(getSolarVoltage()) );
float t1 = temp1.getMedian(); float t1 = temp1.getMedian();
float t2 = temp2.getMedian(); if (t1 != NAN) {
sensorTemp.setProperty("control").send( String(t1)); sensorTemp.setProperty("control").send( String(t1));
}
float t2 = temp2.getMedian();
if (t2 != NAN) {
sensorTemp.setProperty("temp").send( String(t2)); sensorTemp.setProperty("temp").send( String(t2));
}
//give mqtt time, use via publish callback instead? //give mqtt time, use via publish callback instead?
delay(100); delay(100);
@ -364,14 +369,18 @@ void readSensors() {
/* Required to read the temperature once */ /* Required to read the temperature once */
float temp[2] = {0, 0}; float temp[2] = {TEMP_MAX_VALUE, TEMP_MAX_VALUE};
float* pFloat = temp; float* pFloat = temp;
if (dallas.readAllTemperatures(pFloat, 2) > 0) { int sensors = dallas.readAllTemperatures(pFloat, 2);
if (sensors > 0) {
Serial << "t1: " << String(temp[0]) << endl; Serial << "t1: " << String(temp[0]) << endl;
Serial << "t2: " << String(temp[1]) << endl;
}
temp1.add(temp[0]); temp1.add(temp[0]);
}
if (sensors > 1) {
Serial << "t2: " << String(temp[1]) << endl;
temp2.add(temp[1]); temp2.add(temp[1]);
}
/* Use the Ultrasonic sensor to measure waterLevel */ /* Use the Ultrasonic sensor to measure waterLevel */
@ -408,8 +417,9 @@ void onHomieEvent(const HomieEvent& event) {
esp_deep_sleep_start(); esp_deep_sleep_start();
break; break;
case HomieEventType::OTA_STARTED: case HomieEventType::OTA_STARTED:
Homie.getLogger() << "OTA started" << endl;
digitalWrite(OUTPUT_SENSOR, HIGH); digitalWrite(OUTPUT_SENSOR, HIGH);
digitalWrite(OUTPUT_PUMP, LOW); digitalWrite(OUTPUT_PUMP, HIGH);
gpio_hold_dis(GPIO_NUM_13); //pump pwr gpio_hold_dis(GPIO_NUM_13); //pump pwr
gpio_deep_sleep_hold_dis(); gpio_deep_sleep_hold_dis();
for (int i=0; i < MAX_PLANTS; i++) { for (int i=0; i < MAX_PLANTS; i++) {
@ -418,6 +428,7 @@ void onHomieEvent(const HomieEvent& event) {
mode3Active=true; mode3Active=true;
break; break;
case HomieEventType::OTA_SUCCESSFUL: case HomieEventType::OTA_SUCCESSFUL:
Homie.getLogger() << "OTA successfull" << endl;
digitalWrite(OUTPUT_SENSOR, LOW); digitalWrite(OUTPUT_SENSOR, LOW);
digitalWrite(OUTPUT_PUMP, LOW); digitalWrite(OUTPUT_PUMP, LOW);
ESP.restart(); ESP.restart();
@ -588,7 +599,7 @@ void mode2(){
/* Jump into Mode 3, if not configured */ /* Jump into Mode 3, if not configured */
if (!mConfigured) { if (!mConfigured) {
Serial.println("m3"); Serial.println("==== Mode 3 ====");
mode3Active = true; mode3Active = true;
} }
} }