--13w 1.4.0 vt={} vt.x='do140-13wa.lua - serdat.lua' vt.a=1459 vt.b=1459 vt.c=1459 vt.d=1459 vt.e=1459 vt.baud=9600 vt.rfh=15 vt.k1=0.11 vt.p00='P' vt.apc0=44444 vt.ppm0=1770 vt.ppm1=1770 vt.ppm2=1770 vt.cdeg0=25.1 vt.fdeg0=77.1 vt.prb=1.0 vt.ph=7.2 vt.pha=7.20 vt.adc=1000 vt.s_img = "http://i.imgur.com/kzt3tO8.png" vt.heap=12345 vt.bgc ="Cyan" vt.cmx="--" vt.cmd="--" vt.Lcb= 0 vt.ESP=" " vt.sin=" " ------------------------------------------------------ local function c_station() if wifi.sta.getip() == nil then print("Connect") else ip, nm, gw = wifi.sta.getip() do_next = c_server print("IP: "..ip,"NM: "..nm,"GW: "..gw.."\n") end collectgarbage() end ------------------------------------------------------ function c_server() do_next = nocode -- just in case timewaste -- uart.setup(0,38400,8,1,0) sv=net.createServer(net.TCP, 30) --create server sv:listen(80,function(c) --listen on port 80 uart.on("data", "\n",uartRX,0) c:on("sent", Send80) c:on("receive", Rcv80) --when rcv do function rcv99 end) end ----------------------------- function nocode() -- tmr.stop(0) collectgarbage() end ----------------------------- function uartRX(sdin) serdat = require("serdat") serdat.S1(sdin) end --[[ local serdat = {} function serdat.S1(sdin) if #sdin <= 2 then return end -- suspect just crlf ?? xdin=string.sub(sdin,1,4) ydin=string.sub(sdin,1,5) -- 000>cr vt.ESP = #sdin..","..ydin cx = string.find(sdin,"]") if string.sub(sdin,1,2)=="[c" and cx ~= nil then cx = string.find(sdin,"/") vt.cdeg0 = string.sub(sdin,3,cx-1) sdin = string.sub(sdin,cx+1,#sdin) cx = string.find(sdin,"/") vt.ppm0 = string.sub(sdin,1,cx-1) sdin = string.sub(sdin,cx+1,#sdin) cx = string.find(sdin,"/") vt.apc0 = string.sub(sdin,1,cx-1) sdin = string.sub(sdin,cx+1,#sdin) cx = string.find(sdin,"/") vt.ph = string.sub(sdin,1,cx-1) sdin = string.sub(sdin,cx+1,#sdin) cx = string.find(sdin,"]") vt.prb = string.sub(sdin,1,cx-1) --uart.write(0,"HB\r\n") - else vt.sbuf=vt.sbuf..sdin end local strt,endx,sz,xx for xx=1,10 do sz = #vt.sbuf if sz <= 1023 then break end strt,endx=string.find(vt.sbuf,"\r\n") vt.sbuf = string.sub(vt.sbuf,endx+1,sz) --RTRIM buffer end end return serdat --]] -------------------------------------------------------- function process1() end -------------------------------------------------------- function round2(num, idp) return tonumber(string.format("%." .. (idp or 0) .. "f", num)) end -------------------------------------------------------- function trim (s) -- String trim left and right return (s:gsub ("^%s*(.-)%s*$", "%1")) end -------------------------------------------------------- function Rcv80(c, pl) -- print("PL ",pl) local B_Opn = "http://i.imgur.com/kzt3tO8.png" local B_Clo = "http://i.imgur.com/KS1dPa7.png" local Bx=B_Opn local strt_ndx,end_ndx,tmp vt.cmx="--" strt_ndx, end_ndx = string.find (pl, "pwmi=") -- find 1st pwmi if strt_ndx ~= nil then -- POST occurred cmd = string.sub(pl, end_ndx+1,#pl) -- save fld 1 strt_ndx, end_ndx = string.find (cmd, "&pwmi=") -- 2nd &pwmi if submit if strt_ndx then cmd = string.sub(cmd,1,strt_ndx-1) -- fld 2 end end collectgarbage() -- cmdchk = require("cmdchk") -- cmdchk.C1() -- package.loaded.cmdchk = nil if cmd==nil then cmd="--" elseif cmd=="Blink" then if vt.s_img == B_Opn then vt.s_img = B_Clo else vt.s_img = B_Opn end elseif cmd=="Baud" then if vt.baud==9600 then vt.baud=38400 elseif vt.baud==38400 then vt.baud=115200 elseif vt.baud==115200 then vt.baud=9600 end uart.setup(0,vt.baud,8,0,1) elseif cmd=="Adc" then adc_value = adc.read(0) elseif cmd=="Clr" then vt.sbuf="" elseif cmd=="qqq" then uart.write(0,"qqqqqqqq\r\n") elseif cmd=="Rfh" then if vt.rfh >=10 then vt.rfh = vt.rfh+5 end if vt.rfh <=9 then vt.rfh = vt.rfh+1 end if vt.rfh>=35 then vt.rfh = 5 end else tmp=0 if cmd=="[I]" or cmd=="[D]" or cmd=="[V]" or cmd=="[W]" or cmd=="[Y]" then tmp=1 elseif cmd=="[N]" or cmd=="K1" or cmd=="K2" or cmd=="K2" then tmp=1 elseif cmd=="K%d" then tmp=1 -- print("\n"..vt.cmd) elseif cmd=="Z%d" then tmp=1 -- print("\n"..vt.cmd) else tmp=1 --TX other cmd's + crlf end end if tmp==1 and cmd ~="--" then if vt.bgc=="Cyan" then vt.bgc="Yellow" else vt.bgc = "Cyan" end uart.write(0,cmd.."\r\n") ----------------------------------- end if cmd ~= "--" then vt.cmx=cmd.."|"..vt.Lcb end vt.heap = node.heap() vt.cmx=cmd.."|"..vt.Lcb cmd="--" vt.adc = adc.read(0) --- Temperature Adjustments + ----- vt.fdeg0 = round2((vt.cdeg0*1.8) +32,1) vt.ppm1=round2(vt.ppm0/(((vt.cdeg0-25)*.021)+1),1) vt.ppm2=round2((vt.ppm0*46.5)/(vt.cdeg0+21.5),1 ) vt.ph = vt.ph * 1 -- trim left vt.prb = vt.prb * 1 vt.pha=25-vt.cdeg0 vt.pha = round2((vt.ph + (vt.pha*.004)),2) if vt.pha < 0 then vt.pha = round2((vt.ph + (vt.pha*.002)),2) end collectgarbage() -- how to delay ? rfh=vt.rfh Scnt=0 cmx = vt.cmx local cbuf='\n\n' ..'' ..'
' ..'' ..'' ..'
' ..zver ..''..rfh..'
'..vt.x..'BAUD = '..vt.baud..'-

' c:send(cbuf) -- print("CB:",#cbuf) vt.Lcb=#cbuf vt.a=#cbuf cbuf=nil Scnt=1 end --function end ---------------------------- function Send80(c) --uart.write(0,Scnt) if Scnt==1 then local cbuf='
' ..'' ..'' ..'' ..'' ..'' ..'' ..'' ..'' ..'
SensorTempCTempFPPMcntrPPM__Adj__1Adj__2
DS18B20'..vt.p00..''..vt.cdeg0..''..vt.fdeg0..''..vt.apc0..''..vt.ppm0..''..vt.ppm1..''..vt.ppm2..'
Probe-KPool-PHPH-AdjADC Value ESP --> PIC PIC --> ESP Heap
'..vt.prb..''..vt.ph..''..vt.pha..''..vt.adc..''..vt.cmx..''..vt.ESP..''..vt.heap..'

' vt.b=#cbuf c:send(cbuf) cbuf=nil elseif Scnt==2 then local cbuf='
' ..'' ..'' ..'' ..'' ..'' ..'' ..'' ..'' ..'' -- ..'' -- ..'' ..'' ..'' ..'
' ..'CMD' ..'

' vt.c=#cbuf c:send(cbuf) cbuf=nil elseif Scnt==3 then local cbuf='

' ..vt.a.."|"..vt.b.."|"..vt.c.."|"..vt.d.."|"..vt.e.." Baud: "..vt.baud vt.d=#cbuf c:send(cbuf) cbuf=nil end if Scnt >=4 then c:close() c=nil end Scnt=Scnt+1 vt.Lcb=vt.d collectgarbage() end -- function end --------- MAIN ---------------------- wifi.setmode (wifi.STATION) wifi.sta.config ("1302ec-NETGEAR81","mikeisgreat101144") wifi.sta.autoconnect (1) ------------------------------------- --aVer, bVer, cVer, cid, fid, fsz, fm, fsp = node.info(); aVer, bVer, cVer = node.info() yver=aVer.."."..bVer.."."..cVer ------------------------------------- zver = "

ESP8266 SDK " ..yver --

ESP8266 SDK 1.4.0 Version!

.." Version!" --print(yver) collectgarbage() ------------------------------------- --uart.on("data", "\n",uartRX,0) do_next = c_station tmr.alarm( 0, 250, 1, function() do_next() end) --.5ms chek next do ------------------------------------- vt.sbuf='000> 00001,00032 00342,65535 00700,66535 01000,34770 01400,65535\r\n' ..'020> 00001,00032 00342,65535 00700,66535 01000,34770 01400,65535\r\n' --..'040> 00001,00032 00342,65535 00700,66535 01000,34770 01400,65535\r\n' --..'060> 00001,00032 00342,65535 00700,66535 01000,34770 01400,65535\r\n' --..'080> 00001,00032 00342,65535 00700,66535 01000,34770 01400,65535\r\n' --..'100> 00001,00032 00342,65535 00700,66535 01000,34770 01400,65535\r\n' --..'120> 00001,00032 00342,65535 00700,66535 01000,34770 01400,65535\r\n' --..'140> 00001,00032 00342,65535 00700,66535 01000,34770 01400,65535\r\n' --..'160> 00001,00032 00342,65535 00700,66535 01000,34770 01400,65535\r\n' --..'180> 00001,00032 00342,65535 00700,66535 01000,34770 01400,65535\r\n' --..'200> 00001,00032 00342,65535 00700,66535 01000,34770 01400,65535\r\n' --..'220> 00001,00032 00342,65535 00700,66535 01000,34770 01400,65535\r\n'