Code: [Local Link Removed for Guests]
'Zim's Annex Basement monitor v1
onHtmlReload create_page
onhtmlchange update
EMAIL.SETUP "smtp.gmail.com", 465, "zim@gmail.com", "zim123" 'replace with your login / password
D1=5:D2=4:D5=14
hmset = 42 ' sets the humidity alarm threshold
tmpset = 4 ' sets the low temp alarm threshold
PIN.MODE D5, INPUT 'pull up to 3.3v with 475K resistor for water probe (don't use pullup)
PIN.MODE D2, OUTPUT 'LED
PIN(D2)= 1 'alive indicator led
DHT.SETUP 5, 22
tmp = DHT.TEMP:hm = DHT.HUM
pause 2000
wtr$ = "NO":wtrg = 0:ttrig = 0:htrg = 0
stat$ = "---- OK ----"
ad$ = "zim@gmail.com":nu$ = "4565657774@msg.telus.com":ti$ = "Basement"
txtbtmp$ = "text-align:center;display:block;width:54px;height:42px;font-size:30;font-weight:bold"
txtbwtr$ = "text-align:center;display:block;width:65px;height:42px;font-size:30;font-weight:bold"
txtbhm$ = "text-align:center;display:block;width:54px;height:42px;font-size:30;font-weight:bold"
txtbstat$ = "text-align:center;display:block;width:160px;height:26px;font-size:15;font-weight:bold"
gosub create_page
timer0 5000, update
wait
create_page:
cls
A$ = ""
A$ = A$ + |<!DOCTYPE html><html><body><style>|
A$ = A$ + |body {background-color: black;}|
A$ = A$ + |p {font-size:24px;}|
A$ = A$ + |</style>|
A$ = A$ + |</style><center>|
A$ = A$ + |<center>|
A$ = A$ + |<p><font color = 'white', font size = '6'>Crawl Space Monitor</font></p>|
A$ = A$ + |</center>|
A$ = A$ + |<table align='center' width='300' height='100' bgcolor='lightgreen' border='1' cellpadding='8'>|
A$ = A$ + |<th>|
A$ = A$ + |<p>Crawl Space<br>Temp.</p></th></center>|
A$ = A$ + |<th><center>|
A$ = A$ + textbox$(tmp, "txt1")
A$ = A$ + |</th></center>|
A$ = A$ + cssid$("txt1", txtbtmp$)
A$ = A$ + |</table>|
HTML A$ 'break up html
A$ = ""
A$ = A$ + |<table align='center' width='300' height='100' bgcolor='lightgreen' border='1' cellpadding='8'>"|
A$ = A$ + |<center><th>|
A$ = A$ + |<p>Crawl Space<br>Humidity</p>|
A$ = A$ + |</th></center>|
A$ = A$ + |<th><center>|
A$ = A$ + textbox$(hm, "txt2")
A$ = A$ + |</th></center>|
A$ = A$ + cssid$("txt2", txtbhm$)
A$ = A$ + |</table>|
A$ = A$ + |<table align='center' width='300' height='100' bgcolor='lightgreen' border='1' cellpadding='8'>"|
A$ = A$ + |<center><th>|
A$ = A$ + |<p>Water<br>Detection</p>|
A$ = A$ + |</th></center>|
A$ = A$ + |<th><center>|
A$ = A$ + textbox$(wtr$, "txt3")
A$ = A$ + |</th></center>|
A$ = A$ + cssid$("txt3", txtbwtr$)
A$ = A$ + |</table>|
HTML A$ 'break up html
A$ = ""
A$ = A$ + |<table align='center' width='300' bgcolor='lightblue' border='1' cellpadding='8'>|
A$ = A$ + |<td><center>|
A$ = A$ + |<b><big>Crawl Space Status</big></b>|
A$ = A$ + |</center><center>|
A$ = A$ + textbox$(stat$, "txt4")
A$ = A$ + cssid$("txt4", txtbstat$)
A$ = A$ + |</center></td></table>|
A$ = A$ + |<br><center>|
A$ = A$ + button$("<b><big>Turn OFF</big><b/>", offf)
A$ = A$ + |</table>|
HTML A$
A$ = ""
autorefresh 2000
return
update:
PIN(D2)= 1
tmp = DHT.TEMP:hm = DHT.HUM
pause 2000
if (tmp < tmpset)and(stat$ = "---- OK ----") then stat$ = "Temperature Low"
if (hm > hmset)and(stat$ = "---- OK ----") then stat$ = "Humidity High"
if PIN(D5)= 0 then wtr$ = "YES" else wtr$ = "NO"
if (PIN(D5)= 0)and(stat$ = "---- OK ----") then stat$ = "Water Detected"
if (PIN(D5)= 1)and(tmp > 4)and(hm < 38) then let stat$ = "---- OK ----"
if PIN(D5)= 0 then gosub alert_water
if tmp < tmpset then gosub alert_temp
if hm > hmset then gosub alert_hum
PIN(D2)= 0
return
alert_hum:
htrg = htrg + 1
if htrg >= 720 then htrg = 0 'will email every hour
if htrg <> 1 return
html cssid$("txt2", "box-shadow: 12px 0px red;")
print EMAIL (ad$, nu$, ti$, "Basement humidity is high")
pause 100
wlog "high humidity sent"
refresh
return
alert_temp:
ttrg = ttrg + 1
if ttrg >= 720 then ttrg = 0 'will email every hour
if ttrg <> 1 return
html cssid$("txt1", "box-shadow: 12px 0px red;")
print EMAIL (ad$, nu$, ti$, "Basement temperature is low")
pause 100
wlog "low temp sent"
refresh
return
alert_water:
wtrg = wtrg + 1
if wtrg >= 720 then wtrg = 0 'will email every hour
if wtrg <> 1 return
html cssid$("txt3", "box-shadow: 12px 0px red;")
print EMAIL (ad$, nu$, ti$,"Basement water detected")
pause 100
wlog "water message sent"
refresh
return
offf:
timer0 0
cls
butt$ = "background-color:lightblue;text-align:center;display:block;width:180px;height:80px;font-size:40;font-weight:bold;box-shadow: 3px 3px black;border-radius:5px;line-height:1"
A$ = A$ + |<!DOCTYPE html><html><body><style>|
A$ = A$ + |body {background-color: black;}|
A$ = A$ + |p {font-size:36px;}|
A$ = A$ + |</style>|
A$ = A$ + |<br><center>|
A$ = A$ + BUTTON$("Restart", turnon, "but1")
A$ = A$ + cssid$("but1", butt$)
A$ = A$ + |</center>|
A$ = A$ + |</body>|
A$ = A$ + |</html>|
HTML A$
A$ = ""
autorefresh 2000
PIN(D2)= 1
'onHtmlReload offf
return
turnon:
'(D2)= 0
cls
reboot