As the title says... Chat on...

User avatar
By ccxx
#6054 Hi,
i wanto to send a brodcast on my lan when GPIO2 goes high. I have a listner on my pc and with this code
Code: Select allsu=net.createConnection(net.UDP)
su:on("receive",function(su,c) print(c) end)
su:connect(8889,"192.168.1.255")
pin=8
gpio.mode(pin,gpio.INPUT)
if gpio.read(pin)==1 then
su:send("ok")
print("ok")
else
print("NO INPUT")
end
it works, but only if GPIO2 pin is high when ESP starts

First of all, how to create a loop that wait for the input on GPIO2 ?
User avatar
By zeroday
#6122
ccxx wrote:Hi,
i wanto to send a brodcast on my lan when GPIO2 goes high. I have a listner on my pc and with this code
Code: Select allsu=net.createConnection(net.UDP)
su:on("receive",function(su,c) print(c) end)
su:connect(8889,"192.168.1.255")
pin=8
gpio.mode(pin,gpio.INPUT)
if gpio.read(pin)==1 then
su:send("ok")
print("ok")
else
print("NO INPUT")
end
it works, but only if GPIO2 pin is high when ESP starts

First of all, how to create a loop that wait for the input on GPIO2 ?


you can poll GPIO2 every second
Code: Select alltmr.alarm(0, 1000, 1, function()
if gpio.read(pin)==1 then
su:send("ok")
print("ok")
else
print("NO INPUT")
end
end)


or, use gpio.trig() api.
User avatar
By ccxx
#6127 Thank you for your answer.

Can i poll every 500ms without problem ? One second could be too long ...

I tried with gpio.trig without success, or better, i had to reflash the firmware because the ESP entered in a infinite loop without any possibilitiy to communicate.
Any good example of use ?