It is currently running under V3.0 Alpha 8
It exercises timers, io pins, writing to files, use of time command (which still confuses me as DST does not seem to work as I would expect so I manually tweak it).
Here is my code so far. Basics work but sometimes it crashes, sometimes so bad it decides to delete default.bas so save often to notepad, etc.
Eventually I may set up a ramp timer for LED lighting. Made one using PIC but it's kind of nice to have a web interface and NTP for time!
'******************************************************************************
'* Aquarium Light Timer for controlling two lights/devices *
'* By Russ McIntire 6/11/16 *
'* Electrodragon Wifi IoT Relay Board *
'* http://www.electrodragon.com/product/wifi-iot-relay-board-based-esp8266/ *
'* GPIO 12 and 13 are relay controlled *
'* GPIO14 is for DHT *
'* *
'* Not optimized, may not work crossing 24 HR boundary *
'******************************************************************************
memclear
DST = read.val(DaylightSavings)
timezone = read.val(TZ)
if DST = 1 then
tz = timezone + 1
else
tz = timezone
endif
timesetup(tz,DST)
delay 5000
let relay1 = 12 'pin for relay1
let relay2 = 13 'pin for relay2
Relay1on = read(relay1ontime)
Relay1off = read(relay1offtime)
Relay2on = read(relay2ontime)
Relay2off = read(relay2offtime)
cls
wprint "Aquarium Light Timer Running"
wprint "<br>"
wprint "<br>"
wprint "The time is currently: "
wprint time("hour:min")
wprint "<br>"
wprint "Timezone: "
textbox timezone
wprint "<br>"
wprint "DST: "
textbox DST
wprint "<br>"
button "Save Timezone", [timezone_update]
wprint "<br>"
wprint "<br>"
wprint "Enter on/off times below and save when done: <br>"
wprint "Valid times are: 00:00 to 23:59"
wprint "<br>"
wprint "Relay 1 - 24 hour (HH:MM) ON "
textbox Relay1on
wprint "OFF "
textbox Relay1off
wprint "<br>"
wprint "Relay 2 - 24 hour (HH:MM) ON "
textbox Relay2on
wprint "OFF "
textbox Relay2off
wprint "<br>"
button "Save Set Times", [Calculate]
gosub [Calculate_Mins]
timer 30000, [CheckTime]
wait
end
[timezone_update]
write(DaylightSavings,str(DST))
write(TZ,str(timezone))
if DST = 1 then
tz = timezone + 1
else
tz = timezone
endif
timesetup(tz,DST)
delay 5000
wprint "<br>"
wprint "Timezone Updated <br>"
wprint "The Updated time is: "
wprint time("hour:min")
wprint "<br>"
wait
[Calculate]
'Persist relay on and off times
write(relay1ontime,Relay1on)
write(relay1offtime,Relay1off)
write(relay2ontime,Relay2on)
write(relay2offtime,Relay2off)
print "Updated"
print "Relay 1 On: " & Relay1on & " Off: " & Relay1off & "<br>"
print "Relay 2 On: " & Relay2on & " Off: " & Relay2off & "<br>"
gosub [Calculate_Mins]
wait
[Calculate_Mins]
r1onh = val(left(Relay1on,2))
r1onm = val(right(Relay1on,2))
r1offh = val(left(Relay1off,2))
r1offm = val(right(Relay1off,2))
r2onh = val(left(Relay2on,2))
r2onm = val(right(Relay2on,2))
r2offh = val(left(Relay2off,2))
r2offm = val(right(Relay2off,2))
r1onminutes = r1onh * 60 + r1onm
if r1onminutes > 1439 then
r1onminutes = 1439
endif
r1offminutes = r1offh * 60 + r1offm
if r1offminutes > 1439 then
r1offminutes = 1439
endif
r2onminutes = r2onh * 60 + r2onm
if r2onminutes > 1439 then
r2onminutes = 1439
endif
r2offminutes = r2offh * 60 + r2offm
if r2offminutes > 1439 then
r2offminutes = 1439
endif
return
[CheckTime]
ct = time("hour:min")
cth = val(left(ct,2))
ctm = val(right(ct,2))
currminutes = cth * 60 + ctm
'Set Relay 1 state
if r1onminutes <= currminutes then
if currminutes < r1offminutes then
io(po,relay1,1)
else
io(po,relay1,0)
endif
else
io(po,relay1,0)
endif
'Set Relay 2 state
if r2onminutes <= currminutes then
if currminutes < r2offminutes then
io(po,relay2,1)
else
io(po,relay2,0)
endif
else
io(po,relay2,0)
endif
wait