I'm new to esp8266 so my goal is simple, to make a loop that connects to a web server wait for data from it (or error) and do something depending of what command it receives or if an error accurs.
My limited knowledge led me to http library, but looks like it is a asynhronous function and my lua script do not work preperly, so I use a variable and make rest of the script until http function call it fallback funtion. But looks like board restart by some reason, I tried of different version of nodemcu, even with net library instead of http one, and board still restarts
here is my simple script:
Tstart = tmr.now()
print('httpget.lua started at ' .. Tstart)
httplink="http://r-control.eu/esp8266.php?reportfrom="
code = nil
success= 0
http.get("http://r-control.eu/esp8266.php?reportfrom=", nil, function(code, data)
if (code < 0) then
print("HTTP request failed")
success=2
else
print(code, data)
success=1
end
end)
print ("waiting for function to complete\n")
while success==0
do
print ( tmr.now())
end
print ("here is the data\n")
print (code)
I never see "here is the data" message, probabbly restart after while condition ends.
Thank you in advance for your attention.