I have shown a few examples including one for "Run Once, On Startup" and also a simple "@ midnight" trigger.
Code: [Local Link Removed for Guests]
'
' ' *******************************
' Date: Nov 2022
' Filename:Task_Timer.bas
' Function: Annex Task Timer
' Device: ESP32/8266
'
' References:
'
' *******************************
' v0.05 initial
'
dim tt(10) 'Task Timer array
'Task "Tick" Timer List
'tt(0)=Expired, tt(-1)=Disabled
tt(0)=0' seconds , [u]set to run once on startup[/u]
tt(1)=10' seconds
tt(2)=30' seconds
tt(3)=60' seconds
tt(4)=86400-TIMEUNIX(time$) ' [u]set to trigger at mid night , then 24 hrs thereafter[/u]
tt(5)=-1' seconds 'wifi sleep
tt(6)=-1' seconds 'wifi wake
'
' Timers & Interupts
timer0 1000 ,T1 'establish seconds "Tick Timer"
tt(5)=10 'set up trigger task 5 wifi sleep
'main program loop
do
it=millis
option.WDTreset
if tt(0)=0 then
tt(0)=-1 'dont run again
gosub onStartup
end if
If tt(1)=0 Then
tt(1)=10
'eg. 10 second report
'wlog "The Temperature DS18B20 is ";ds_temp ; "C"
EndIf
If tt(2)=0 Then
tt(2)=30
if pin(12)=0 then gosub concheck 'only if wifi enabled
EndIf
'wifi sleep
if tt(5)=0 then
tt(5)=-1 'dont run again
wlog "******************************** sleep wifi"
wifi.sleep
tt(6)=10 'wake wifi trigger
end if
'wifi wake
if tt(6)=0 then
tt(6)=-1 'dont run again
wlog "********************************** wake wifi"
wifi.awake
end if
'check for midnight
'wlog tt(4)
If tt(4)=0 Then
tt(4)=86400
mmrain=0 'reset rain
EndIf
loop
'***** End main program loop
end
'sub routines
T1: 'Tick Timer
'update the task timer array tt()
for x= 0 to 10
y=tt(x)
if y>0 then
y=y-1
tt(x)=y
end if
next x
return