-- main.lua -- conta = 0 litro = 0 pin = 2 --> GPIO4 -- Connect print('\nAll About Circuits main.lua\n') tmr.alarm(0, 1000, 1, function() if wifi.sta.getip() == nil then print("Connecting to AP...\n") else ip, nm, gw=wifi.sta.getip() print("IP Info: \nIP Address: ",ip) print("Netmask: ",nm) print("Gateway Addr: ",gw,'\n') tmr.stop(0) end end) -- Start a simplge http server srv=net.createServer(net.TCP) --conn:send("

Hello, SPARTA YEAAHHHHH!!!

" .. litro) --conn:on("sent",function(conn) conn:close() end) srv:listen(80,function(conn) conn:on("receive", function(client,payload) tmr.alarm(6, 100, 1, function () function onChange () --print('The pin value has changed to '..gpio.read(pin)); conta = conta + 1; if conta > 10 then litro = litro + 1; print ('Litros:'..litro); conta = 0; end end gpio.mode(pin, gpio.INT) gpio.trig(pin, 'both', onChange) end) tgtfile = string.sub(payload,string.find(payload,"GET /") +5,string.find(payload,"HTTP/")-2) if tgtfile == "" then tgtfile = "index.htm" end local f = file.open(tgtfile,"r") if f ~= nil then --conn:send("Litros: ".. litro) client:send(file.read()) file.close() else client:send(""..tgtfile.." not found - 404 error.
Home
") end client:close(); collectgarbage(); f = nil tgtfile = nil end) end)