'webcontrolHTML.bas
'picaxe program to control a single relay
'picaxe 14m2 and Wisnet110SR with 1 sec timeout
'1613 bytes out of 2048
'Use HTTP 1.1
'Relays:
'B.1 relay 1
'B.2 relay 2
'B.3 relay 3
'Inputs:
'J3-1 C.0
'J3-2 C.2
'J3-3 C.3
'J3-4 C.4
'Temperature:
'B.5
'Serial Ports
'Serin C.1
'Serout B.4
input c.0
input c.2
input c.3
input c.4
settle:
low B.1
pause 1000
readport:
serin c.1, T1200_4,("GET /"),b1
header: 'response header
SerOut b.4,T1200_4,( "HTTP/1.1 200 OK",13,10 )
SerOut b.4,T1200_4,( "Content-Type: text/html",13,10 )
SerOut b.4,T1200_4,( 13,10 )
sertxd ("b1= ",#b1,13,10) 'optional diagnostic port
if b1 = 48 then '0
goto printhtml
endif
if b1 = 49 then '1
goto on1
endif
if b1 = 50 then '2
goto off1
endif
if b1 = 51 then '3
goto on2
endif
if b1 = 52 then '4
goto off2
endif
if b1 =53 then '5
goto on3
endif
if b1 = 54 then '6
goto off3
endif
if b1 = 55 then '7
goto inport
endif
goto readport
on1:
high B.1
b2=1
goto printHTML
off1:
low B.1
b2=0
goto printHTML
on2:
high B.2
b3=1
goto printHTML
off2:
low B.2
b3=0
goto printHTML
on3:
high B.3
b4=1
goto printHTML
off3:
low B.3
b4=0
goto printHTML
printHTML:
serout b.4, T1200_4,("<!DOCTYPE html><html><body>",13,10)
serout b.4, T1200_4,("<h1>PICAXE WEB SERVER</h1><br>",13,10)
serout b.4, T1200_4,("<b>SELECT RELAY TO CONTROL<br>",13,10)
serout b.4, T1200_4,("<a href=http://YourURLhere:port/1>Relay1 ON</a><br>",13,10)
serout b.4, T1200_4,("<a href=http://YourURLhere:port/2>Relay1 OFF</a><br><br>",13,10)
serout b.4, T1200_4,("<a href=http://YourURLhere:port/3>Relay2 ON</a><br>",13,10)
serout b.4, T1200_4,("<a href=http://YourURLhere:port/4>Relay2 OFF</a><br><br>",13,10)
serout b.4, T1200_4,("<a href=http://YourURLhere:port/5>Relay3 ON</a><br>",13,10)
serout b.4, T1200_4,("<a href=http://YourURLhere:port/6>Relay3 OFF</a><br><br>",13,10)
serout b.4, T1200_4,("<b>RELAY STATUS<br>",13,10)
if b2 = 1 then
serout b.4, T1200_4,("RELAY1=",#b2,"<br>",13,10)
'serout b.4, T1200_4,("<br>",13,10)
endif
if b2 = 0 then
serout b.4, T1200_4,("RELAY1=",#b2,"<br>",13,10)
'serout b.4, T1200_4,("<br>",13,10)
endif
if b3 = 1 then
serout b.4, T1200_4,("RELAY2=",#b3,"<br>",13,10)
'serout b.4, T1200_4,("<br>",13,10)
endif
if b3 = 0 then
serout b.4, T1200_4,("RELAY2=",#b3,"<br>",13,10)
'serout b.4, T1200_4,("<br>",13,10)
endif
if b4 = 1 then
serout b.4, T1200_4,("RELAY3=",#b4,"<br><br>",13,10)
'serout b.4, T1200_4,("<br>",13,10)
endif
if b4 = 0 then
serout b.4, T1200_4,("RELAY3=",#b4,"<br><br>",13,10)
'serout b.4, T1200_4,("<br>",13,10)
endif
Inport:
SerTxd (#pinc.0,#pinc.2,#pinc.3,#pinc.4,13,10)
'serout b.4, T1200_4,("<br>",13,10)
serout b.4, T1200_4,("<b>READ INPUTS<br>",13,10)
'serout b.4, T1200_4,("<br>",13,10)
serout b.4, T1200_4,("Input1=",#pinc.0,"<br>",13,10)
'serout b.4, T1200_4,("<br>",13,10)
serout b.4, T1200_4,("Input2=",#pinc.2,"<br>",13,10)
'serout b.4, T1200_4,("<br>",13,10)
serout b.4, T1200_4,("Input3=",#pinc.3,"<br>",13,10)
'serout b.4, T1200_4,("<br>",13,10)
serout b.4, T1200_4,("Input4=",#pinc.4,"<br><br>",13,10)
'serout b.4, T1200_4,("<br>",13,10)
Ftemp:
Readtemp12 b.5,w0 ' read in result ds18b20
convert:
w0 = w0+880/16*9/5-67
let b9 =43 ' Display + (43) space (32)
IF w0 > 65468 THEN ' If negative
let b9 =45 ' Display - (45)
w0 = -w0
endif
BINTOASCII w0,b8,b7,b6
IF b8 = "0" THEN : b8 = " ": endif ' zero blanking b8
IF b7 = "0" THEN : b7 = " ": endif ' zero blanking b7
printtempF:
'SERTXD ("tempF=",b9,b8,b7,b6,13,10)'resolution to 1
serout b.4,T1200_4, ("<b>Temperature " ,b9,b8,b7,b6," F<br><br>",13,10)
'serout b.4, T1200_4,("<br>",13,10)
serout b.4, T1200_4,("<a href=http://YourURLhere:port/0>Reload this Page</a></body></html>",10,13)
goto readport
end