Skip to content

Instantly share code, notes, and snippets.

@ccfiel
Created May 11, 2017 07:45
Show Gist options
  • Save ccfiel/7ad60bcc35dfc4bea8db54dbd91297f6 to your computer and use it in GitHub Desktop.
Save ccfiel/7ad60bcc35dfc4bea8db54dbd91297f6 to your computer and use it in GitHub Desktop.
-- main.lua --
conta = 0
litro = 0
pin = 2 --> GPIO4
-- Connect
print('\nInitializing...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 simple http server
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive",function(conn,payload)
print(payload)
conn:send("<h1> Litros </h1>" .. litro)
end)
conn:on("sent",function(conn) conn:close() end)
end)
tmr.alarm(6, 100, 1, function ()
function onChange ()
--print('The pin value has changed to '..gpio.read(pin));
conta = conta + 1;
if conta > 440 then
litro = litro + 1;
print (litro);
conta = 0;
end
end
gpio.mode(pin, gpio.INT)
gpio.trig(pin, 'both', onChange)
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment