Chat freely about anything...

User avatar
By nedoskiv
#71665 Hello,

I tried to achieve reading content from website (HTTP request) and do something depending on the response into a infinite loop, for that case I tried both NET and HTTP module , my idea is to wait into whileloop until NET or HTTP function finish work, and then decide what to do (depends on errors, etc)
but informatelly if my file is still running while NET or HTTP callback functions are executed, board reboots.
here is one code for example that do that:

Code: Select allTstart  = tmr.now()
print('httpget.lua started at ' .. Tstart)
httplink="http://r-control.eu/esp8266.php?reportfrom="
print ("here is the data\n")
print (code)
code = nil
success= 0

function pause (seconds)
temptimer = tmr.now() + seconds
print (seconds.." pause\n")
print (temptimer.." - " ..tmr.now())
while temptimer > tmr.now()
do
print (temptimer.." - " ..tmr.now())
end


end


http.get("http://r-control.eu/esp8266.php?reportfrom=", nil, function(code, data)
    if (code < 0) then
      
--      print("HTTP request failed")
      success=2
--      dofile(wifi_config_permanent.lua)
    else
    
--     print(code, data)
     success=1
--     dofile(wifi_config_permanent.lua)
    end
  end)

print ("waiting for function to complete\n")
while success==0
   do
   print ( tmr.now())
   end

print ("Here is the response")
print (success)


Any idea why that happen? Tried old nodemcu build, and latest one, both HTTP or NET connections, they fail in same way - never seen message "Here is the response"
User avatar
By RICARDO PACHECO
#71719 Hi!

Well, I like to develop using Arduino IDE, I think that to me, was the better choice.
I didn't know if I undestood everything about your project, but I will try to help you, but in my universe.
Check out these:
https://github.com/me-no-dev/ESPAsyncWebServer
https://github.com/me-no-dev/ESPAsyncTCP