This to give the esp the time to read the requested data over serial (from an arduino). This reading is done by uart.on("data", "\r", function(data)
However, it seems that it just ignores the tmr.delay(100)
the whole code inside the conn2:on is:
srv=net.createServer(net.TCP) srv:listen(80,function(conn2)
conn2:on("receive",function(conn2,payload)
--print(payload)
if string.find(payload,"comm=") ~= nil then --we ontvangen een commando
local a
a = string.find(payload,"vijver")
if a then
value2 = "test"
print('HH\n') --commando H doorsturen, in arduino vraagt dit de hoogte op van de vijver
conn2:send(verwerk())
end
a = string.find(payload,"regenwater")
if a then
value2 = "test"
print('GH\n') --commando G doorsturen, in arduino vraagt dit de hoogte op van de vijver
conn2:send(verwerk())
end
end)
conn2:on("sent",function(conn2) conn2:close() conn2 = nil end)
end)
function verwerk ()
local teller = 0
while value2 == "test" do
--print (".\n")
volgende = tmr.now() + 10000
--print (volgende)
while tmr.now() < volgende do zomaar = 1 end
if teller > 500 then break end
teller = teller + 1
end
if value2 == "test" then return("fout geen hoogte bekend") else return(value2) end
end
Does anyone know how to give the arduino the time to respond to the esp?