agroszer wrote: ↑23 Oct 2023, 09:11
What else can I do to reduce wake time (and power usage)?
I can show you how my code works to reduce uptime when reading a sensor and sending its data to thingspeak.
Basically i wait for WiFi and sensordata to become available and send it to thingspeak.
I don't use the sleep options in the /config tab. I emulate therefore the "30seconds after reboot" behavior in rules
If the data is send successfully go to sleep immediately....
Code: Select all
On System#Wake Do
LoopTimerSet_ms,1,100,50 //loop until wifi is connected and we got data from sensor
GPIO,12,1 //Turn on the sensor
TaskRun,1 // Update first sensor
Endon
On WiFi#Connected Do
Let,1,1
Endon
On sensor_extern#All Do
Let,2,1
Endon
On Rules#Timer=1 Do
If [var#1]=1 and [var#2]=1 //when wifi is connected and there are values from the sensor send data
SendToHTTP api.thingspeak.com,80,/update?api_key=XXXXXXXXXXXXX&field8=[batterie#Analog]&field4=[sensor_extern#Humidity]&field7=[sensor_extern#Pressure]&field3=[sensor_extern#Temperature]
TimerSet_ms,1,0
Let,1,0
Let,2,0
Elseif %eventvalue2%=50 //after 5sec go back to sleep
Event,sleep
Endif
Endon
On http#api.thingspeak.com=200 Do //when receiving the HTTP code 200 it basically means the sending was successful
Event,sleep
Endon
On sleep Do //after sending data either go to sleep or if power cycled wait 30sec
If [boot#isboot]=1
DeepSleep,1800 //comment this out to stop deepsleep
Else
TimerSet,2,30
TaskValueSet,boot,1,1 //this sets the first value of a dummy device called boot to 1
//it doesn´t survive a reboot and therefore becomes 0. so you have 30 seconds after a reboot to do changes
Endif
Endon
On Rules#Timer=2 Do
Event,sleep
Endon