Problem with ADC Deep Sleep MQTT Grafana

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
ssteff29
New user
Posts: 3
Joined: 28 Feb 2023, 09:57

Problem with ADC Deep Sleep MQTT Grafana

#1 Post by ssteff29 » 28 Feb 2023, 10:17

Hallo Board Mitglieder,

ich habe leider ein Problem mit dem ADC Wert auslesen mit ESPEASY.

Verwende einen D1mini ESP1866 an dem ich am A0 Pin einen Spannung von einem Akku messe.
Diese Messung sende ich per MQTT alle 10sec zum iOBroker und Visualisiere in Grafana in einem Time Graph.
Das funktioniert super!!
Jetzt will ich den DEEP SLEEP verwenden und schicke ihn für 60sec in Tiefschlaf und lasse ihn für 20sec aufwachen.

Leider ist es jetzt so das am A0 beim Init eine höhere Spannung gemessen wird und per MQTT übertragen wird. Nach 10sec wird der richtige Wert übertragen.
Die Grafik in Grafana sieht jetzt komisch aus.
Hängt das mit WLan Init zusaen?

Gibt es da eine Lösung das MQTT erst nach 5sec sendet nach dem booten.

Bitte um HIlfe.

Danke
Stephan
Graph.JPG
Graph.JPG (14.82 KiB) Viewed 1005 times

In english:

Hello Board Member,

Unfortunately I have a problem with reading the ADC value with ESPEASY.

I use a D1mini ESP1866 on which I measure a voltage from a battery at the A0 pin.
I send this measurement via MQTT to the iOBroker every 10 seconds and visualize it in Grafana in a time graph.
That works great!!
Now I want to use the DEEP SLEEP and send him into deep sleep for 60sec and let him wake up for 20sec.

Is there a solution that MQTT only sends after 5 seconds after the boot.

Please help.

Thanks
Stephen
Graph.JPG
Graph.JPG (14.82 KiB) Viewed 1005 times
Last edited by ssteff29 on 28 Feb 2023, 11:31, edited 4 times in total.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Problem mit ADC Deep Sleep MQTT Grafana

#2 Post by TD-er » 28 Feb 2023, 10:36

Please for future replies, use English.
I can read German, but lots of others may not.

The problem you're facing has probably to do with the fact that an ESP8266 should not read from ADC when starting WiFi.
In ESPEasy the ADC is read right at boot, before starting WiFi and then it isn't read until the WiFi was successful in connecting to WiFi.
This means that right after boot, there is hardly any oversampling performed as there is probably only 1 reading.
Also this reading is done before the WiFi is started and thus the ESP does draw (quite a lot) less current.
This means that there is a different voltage drop over the cables as the current draw changes.
Based on the quite consistent values, I assume these are also related to the discrete ADC output values, roughly 0.01V per step.
That means the full range should be about 10V, is that correct?

The ADC plugin does average all measured values, minus the lowest and highest value for a given period. (when nr. of samples > 3)
I guess you may need to keep the ESP awake a bit longer, which can be compensated by a longer sleep time.
You may also want to discard the first sample.
For example doing this in rules, like act on an event from the ADC task and store it in a dummy.
On the second event, store it in a dummy and call taskRun on this dummy task to 'flush' it to a connected controller.

ssteff29
New user
Posts: 3
Joined: 28 Feb 2023, 09:57

Re: Problem mit ADC Deep Sleep MQTT Grafana

#3 Post by ssteff29 » 28 Feb 2023, 11:27

Hello TD-er,

"The problem you're facing has probably to do with the fact that an ESP8266 should not read from ADC when starting WiFi."

Yes, exactly

The measured value when booting on the ADC is higher than the value measured after 10 seconds.
It behaves the same when booting.

Is it possible not to send the first reading to the controller when booting, or at least to suspend it so that the values ​​are only sent to the controller 5 seconds after booting?

Thanks

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Problem with ADC Deep Sleep MQTT Grafana

#4 Post by TD-er » 28 Feb 2023, 11:34

Yep, that's possible and is quite what I suggested.
So not let the ADC task send to the controller, but use the rules to copy the value to some dummy task and then -when the sample is considered reliable- call taskrun on this dummy task.

You could for example trigger on events like "WiFi#Connected" or "MQTT#connected" to start collecting the ADC samples (taskrun on the ADC task) and then when you receive a new event from the ADC task, copy it to the dummy and 'flush' it to the controller using taskrun on the dummy task.

I would then set the ADC task "interval" to 5 sec or something like that, so you can be sure to not have to wait too long, but still have enough samples to average.

ssteff29
New user
Posts: 3
Joined: 28 Feb 2023, 09:57

Re: Problem with ADC Deep Sleep MQTT Grafana

#5 Post by ssteff29 » 06 Mar 2023, 09:08

Hello,

I did it this way and watched it for a few days.
The solution is perfect for me.

Thanks for the support

Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests