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

User avatar
By promy
#13559 I am trying to put a delay in the function inside: conn2:on("receive",function(conn2,payload)
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:
Code: Select allsrv=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?
User avatar
By TerryE
#13568 A delay of 100µS isn't going to give an Arduino much time to do anything. Don't you want at least a few mS?
User avatar
By promy
#13570 yes, but the esp crashes when i put tmr.delay(1000) inside the loop? (or use the tmr.now()+ 10000)
just thinking, could it be the watchdog? it crashes after 20 to 30 times delay(100000)
User avatar
By cal
#13571
promy wrote:yes, but the esp crashes when i put tmr.delay(1000) inside the loop? (or use the tmr.now()+ 10000)
just thinking, could it be the watchdog? it crashes after 20 to 30 times delay(100000)


-- Pet the dog...
tmr.wdclr()