BLYNK
BLYNK.IO       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

BME280 reading absurd values after connecting to Blynk

Hello,

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!

A wiring diagram would be helpful.

There are a few things that jump out at me immediately.

  1. You should remove check(); from your void loop, and use a BlynkTimer to call this function instead.
    Read this:
    https://docs.blynk.io/en/legacy-platform/legacy-articles/keep-your-void-loop-clean

  2. 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

  3. 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.

//Get values from server======================================
  BLYNK_WRITE(V12){
  v_set = param.asInt();
  }
  BLYNK_WRITE(V13){
  temp_set = param.asInt();
  }
  BLYNK_WRITE(V14){
  hum_set = param.asInt();
  }
  BLYNK_WRITE(V15){
  b_set = param.asInt();
  }

This code ONLY gets the values from the Blynk server when these values change. You need to add…

BLYNK_CONNECTED()
{
  Blynk,syncVirtual(V12);
  Blynk,syncVirtual(V13);
  Blynk,syncVirtual(V14);
  Blynk,syncVirtual(V15);
} 

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.

Pete.

Hello Pete,

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.


This is the wireing diagram you asked for.

Sam

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, that’s good.

I noticed that you didn’t add the BLYNK_CONNECTED() callback.

Pete.

Yeah, I was unsure where to put it. Should I just call it with a timer?

I’d put it with the BLYNK_WRITE(vPin) callbacks, keeps them all together.

Pete.

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? :smiley:

Are you using GPIO 34 as an output ?

GPIOs 34 to 39 are GPIs – input only pins. These pins don’t have internal pull-up or pull-down resistors.

Pete.

1 Like

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.

What exactly is the error?

Pete.

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.

Thanks a lot for your help, appreciate it!

1 Like

I also meant to say that your notifications look too long.
The limit is 120 characters.

Also, you’ll need to use the Legacy library version 0.6.1 if you want the notifications to work.

Pete.

Oh you are right. Didn’t even noticed it. If they are longer, are they cut of or not send at all?

I’m not sure, I’ve never tried.

Pete.