Sending data to defined controller after deepsleep wake up

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
spm
Normal user
Posts: 11
Joined: 08 Aug 2019, 15:54

Sending data to defined controller after deepsleep wake up

#1 Post by spm » 08 Aug 2019, 16:06

Hi,

I have ESP board running on mega-20190630 and I'm trying to make temperature/humidity datalogger running from batteries. I want data stored in InfluxDB. So, in controllers I have defined Generic HTTP Advanced with parameters for my Influx. Under devices I have defined DHT11 sensor with option to send data to controller and interval 60 seconds. So far it's working very well - ESP running, every 60 seconds new record in my influx database.

Now I tried to set up deep sleep to prepare it for running from batteries. And there is the problem - currently I have configured awake interval 10 seconds and sleep for 60 seconds. This is working fine - ESP after 60 seconds woke up, connect's to WiFi (I can ping it) and it's alive for approximately 10 seconds. Issue is that no data in this case is written to Influx. It seems that writing data using controllers is done after sensor update interval which means after another 60 seconds - which is nonsense to keep ESP from battery so long alive. Well, I can set shorter interval for sensor. But I also have (working) physical switch to turn off deepsleep and in that case when I keep ESP running it flood my influx database with a lot of unwanted data.

I also tried to play with rules to achieve data publication after wake up. I tried this rule:
on WiFi#Connected do
taskRun,1
endon
but still no data in Influx. In examples on the internet they are often using in rules commands Publish or SendToHTTP. But unfortunately none of them is suitable for InfluxDB - Publish is for MQTT protocol and SendToHTTP didn't support HTTP POST which I need for posting data to influx (and it's working fine using Generic HTTP Advanced controller).

So there is some way with current mega release how to force publishing data after wake up as soon as possible? Without requiring to create some HTTP-GET to InfluxDB od MQTT to InfluxDB proxy as current ESPEasy mega release can do POST requests fine...

Thanks,

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

Re: Sending data to defined controller after deepsleep wake up

#2 Post by TD-er » 08 Aug 2019, 21:12

I have made a very recent fix which does force to flush the data still stored in buffers of the controllers, right before going to sleep (or reboot).
You may want to test it using the latest code from Github, or wait for tomorrow's build.

Let me know if this is then fixed.

spm
Normal user
Posts: 11
Joined: 08 Aug 2019, 15:54

Re: Sending data to defined controller after deepsleep wake up

#3 Post by spm » 09 Aug 2019, 17:03

Ok, few minutes ago I updated to last mega release (20190809). I had to remove rule with taskRun,1 because it was causing some problems - ESP after upgrades several times crashed / rebooted, after few minutes it normaly boots but device with DHT11 was disabled. So I removed this rule, enable device. Now it's working but again no new data in influx while deepsleep is enabled :-/ It's this patch included in 20190809 build or is needed to do something special to flush buffers? Awake time is still configured for 10 seconds.

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

Re: Sending data to defined controller after deepsleep wake up

#4 Post by TD-er » 09 Aug 2019, 22:23

No the patch should be in there.
So apparently there is still more.

Are you sure the device was even queried before going to deep sleep again?
The 10s awake time should be reset to 10s after WiFi connection was successful.
Can you experiment a bit with the awake time to see if you find a sweet spot where it starts to give data and when it always gives data?
I suggest trying first with minutes (1 or 2) and then move down in smaller steps if you find some interval that will switch between "meh" and "yeah".

spm
Normal user
Posts: 11
Joined: 08 Aug 2019, 15:54

Re: Sending data to defined controller after deepsleep wake up

#5 Post by spm » 12 Aug 2019, 13:49

Well about querying device - I have also attached OLED display with displayed values. When ESP wake up from deepsleep, I can after 1-2 sec read temperature/humidity from sensor. So, if it's not last value from DHT11 saved before deepsleep and after wake up recovered then I think that sensor is queried and read almost immediately.

I played with deep sleep intervals. It seems that correct value between meh and yeah is somewhere between 53 - 55 seconds. With wake up interval set to 55 seconds it's working fine, recording every value. With 53 seconds it's almost not working but sometimes it save value.

If I keep in mind that value for querying sensor is 60 second and now I know that sleep interval is resetted after wifi connection, it's still looking as that data are sent to controller after regular interval (60 seconds) where values are read again but not with the first read after boot. Also with 55 second wake up time settings recorded values are spread almost exactly within 2 minutes.

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

Re: Sending data to defined controller after deepsleep wake up

#6 Post by TD-er » 12 Aug 2019, 14:44

What is the set "interval" for the plugin? (one of the last values on the plugin settings page)

spm
Normal user
Posts: 11
Joined: 08 Aug 2019, 15:54

Re: Sending data to defined controller after deepsleep wake up

#7 Post by spm » 12 Aug 2019, 16:34

Do you mean interval in device settings (in my case DHT11 device)? There is 60 seconds.

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

Re: Sending data to defined controller after deepsleep wake up

#8 Post by TD-er » 12 Aug 2019, 23:52

spm wrote:
12 Aug 2019, 16:34
Do you mean interval in device settings (in my case DHT11 device)? There is 60 seconds.
Yep, that's the interval to call the plugin's READ function.
A read returns a sample value (or set of max 4 values) which are set to the controller.

If you reduce that interval, you're likely to go to sleep sooner.

spm
Normal user
Posts: 11
Joined: 08 Aug 2019, 15:54

Re: Sending data to defined controller after deepsleep wake up

#9 Post by spm » 13 Aug 2019, 10:28

Yeah, but if I reduce interval to some short value it will make me trouble when I disable deepsleep and leave ESP running (I'm guessing that if I reduce interval to 10s I can reduce sleep awake time but when I keep it running it will be saving to InfluxDB every 10s which also it's not what I want :-) ). So, in that case, is there some way (rule?) how to change this interval when I'm not in deepsleep? (I have physical NO/NC switch connected between RST, GPIO16 and GND which now works great).

User avatar
dynamicdave
Normal user
Posts: 188
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Sending data to defined controller after deepsleep wake up

#10 Post by dynamicdave » 13 Aug 2019, 11:38

The approach I've taken is NOT to use the Sleep Mode options - just leave them turned off.

Then in one of the Rule-Sets use... deepsleep,<some_fixed_sleep_value>

e.g. deepsleep,600 << Send Wemos to sleep for 10-mins i.e. 600 seconds

One of my IoT students has built a solar-powered weather station that wakes up, takes some readings, sends them to Node-RED via MQTT, then goes back to sleep.

It has been working for over 3-weeks with no problem at all.

Here's a link if you want to read more about it.

https://discourse.nodered.org/t/solar-p ... n/12499/51

And here's the specific part about using 'deepsleep'.

http://resources-area.co.uk/bohunt-proj ... tage_2.pdf

Regards, David.

spm
Normal user
Posts: 11
Joined: 08 Aug 2019, 15:54

Re: Sending data to defined controller after deepsleep wake up

#11 Post by spm » 13 Aug 2019, 12:52

yeah, but I have little trouble with this solution. Problem is that in this solution you are using publish function in rules for sending data (via MQTT). But unfortunately I need to publish them via HTTP POST (to InfluxDB) which is possible to do via controller but I didn't figure out how to do it in rules (there is HTTPSendTo function but it's not supporting POST requests). So I can enable/disable deepsleep via rules but I still need some way how to via rules say "read data from this device and publish them via assigned controller".

User avatar
grovkillen
Core team member
Posts: 3324
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Sending data to defined controller after deepsleep wake up

#12 Post by grovkillen » 13 Aug 2019, 13:05

Just a quick suggestion. Use the task run command to have the task publish to the controller?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

spm
Normal user
Posts: 11
Joined: 08 Aug 2019, 15:54

Re: Sending data to defined controller after deepsleep wake up

#13 Post by spm » 13 Aug 2019, 13:08

It wasn't working :-( I had it (look on first post, there is rule which I had). In that case it did nothing, after upgrade to last mega, which have implemented fix for flushing buffers before sleep, it even start crashing after wake up :-) (it crashed several times and after that it disabled my device/sensor and boot normally. )

User avatar
dynamicdave
Normal user
Posts: 188
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Sending data to defined controller after deepsleep wake up

#14 Post by dynamicdave » 13 Aug 2019, 16:22

Oops - sorry, didn't spot the 'http post' requirement.
Hope you find a solution that works for you.

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

Re: Sending data to defined controller after deepsleep wake up

#15 Post by TD-er » 13 Aug 2019, 19:41

spm wrote:
13 Aug 2019, 13:08
It wasn't working :-( I had it (look on first post, there is rule which I had). In that case it did nothing, after upgrade to last mega, which have implemented fix for flushing buffers before sleep, it even start crashing after wake up :-) (it crashed several times and after that it disabled my device/sensor and boot normally. )
What plugin is this?
Sounds like an "undocumented feature" ;)

spm
Normal user
Posts: 11
Joined: 08 Aug 2019, 15:54

Re: Sending data to defined controller after deepsleep wake up

#16 Post by spm » 14 Aug 2019, 09:58

Heh, no other plugin installed :-) I've just flashed ESP_Easy_mega-20190809_test_core_242_ESP8266_4M.bin to my ESP, after upgrade it stopped working (not reachable on wifi) and I see that sometimes OLED display resets so it looks like it's resetting. I keep it powered on, doing some other things and after some times I look on it and it was running, reachable on WiFi and when I opened config, device with DHT11 was disabled. Not sure what cause this :-) Then I deleted rule with TaskRun and it started working normally.

So, what to try now - should I put back rule with TaskRun and hope it will be working? :-)

User avatar
hilo90mhz
Normal user
Posts: 11
Joined: 29 Mar 2016, 21:21
Location: Hilo, Hawaii
Contact:

Re: Sending data to defined controller after deepsleep wake up

#17 Post by hilo90mhz » 08 Sep 2019, 12:17

We really just need a direct to InfluxDB controller that is purpose designed for that.. I have not found time to work on it myself but would use it if someone comes up with one.

Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests