Post about your Basic project here

Moderator: Mmiscool

User avatar
By heckler
#59027 Hi ardhuru,
Thanks for the feedback.

So my project has been running for just under 24 hours and it is still showing within a minute of real time. The internal oscillator of this module seems to be sufficiently accurate to be +/- 1 minute in 24 hrs.

As you may have noticed the current status of the code does not eve recognize Seconds. So I am not sure it would be useful to try and re-sync the clock more than once a day.

But I am going to work on making the code re-attempt to get the time whenever it fails. ie. to have the code make successive attempts say every 10 minutes until it is successful.

But "to each his own" this code is just a basis for others to take and modify to their hearts content. :mrgreen:

regards
dwight
User avatar
By robert badiduwitz
#59061 I did something similar using the olimex esp module to sound off a PA system bell sound for our shop to indicate break times, lunch, cleanup, etc. The olimex board has a relay and esp on one little board. Here is the link.
https://www.olimex.com/Products/IoT/ESP8266-EVB/open-source-hardware
I bought it from amazon for $15.00. The PA system has a dry contact input to sound a "bell", which is a series of different tones that lasts for about 4 seconds, so I do that twice in the [dorelay] sub because the shop is pretty loud sometimes. Here is the link for the PA unit.
https://www.vikingelectronics.com/product-details.php?pid=317#
Also, at 1 in the morning, it updates the time to keep it current. I have 7 different times you can store but you can add many more very easily and also save them in case of power failure. I am sure that this could also be used with the sonoff with proper pin changes, etc. and you can add some fancy things like the original poster did. This is just another simple way to do time based things.

Code: Select allmemclear
cls

relay = 5
LED = 1
blink = 1
tz = -8
DST = 0

for x = 1 to 20 'show blinky at startup
io(po,LED,0)
delay 40
io(po,LED,1)
delay 40
next x

alarm1 = read(alarm1s)
alarm2 = read(alarm2s)
alarm3 = read(alarm3s)
alarm4 = read(alarm4s)
alarm5 = read(alarm5s)
alarm6 = read(alarm6s)
alarm7 = read(alarm7s)

timesetup(tz,DST)
delay 5000

wprint "<br><br>"
curtim = time("hour:min:sec")
wprint "Time Now:  "
textbox curtim

wprint "<br><br>"

wprint "Enter alarm times in HH:MM 24 hour format"
wprint "<br>"
wprint |Press "Update All Alarms" button when done|
wprint "<br><br>"
wprint "Alarm 1  "
textbox alarm1
wprint "<br>"
wprint "Alarm 2  "
textbox alarm2
wprint "<br>"
wprint "Alarm 3  "
textbox alarm3
wprint "<br>"
wprint "Alarm 4  "
textbox alarm4
wprint "<br>"
wprint "Alarm 5  "
textbox alarm5
wprint "<br>"
wprint "Alarm 6  "
textbox alarm6
wprint "<br>"
wprint "Alarm 7   "
textbox alarm7
wprint "<br>"


wprint "<br><br>"
button "Update All Alarms", [updatealarms]
button "Test Alarm", [dorelay]
button "End Program", [endprog]

timer 1000, [updatetime]
wait

[updatetime]

curtime = time("hour:min")

if (curtime = alarm1) and (val(time("sec")) = 0) then goto [dorelay]
if (curtime = alarm2) and (val(time("sec")) = 0) then goto [dorelay]
if (curtime = alarm3) and (val(time("sec")) = 0) then goto [dorelay]
if (curtime = alarm4) and (val(time("sec")) = 0) then goto [dorelay]
if (curtime = alarm5) and (val(time("sec")) = 0) then goto [dorelay]
if (curtime = alarm6) and (val(time("sec")) = 0) then goto [dorelay]
if (curtime = alarm7) and (val(time("sec")) = 0) then goto [dorelay]

if (curtime = "01:00") then 'update clock at 1 in the a.m.
timesetup(tz,DST) 
delay 5000
endif

if blink = 1 then  'show heartbeat on LED
blink = 0
else
blink = 1
endif
io(po,LED,blink)
wait

[dorelay]
serialprintln "relay sub"
io(po,relay,1)
delay 250
io(po,relay,0)
delay 4000
io(po,relay,1)
delay 250
io(po,relay,0)
wait

[updatealarms]
write(alarm1s,alarm1)
write(alarm2s,alarm2)
write(alarm3s,alarm3)
write(alarm4s,alarm4)
write(alarm5s,alarm5)
write(alarm6s,alarm6)
write(alarm7s,alarm7)
wait

[endprog]
timer 0
end
User avatar
By heckler
#59085 Hey Group,

If you downloaded my "working" code above you may want to re-download it as there was a section of the code that had erroneously been duplicated three times. Must have been an issue with my copy/paste or something.

At any rate I "think" the above code is now correct.

The duplicated code was toward the top where several of the variables were being pre-loaded.

regards
dwight