ESP32 / MQTT / BME280 problem..

Post Reply
MJU20
Posts: 138
http://meble-kuchenne.info.pl
Joined: Tue Dec 08, 2020 5:11 pm
Has thanked: 50 times
Been thanked: 35 times

ESP32 / MQTT / BME280 problem..

Post by MJU20 »

I'm getting somewhat frustrated because of a file I'm working on for... a while.

My goals is simple:

Sample a sensor (BME280), send the data to MQTT (Thingspeak) and go to deepsleep until the next sample about 5 mins later. All this with a ESP32 Wroom

But this has a few features that need to work.
1- It needs to see which of 4 known SSID he has the strongest connection with. And choose the strongest (this works).
-- I use 8 variables to make this work. 4 store the known SSID names, and 4 the paswords of the know SSIDs.
-- This feature seems to work

2- it should become a battery powered (mobile) device so the less power it needs the better.
-- this needs to be finetuned by using the different macro's in a smart way (not starting the WIFI before there is a valid sensor sample and...)

3- I need to add more checks if all steps work fine and if somethings wrong => go to deepsleep

Most of the stuff works. But for most of the time something goes wrong. The file doesn't work consistence.
If I look at the data on Thingspeak there are moments that for 30minutes there is no valid data posted.

In an earlier version I had UART enabled and send feedback for each and every step, but most of the time the initialization of the sensor gave a 0 as return.

My problem is that I can't seem to figure out why the project sometimes works and sometimes it doesn't.
By waking up from deep sleep, it starts from main every time so if there is nothing different from previous time, it should work like previous time.

Can someone please dive into this chart and think with me why it sometimes works and sometimes it doesn't?
The device is 1 m from the access point it uses so there was never a connection problem.

The brownout detection is been switched of in the sdkconfig

The flowchart is somewhat messy I know, but this changes every 15 minutes while I'm working on it.

Why does the BME280 gave a 0 after initialisation before? I did never change anything on the hardware...

Any suggestion/help is welcome.
Attachments
Weerstation.fcfx
(31.01 KiB) Downloaded 42 times

chipfryer27
Valued Contributor
Posts: 154
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 109 times
Been thanked: 83 times

Re: ESP32 / MQTT / BME280 problem..

Post by chipfryer27 »

Hi

Sorry I cant be of better help as I'm travelling and this laptop doesn't have FC on it, so I can't look at your project just yet.

I don't have much experience with the ESP32 (but recently purchased one) so I am no expert. From the brief outline of your project it sounds like something I'd look to do with mine though (sleep, wake up, do something useful, post result, sleep), so I'm keen to see how you progress.

I could be completely wrong in regards to your project, but in other instances using different components (e.g. PIC and some RF module) I found I needed to insert a small delay here and there to allow the RF sections time to register/do whatever/etc after enabling them (or increase default timeout as necessary). One embarrassing time I'd forgotten about preamble and wasted the dark hours chasing my tail.

When entering "deep sleep" and then exiting, do you need to wait until any oscillators or such like first stabilise?

Appreciate that you may already be waiting on confirmations and actioning upon receipt (can't yet look at your file).

I read in another relatively recent post of some issues using the MQTT component. Maybe it could throw some light?

As mentioned, keen to hear of your progress and sorry I can't be of more help at present.

Regards

chipfryer27
Valued Contributor
Posts: 154
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 109 times
Been thanked: 83 times

Re: ESP32 / MQTT / BME280 problem..

Post by chipfryer27 »

Hi

Still traveling, back at weekend so maybe then I'll have time to look at your chart.

From searching around I have seen reports that the BME280 can take a bit of time to settle before accurate readings can be obtained. Maybe you could experiment a bit using only the component? That may help to narrow things down. Perhaps wake it up and then take a series of readings (perhaps ten spaced evenly apart) and see if they start to read correctly only after "x" readings or such like?

Regards

BenR
Matrix Staff
Posts: 1104
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 276 times
Been thanked: 377 times

Re: ESP32 / MQTT / BME280 problem..

Post by BenR »

Is the sensor maybe getting into a stuck state? Are you powering down the sensor when going into deep sleep e.g. using a FET? if not then this might help put it into a repeatable state.

MJU20
Posts: 138
Joined: Tue Dec 08, 2020 5:11 pm
Has thanked: 50 times
Been thanked: 35 times

Re: ESP32 / MQTT / BME280 problem..

Post by MJU20 »

Thanks guys, I haven't got the time to do more testing until the weekend.

But I tried to use an IO pin to power the BME280 (without FET). The current for the BME280is very low so an IO pin must be able to supply the current.
I've tried this (maybe any remainder is still in the example). And I found that the BME280 needs 10ms to get ready for its job.

I need to make time to start testing again, maybe even with the native I2C component.
I found in the past that using the protocol macro instead of the component macro solves a few things.

But first: create time.
Thanks already for the suggestions!

MJU20
Posts: 138
Joined: Tue Dec 08, 2020 5:11 pm
Has thanked: 50 times
Been thanked: 35 times

Re: ESP32 / MQTT / BME280 problem..

Post by MJU20 »

Some further testing in a nutshell:

I've added (back) some UART responses and it seems that the sensor is not the real issue.

I've made the flowchart so that, if the sensor @initialisation returns an error (init is not OK) it tries 3 times, and after 3 times, still there is no positive response, the ESP32 goes back to sleep for a short while.
The BME280 is now powered by an IO-pin. So after each faulty init it is powered down and after a short period it is powered back on. I hope that if the sensor has issues, this way after a few attempts it has a success.

But I found out that the MQTT connect doesn't always return a success (1).
So I've added a loop that tries 3 times to connect to the MQTT broker and if, after 3 attempts there is still no success in connecting, it goes to sleep for a while.

This seems to work for the last hours.
I will keep you informed :-)

BenR
Matrix Staff
Posts: 1104
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 276 times
Been thanked: 377 times

Re: ESP32 / MQTT / BME280 problem..

Post by BenR »

I've found sometimes my personal router is still in a working state providing wifi to my laptop but a connecting ESP device will be refused connection time and time again and won't be able to connect. Restarting the router clears the problem for a couple of months so probably some kind of minor memory leak on the router firmware. Maybe something to try if it's being stubborn again.

Post Reply