Edit New issue problem with net.socket:send()
Posted: Wed May 06, 2015 4:57 pm
Hello.
This is the code I'm trying to run on my ESP8266.
When I try to send packets outside the while loop, it works fine.
But the packets inside the loop are not being sent.
I know I'm supposed to use tmr.alarm() instead of tmr.delay(), but still not sure why and how.
Anyone has any tip on this issue?
This is the code I'm trying to run on my ESP8266.
When I try to send packets outside the while loop, it works fine.
But the packets inside the loop are not being sent.
I know I'm supposed to use tmr.alarm() instead of tmr.delay(), but still not sure why and how.
Anyone has any tip on this issue?
Code: Select all
-- Reading liquid flow rate using an ESP8266
-- Code adapted by Bernardo Rodrigues
--from PC Fan RPM code written by
--Crenn@thebestcasescenario.com
count = 0
conn=net.createConnection(net.TCP, false)
conn:connect(8888,"192.168.0.103")
--count interrupts
function rpm()
count = count + 1
end
--enable interrupts
function enInt()
gpio.mode(6, gpio.INT)
gpio.trig(6, "up", rpm)
end
--disable interrupts
function disInt()
gpio.mode(6, gpio.INPUT)
end
consumption = 0
--infinite loop
while 1 do
count = 0 --Set NbTops to 0 ready for calculations
enInt() --Enable interrupts
tmr.delay(1000000) --Wait 1 second
disInt() --Disable interrupts
flux = (count * 60 / 7.5)
consumption = consumption + flux/36000
conn:send(consumption)
print(flux .. " L/hour")
print(consumption .. " L consumed\r\n")
end