Help: A guide for a battery powered measuring station

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
chromo23
Normal user
Posts: 26
Joined: 10 Sep 2020, 16:02

Help: A guide for a battery powered measuring station

#1 Post by chromo23 » 03 Jan 2021, 16:23

I am using multiple Esp8266 with sensors attached as mobile sensor stations.
Therefore i let the esp sleep for a while and wake it it up as short as possible (around 3sek) to send data to thingspeak (i use sendtohttp)
But it is alway a hassle to write the rules, that the data thats beeing send is correct in terms of acutality.

Because the timing is a problem especially when you have more than one sensor connected. (eg. ih have in my recent installation two bme280s)
Sometimes the sensordata comes to late and old values are beeing send.
I usually collect the data in a dummydevice on sensorreading and send it away on wifi#connected.

So what i really want and not able to do:

-collect alle the readings of all the sensors immediately after startup
-send this data as soon as available and when wifi is connected to wherever-i-want
- (extra but as far as i read not possible) send the esp to sleep immediately after sending.

What i dont want:

-give the readings more time to happen and to send (that would be only a workaround and no solution)



Has somebody a solution for this or could point me to a relevant thread(i couldn´t find any in the forum)?
Thanks in advance and a happy and healthy new year!
Last edited by chromo23 on 05 Jan 2021, 16:10, edited 1 time in total.

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

Re: Help: The ultimate guide for batterie powered measuring station

#2 Post by TD-er » 03 Jan 2021, 16:39

As Thingspeak has a rate limit on it, wouldn't it make more sense to send the data to another node in the network which isn't battery powered and let that one handle sending it?

For example you send it via the p2p protocol to another node, or send it to a MQTT broker.
The other node then either receives the value via p2p or mqtt import and adds it to its queue for thingspeak (using a controller with its own queue).
This way you don't need to have the battery powered node active for longer than strictly needed.

Disadvantage of the p2p is that for sharing tasks you must keep the task index the same among sending and receiving node, and thus you may run out of task indices quite fast and also configuring it is rather complex for your entire network.

Disadvantage of MQTT is that you need a separate broker.

chromo23
Normal user
Posts: 26
Joined: 10 Sep 2020, 16:02

Re: Help: The ultimate guide for batterie powered measuring station

#3 Post by chromo23 » 03 Jan 2021, 16:44

TD-er wrote: 03 Jan 2021, 16:39 As Thingspeak has a rate limit on it, wouldn't it make more sense to send the data to another node in the network which isn't battery powered and let that one handle sending it?
The Thingspeak limit is not my problem. Data is beeing send around every 30minutes
My problem is, that i dont know how to make sendhttp wait for the data.
If i use "on wifi#connected" it can happen, that the sensorreading is slower than that and so old data is beeng send.

Any extra device is an extra level of complexity and i want to keep it simple. and a single device offers more flexibility and mobility.
Last edited by chromo23 on 03 Jan 2021, 17:49, edited 1 time in total.

User avatar
Ath
Normal user
Posts: 473
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Help: The ultimate guide for batterie powered measuring station

#4 Post by Ath » 03 Jan 2021, 16:49

You can use a TaskRun command on the sensors that need to be updated, just before you are sending the data.
/Ton

chromo23
Normal user
Posts: 26
Joined: 10 Sep 2020, 16:02

Re: Help: The ultimate guide for batterie powered measuring station

#5 Post by chromo23 » 03 Jan 2021, 17:01

Ath wrote: 03 Jan 2021, 16:49 You can use a TaskRun command on the sensors that need to be updated, just before you are sending the data.
I already use TaskValueSetandRun to update the Dummydevice but thats not making sure that the data is available on wifi#connected.
I am also not sure that TaskValueSetandRun is really helping here.

chromo23
Normal user
Posts: 26
Joined: 10 Sep 2020, 16:02

Re: Help: The ultimate guide for batterie powered measuring station

#6 Post by chromo23 » 03 Jan 2021, 17:34

Here is my Rule:

Code: Select all

On System#Boot do
	TaskValueSetAndRun 3,1,[sensor_intern#Temperature]
	TaskValueSetAndRun 3,2,[sensor_intern#Humidity]
	TaskValueSetAndRun 6,1,[sensor_intern#Pressure]
	TaskValueSetAndRun 3,3,[sensor_extern#Temperature]
	TaskValueSetAndRun 3,4,[sensor_extern#Humidity]
endon


on WiFi#Connected do
	SendToHTTP api.thingspeak.com,80,/update?api_key=xxx&field1=[alle#t_int]&field2=[alle#h_int]&field3=[batterie#Analog]&field4=[alle#h_ext]&field5=[alle2#p]&field8=[alle#t_ext]
endon
expected behavior:
send the sensordata measured at this wakeup to thingspeak

actual behavior:
data ist send but it is either from the last wakeup or it is exactly the same data as before. (and sometimes it even works as expected )

so the data is send and after that the dummydevice is updated or the dummydevice is not updated at all because is uses old readings.
this is something not noticeable on short wakeup intervals but as you can imagine a interval of half an hour gives you strange readings when they are always half an hour old (or the same)....

User avatar
Ath
Normal user
Posts: 473
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Help: The ultimate guide for batterie powered measuring station

#7 Post by Ath » 03 Jan 2021, 19:50

TaskValueSetAndRun will only update that data to the Dummy Device, it will not update the separate sensors, you need separate TaskRun commands for that, before the TaskValueSetAndRun commands you have now.
NB: TaskValueSetAndRun does a TaslValueSet and a TaskRun, thus sets the values and generates (multiple) events on the dummy devices, and that needs quite some CPU cycles. You can do with just TaskValueSet commands here.
Assuming your sensors are at task 1 and 2, you'd have:

Code: Select all

On System#Boot do
	TaskRun,1 // Update first sensor
	TaskRun,2 // Update second sensor
	TaskValueSet 3,1,[sensor_intern#Temperature]
	TaskValueSet 3,2,[sensor_intern#Humidity]
	TaskValueSet 6,1,[sensor_intern#Pressure]
	TaskValueSet 3,3,[sensor_extern#Temperature]
	TaskValueSet 3,4,[sensor_extern#Humidity]
endon
/Ton

chromo23
Normal user
Posts: 26
Joined: 10 Sep 2020, 16:02

Re: Help: The ultimate guide for batterie powered measuring station

#8 Post by chromo23 » 03 Jan 2021, 20:19

Thank you for this explanation. I never really understood TaskRun and TaskValueSetAndRun.

But unfortunately i have still the same problem. Data is either one cycle behind or the same as in the last cycle....

Somehow i must get SendToHttp to wait for the data

User avatar
Ath
Normal user
Posts: 473
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Help: The ultimate guide for batterie powered measuring station

#9 Post by Ath » 03 Jan 2021, 20:26

What type of sensors are you using for sensor_intern and sensor_extern measurements? Ah, I found it BME280's.
/Ton

chromo23
Normal user
Posts: 26
Joined: 10 Sep 2020, 16:02

Re: Help: The ultimate guide for batterie powered measuring station

#10 Post by chromo23 » 03 Jan 2021, 20:38

the dummydevice is actually not necessary i guess:

Code: Select all

On System#Boot do
	TaskRun,1 // Update first sensor
	TaskRun,2 // Update second sensor

endon

On WiFi#Connected do
	SendToHTTP api.thingspeak.com,80,/update?api_key=xxx&field1=[sensor_intern#Temperature]&field2=[sensor_intern#Humidity]&field3=[batterie#Analog]&field4=[sensor_extern#Humidity]&field5=[sensor_intern#Pressure&field8=[sensor_extern#Temperature]
endon
but same problem.....

User avatar
Ath
Normal user
Posts: 473
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Help: The ultimate guide for batterie powered measuring station

#11 Post by Ath » 03 Jan 2021, 20:45

I think you need a little adjustment on your strategy, as the BME's need about 2 seconds for a proper read, and I suspect they don't get enough time to complete that.
So you could move the TaskRun and TaskValueSet commands to the Wifi#Connected event, just before the SendToHTTP.
As the Wifi probably needs a few seconds before it's connected, the sensors should have had a bit of time to do their measurements, and 10msec after that update the values, so the TaskValueSet commands have the correct data to send.
If that still has 'delayed' or 'previous' values, you may need to start a timer for ~1 or 2 seconds (TimerSet_ms creates a quite accurately configurable delay) where you then run the sequence of commands.

Edit: You can remove the Dummy Device. I guess the somewhat-delayed strategy should get you running.
/Ton

chromo23
Normal user
Posts: 26
Joined: 10 Sep 2020, 16:02

Re: Help: The ultimate guide for batterie powered measuring station

#12 Post by chromo23 » 03 Jan 2021, 20:56

But TaskRun should be on system boot so that the BMEs start to measure as soon as possible?
More like this:

Code: Select all

On System#Boot do
	TaskRun,1 // Update first sensor
	TaskRun,2 // Update second sensor

endon

On WiFi#Connected do
	TimerSet_ms,10
	SendToHTTP api.thingspeak.com,80,/update?api_key=xxx&field1=[sensor_intern#Temperature]&field2=[sensor_intern#Humidity]&field3=[batterie#Analog]&field4=[sensor_extern#Humidity]&field5=[sensor_intern#Pressure&field8=[sensor_extern#Temperature]
endon
Is this TimerSet existing and my syntax right? Couldn’t find it in the Command Reference....

User avatar
Ath
Normal user
Posts: 473
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Help: The ultimate guide for batterie powered measuring station

#13 Post by Ath » 03 Jan 2021, 21:10

chromo23 wrote: 03 Jan 2021, 20:56 But TaskRun should be on system boot so that the BMEs start to measure as soon as possible?
As soon as the plugin is started, during boot, it starts a measurement on the first 'PLUGIN_ONCE_A_SECOND' event. That should be quite soon after System#Boot.
chromo23 wrote: 03 Jan 2021, 20:56 Is this TimerSet existing and my syntax right? Couldn’t find it in the Command Reference....
Well, that's not quite right. The current documentation can be found here: https://espeasy.readthedocs.io/en/lates ... t=timerset

You may not even need the TaskRun commands right at boot, but it won't hurt to leave them there. Edit: I also added them just before the SendToHTTP command
I'd go with this:

Code: Select all

On System#Boot do
	TaskRun,1 // Update first sensor
	TaskRun,2 // Update second sensor
endon

On WiFi#Connected do
	TimerSet_ms,1,500 // 0.5 seconds after Wifi is connected timer 1 will trigger, increase as desired/required
endon

On Rules#Timer=1 do
	TaskRun,1 // Update again
	TaskRun,2
	SendToHTTP api.thingspeak.com,80,/update?api_key=xxx&field1=[sensor_intern#Temperature]&field2=[sensor_intern#Humidity]&field3=[batterie#Analog]&field4=[sensor_extern#Humidity]&field5=[sensor_intern#Pressure&field8=[sensor_extern#Temperature]
endon
/Ton

chromo23
Normal user
Posts: 26
Joined: 10 Sep 2020, 16:02

Re: Help: The ultimate guide for batterie powered measuring station

#14 Post by chromo23 » 03 Jan 2021, 22:00

Ath wrote: 03 Jan 2021, 21:10 Well, that's not quite right. The current documentation can be found here: https://espeasy.readthedocs.io/en/lates ... t=timerset
Sometimes these different sources are a bit confusing. I looked here: https://www.letscontrolit.com/wiki/inde ... _Reference
And of course the syntax was wrong. Because of the milliseconds i had a delay in my head :roll:

But other than that it works. You were really helpful! Thank you very much!!!
I am relieved that it still works in the 3 seconds timeframe

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

Re: Help: The ultimate guide for batterie powered measuring station

#15 Post by TD-er » 03 Jan 2021, 23:25

chromo23 wrote: 03 Jan 2021, 16:44
TD-er wrote: 03 Jan 2021, 16:39 As Thingspeak has a rate limit on it, wouldn't it make more sense to send the data to another node in the network which isn't battery powered and let that one handle sending it?
The Thingspeak limit is not my problem. Data is beeing send around every 30minutes
My problem is, that i dont know how to make sendhttp wait for the data.
If i use "on wifi#connected" it can happen, that the sensorreading is slower than that and so old data is beeng send.

Any extra device is an extra level of complexity and i want to keep it simple. and a single device offers more flexibility and mobility.
See the Tools => Advanced page: "SendToHTTP wait for ack"
This will cause the sendToHttp command to wait till it receives an ack (or timeout).

chromo23
Normal user
Posts: 26
Joined: 10 Sep 2020, 16:02

Re: Help: The ultimate guide for batterie powered measuring station

#16 Post by chromo23 » 05 Jan 2021, 15:48

I wanted to give a feedback how i finally managed to get successful readings and i also wanted to talk about my setup and my measurements.

The rules Ath provided me work.

Code: Select all

On System#Boot do
	TaskRun,1 // Update first sensor
	TaskRun,2 // Update second sensor
endon

On WiFi#Connected do
	TimerSet_ms,1,2500 // 0.5 seconds after Wifi is connected timer 1 will trigger, increase as desired/required
endon

On Rules#Timer=1 do
	TaskRun,1 // Update again
	TaskRun,2
	SendToHTTP api.thingspeak.com,80,/update?api_key=xxx&field1=[sensor_intern#Temperature]&field2=[sensor_intern#Humidity]&field3=[batterie#Analog]&field4=[sensor_extern#Humidity]&field5=[sensor_intern#Pressure&field8=[sensor_extern#Temperature]
endon
But to make it really work i had to set the timer to 2500ms to gather all the data since it takes very long for the readings
Initially i had a Sleep awake time of 3 seconds that i now had to extend to 4s otherwise the device would go to sleep before sending data. Not ideal for a battery powered application where every second count.
Ath wrote: 03 Jan 2021, 21:10 As soon as the plugin is started, during boot, it starts a measurement on the first 'PLUGIN_ONCE_A_SECOND' event. That should be quite soon after System#Boot.
If understand this correctly, every BME280 i given one second to read the data. Thats a lot given the fact, that a BME280 needs around 11ms for a measurement.
I also read that somebody (TD-er?) working on implementing ESP-Now and therefore it would be also nice to have such readings much quicker.

To my setup:
IMG-7746.JPG
IMG-7746.JPG (493.85 KiB) Viewed 1122 times
IMG-7745.JPG
IMG-7745.JPG (532.62 KiB) Viewed 1122 times
This is my prototype version. I have no picture here of my "final" version with the connector for the second sensor.
As you can see i used a Wemos D1 mini a battery salvaged from a kindle and a simple charging ciruit.
I wanted to keep this Project as simple as possible so the LiPo-Battery is directly connected to the 5Volts in of the Wemos. In Sleepmode i measured 140uA which is no perfect but ok. (ch340 still connected since it draws only 10uA or less if i remember correctly). The relatively high current is caused by the LDO. I could buy a better one and solder it to the Wemos but as i said, i wanted to keep it as simple as possible.
Now it was important to see how low the Voltage can go until the Wemos refuses to connect and send data. So i charged the battery and let it send seonsordata and the battery voltage to thingspeak every 30seconds.
What can i say. The last successful reading was made with a voltage of 2.33Volts and before that it did not drop a single measurement.
Bildschirmfoto 2021-01-05 um 15.42.19.png
Bildschirmfoto 2021-01-05 um 15.42.19.png (28.96 KiB) Viewed 1122 times
I calculated a runtime of the station of 8months for measurements every 30minutes. Even longer for 1h of course (my initial interval). I am excited to see how long it will last for real.

Wiki
Normal user
Posts: 314
Joined: 23 Apr 2018, 17:55
Location: Germany

Re: Help: A guide for a battery powered measuring station

#17 Post by Wiki » 11 Jan 2021, 19:46

As I can see in the picture, you still have the serial ncontroller connected. Shouldn't do that as it consumes too much of energy.

Have a look over here: viewtopic.php?f=5&t=5498#p32183 where I posted some experiences on how to save battery power.

Code: Select all

pi@raspberrypi:~ $ man woman
Kein Handbucheintrag für woman vorhanden
pi@raspberrypi:~ $

Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests