I am trying to make some robust code for my temperature logging project. The ESP starts off by requesting the number of seconds until next update is required from a nodejs service, this aligns all the temperature sensors so I receive all the temperatures at the same time and offloads any time keeping functions to a server.
I dont see a listener for failed connection attempt. The documentation says these are available. "connection", "reconnection", "disconnection", "receive", "sent"
If i try to connect to a sever that is not running I am finding it difficult to detect, nothing is fired for event reconnection or disconnection. On bootup of the esp if the server is down I want it to keep trying until it gets a response. I am having one of these up in the ceiling of my house I don't want to go up there and manually reset it. Im not even sure if the connection is closed.
Here is my code that does seem to work but I dont feel its the right way about it. Basically a 60 second time is setup, once something is received the timer is stoped.
function getSleepDelay()
tmr.alarm(1,60000,1,function()
print('Attempting to get delay till next update required')
conn=net.createConnection(net.TCP, 0)
conn:connect(5050,'192.168.1.8')
conn:send("sleepdelay\n")
conn:on("receive", function(sck, c)
tmr.stop(1)
nextUpdate(c)
conn:close()
end)
conn:on("reconnection",function() print('reconnect trying to get sleep delay') end )
end)
end