I am currently building a controller for a window. It should read the slider values from the App, compare them to the BME280 sensor (aswell as rain & windspeed) and if they are smaller, open the window. If they are bigger, the windows should close. Everything seems to work so far, but after the first close, the ESP32 connects to the Blynk server, reads the BME280 and spits out absolute nonsense:
======================================================================================
[System]: Druck: 988.16hPa | Temperatur: 23.75°C | Luftfeuchtigkeit: 40.59%
[System]: Die Helligkeit beträgt: 0.00
[System]: Es regnet nicht!
[System]: Windgeschwindigkeit: 0.00m/S
[Motor]: Die Fenster sind geschlossen!
======================================================================================
[System]: Druck: 988.16hPa | Temperatur: 23.75°C | Luftfeuchtigkeit: 40.41%
[System]: Die Helligkeit beträgt: 0.00
[System]: Es regnet nicht!
[System]: Cooldown has run out and is ready to open again!
[System]: Cooldown has run out and is ready to open again!
[158937] Connecting to blynk-cloud.com:80
[158976] Ready (ping: 19ms).
[System]: Cooldown has run out and is ready to open again!
[System]: Windgeschwindigkeit: 0.00m/S
[Motor]: Die Fenster sind geschlossen!
======================================================================================
[System]: Druck: 167491.27hPa | Temperatur: 191.71°C | Luftfeuchtigkeit: 100.00%
[System]: Die Helligkeit beträgt: 0.00
[System]: Es regnet nicht!
[System]: Cooldown has run out and is ready to open again!
[System]: Cooldown has run out and is ready to open again!
[System]: Windgeschwindigkeit: 0.00m/S
[Motor]: Die Fenster sind geschlossen!
======================================================================================
As you can see, a pressure of 167491hPa and 191°C is not really realistic. The sensor seems to be fine tho, since it works before that. I believe that it has something to do either with blynk or the cooldown function, but since I read the BME280 from an entirely different core, none of these are very likely.
Any ideas on why that is? The code is a bit too big for me to post here, I uploaded it here: 10.8 KB folder on MEGA
Thanks in advance!
The 150 second delay in closewindow and the 130 second delay in openwindow will cause Blynk disconnections. You should use non-blocking BlynkTimers in Timeout mode instead. Read this: Using BlynkTimer or SimpleTimer
This makes no sense:
void wifi_publish(){ //Every value is sent twice, once for the Display and once for the Value graph.
Blynk.virtualWrite(V0, temp); //send Temperature
Blynk.virtualWrite(V1, temp); //send Temperature
Blynk.virtualWrite(V2, hum); //send Humidity
Blynk.virtualWrite(V3, hum); //send Humidity
Blynk.virtualWrite(V4, pres); //send Pressure
Blynk.virtualWrite(V5, pres); //send Pressure
Blynk.virtualWrite(V6, v); //send windspeed
Blynk.virtualWrite(V7, v); //send windspeed
Blynk.virtualWrite(V8, b); //send brightness
Blynk.virtualWrite(V9, b); //send brightness
Blynk.virtualWrite(V10, r); //send rain
Blynk.virtualWrite(V11, r); //send rain
}
You should be connecting the display widgets and the Superchart datastreams to the same virtual pin.
in order to force the Blynk server to send these values when the device connects or re-connects to the server.
Without this callback function in place, the sketch will use the hardcoded values for the v_set, temp_set, hum_set and b_set variables.
thanks for the feedback. I modified my code according to your suggestions, but the roblem persist:
======================================================================================
[System]: Druck: 167491.27hPa | Temperatur: 191.71°C | Luftfeuchtigkeit: 100.00%
[System]: Die Helligkeit beträgt: 0.00
[System]: Es regnet nicht!
[System]: Cooldown has run out and is ready to open again!
[System]: Cooldown has run out and is ready to open again!
[System]: Windgeschwindigkeit: 0.00m/S
[Motor]: Die Fenster sind geschlossen!
======================================================================================
[System]: Druck: 986.85hPa | Temperatur: 25.16°C | Luftfeuchtigkeit: 38.79%
[System]: Die Helligkeit beträgt: 0.00
[System]: Es regnet nicht!
[System]: Cooldown has run out and is ready to open again!
[60150] Heartbeat timeout
[System]: Cooldown has run out and is ready to open again!
[System]: Windgeschwindigkeit: 0.00m/S
[Motor]: Die Fenster sind geschlossen!
======================================================================================
I now get “Heartbeat timeouts” aswell as messy readings. The values go back to normal afterwards, but even one wrong measurement every 10 Minutes would result in the windows opening and closing all the time. I uploaded my new code to the same link as above.
Okay, I think I fixed it. I just decreased the I2C frequency from 100.000Hz to 5.000Hz
by adding Wire.setFrequency(5000); before bme.begin(). Now all values seem to be stable.
I will leave it running for a day now and Superchart the values to see if it really worked.
Okay, did it.
Got one last bug to fix: If I pull GPIO34 HIGH in combination with an interrupt, the ESP crashes with a Core 0 panic. Any chance you know something about that?
Okay, but that didn’t fix it. Still Guru meditation errors.
The function that is called by the interrupt does not seem to be able to access the variable v_counter.
Nevermind, I just found it.
The Interrupt calls a function which increments v_counter by one everytime it is called.
The Problem was that I put that function into IRAM for faster execution.
Functions in IRAM can not access global variables in Flash, so the ESP crashes when it tries to increment v_counter.
Simple solution: Made v_counter volatile, now everything works.