collectgarbage()
tmr.alarm(0, 1000, 1, function(QQ)
print("\nTry Connecting:")
ip, nm, gw=wifi.sta.getip()
if ip ~= nil then
print("\nIP Info: \nIP Address: ",ip,"\n Netmask: ",nm,"\n Gateway: ",gw)
tmr.stop(0)
end
end)
collectgarbage()
for xx=1,10000 do
tmr.delay(50)
end;
collectgarbage()
led_pin = 1
sw_pin = 2
eye_opn=0
adc_id = 0
adc_value = 512
k1=0.11
p00='P'
apc0='11111'
ppm0='1770'
cdeg0='25.1'
fdeg0='77.1'
apc1='22222'
ppm1='1772'
apc2='33333'
ppm2='1773'
kta0='0.01'
lo0='12'
hi0='20'
prb='01.0'
ph='7.0'
blink_open = "http://i.imgur.com/kzt3tO8.png"
blink_close = "http://i.imgur.com/KS1dPa7.png"
site_image = blink_open
collectgarbage()
uart.setup(0,9600,8,0,1)
srv = net.createServer(net.TCP, 30)
srv:listen(80,function(conn)
conn:on("receive", function(conn, payload)
function esp_update()
mcu_do=string.sub(payload,postparse[2]+1,#payload)
if mcu_do == "Update+LED" then print("Noda") end
if mcu_do == "Read+ADC" then
adc_value = adc.read(adc_id)
if adc_value > 1023 then
adc_value = 1023
elseif adc_value < 0 then
adc_value = 0
end
print("ADC: ", adc_value)
end
if mcu_do == "Blink+EYE" then
if eye_opn==0 then
site_image = blink_close
eye_opn=1
else
site_image = blink_open
eye_opn=0
end
end
if mcu_do == "TEST+12345" then
apc0 = apc0 + 100
end
end
postparse={string.find(payload,"mcu_do=")}
if postparse[2]~=nil then esp_update()end
conn:send('HTTP/1.1 200 OK\n\n')
conn:send('<!DOCTYPE HTML>\n')
conn:send('<html>\n')
conn:send('<head><meta content="text/html; charset=utf-8">\n')
conn:send('<title>ESP8266 Blinker Thing</title></head>\n')
conn:send('<body><h1>ESP8266 Blinker Thing!</h1>\n')
conn:send('<IMG SRC="'..site_image..'" WIDTH="98" HEIGHT="49" BORDER="1"><br><br>\n')
conn:send('Temperature__Sensor___DS18B20 <input style="text-align: center" type="text" value="'..p00..'" size="5" maxlength="5"><br>'
..' Probe__K <input style="text-align: center" type="text" value="'..k1..'" size="5" maxlength="5">'
..' Computed_K <input style="text-align: center" type="text" value="'..k1..'" size="5" maxlength="5"><br>'
..' Pool__PH <input style="text-align: center" type="text" value="'..ph..'" size="5" maxlength="5">'
..' PH___@25C <input style="text-align: center" type="text" value="'..ph..'" size="5" maxlength="5"><br>')
conn:send('PulseCount@CurrentT <input style="text-align: center" type="text" value="'..apc0..'" size="5" maxlength="5">'
..' ppm_currentT <input style="text-align: center" type="text" value="'..ppm0..'" size="5" maxlength="5">'
..' T0C <input style="text-align: center" type="text" value="'..cdeg0..'" size="5" maxlength="5"><br>')
conn:send('PulseCountAdj1@25C <input style="text-align: center" type="text" value="'..apc1..'" size="5" maxlength="5">'
..' ppm@25Adj1 <input style="text-align: center" type="text" value="'..ppm1..'" size="5" maxlength="5">'
..' T0F <input style="text-align: center" type="text" value="'..fdeg0..'" size="5" maxlength="5"><br>')
conn:send('PulseCountAdj2@25C <input style="text-align: center" type="text" value="'..apc2..'" size="5" maxlength="5">'
..' ppm@25Adj2 <input style="text-align: center" type="text" value="'..ppm2..'" size="5" maxlength="5"><br>')
conn:send('<p>ADC Value: '..adc_value..'</p><br>')
conn:send('<form action="" method="POST">\n')
conn:send('<input type="submit" name="mcu_do" value="Read ADC">\n')
conn:send('<input type="submit" name="mcu_do" value="Update LED">\n')
conn:send('<input type="submit" name="mcu_do" value="Blink EYE">\n')
conn:send('<input type="submit" name="mcu_do" value="TEST 12345">\n')
conn:send('</body></html>\n')
conn:on("sent", function(conn) conn:close() end)
end)
end)
function round2(num, idp)
return tonumber(string.format("%." .. (idp or 0) .. "f", num))
end
function si(sIN)
buffer=sIN
print("buf--",buffer)
if string.find(sIN,"co") then
cx=(string.find(sIN,"co"))+2
cdeg0 = string.sub(sIN,cx,6) --cx startof data 6 end of data
fdeg0 = round2((cdeg0*1.8) +32,1)
print("cd-",cx,cdeg0,fdeg0)
end
if string.find(sIN,"ao") then
cx=(string.find(sIN,"ao"))+2
apc0 = string.sub(sIN,cx,7)
apc1=round2(apc0/(((cdeg0-25)*.021)+1),1)
apc2=round2((apc1*46.5)/(cdeg0+21.5),1)
print("apc",cx,apc0,apc1,apc2)
end
if string.find(sIN,"bo") then
cx=(string.find(sIN,"bo"))+2
ppm0=string.sub(sIN,cx,6)
print("ppm0",cx,ppm0)
ppm1=round2(ppm0/(((cdeg0-25)*.021)+1),1)
ppm2=round2((ppm0*46.5)/(cdeg0+21.5),1 )
print("ppm",ppm1,ppm2)
end
tmr.alarm(0,500,0,function()
if eye_opn==0 then
site_image = blink_close
eye_opn=1
else
site_image = blink_open
eye_opn=0
end
end)
end
--apc0=string.sub(sIN,string.find(sIN,"pc0=")+4,string.find(sIN,"pm0=")-2) -- 1st