-
• #2
That's interesting - I wonder, does it still work as a server after that error? The ESP8266 is reporting
no change
, which is being treated as an error - however it might not be - it might just be reporting that a server is being created with the same details as last time and the driver shouldn't be creating an error.Does it work if you do
createServer
again? If I'm honest, repeatedlisten
,close
,listen
isn't something I have tested, and it may be that it just doesn't work. Realistically though, usingcreateServer
again isn't actually very slow or wasteful, so it could be an idea. -
• #3
Hmmm...
I wonder, does it still work as a server after that error?
I never thought to check that - and yes it does work, the server is running again.
So what do you recommend doing about the error? Can I wrap it in a 'try' and then ignore it, or is it something you might look into fixing?The scenario I am wanting to handle it to have a web server running most of the time, but I periodically (every 10 minutes) want to make a client call as I'm using the reponse.headers.Date from a reliable, local source to reset the time on the Pico with a call to setTime() because I am normally loosing a second every minute on the built-in RTC. SO if you have another solution for that I'm all ears.
-
• #4
OK call me rash. It worked on one cycle:
listen -> request/response -> close -> get (client) -> listen -> request/response -> close -> get -> listen
and then the next request to the server didn't get a response from the server. -
• #5
Also tested issuing another
createServer()
and found that the next call tolisten()
produces the same error I reported in the OP. -
• #6
Which ESP8266 firmware do you have? 0.25?
It looks to me like the ESP8266 driver isn't actually closing the server when you say close... So it's possible the page is wrong and you actually can do TCP/IP requests while having a server. Might be worth a try?
But I'll have to fix the driver so that it properly closes the server. A hack for now would be (I think):
wifi.at.cmd("AT+CIPSERVER=0\r\n",1000,print);
-
• #7
Ok, I've just updated the drivers. Next time you click
send to espruino
in the Web IDE you'll be able to close and re-open the server exactly as you were doing. -
• #8
Yes, I'm using 0.25
Looks like you fixedESP8266WiFi_0v25
right under my feet. Its now working without errors and I can listen/close/get/listen/... repeatedly without issue. So thanks for that.If I don't close the server, I can't make a get(client) request. If I do I get the following error
ERROR: Socket error -1 while sending
I'll put this to the test over time and make a final post in a day or so to let you know that it is working reliably without any fringe conditions.
On the ESP8266 WIFI MODULE page at http://www.espruino.com/ESP8266 under the heading GOTCHAS, it is very clear
In my mind this hinges on the word "active".
So I've used http://www.espruino.com/Reference#t_l_httpSrv_close to close a running http server and can then do a client require("http").get(...) successfully.
However, when I try to restart the server using another http://www.espruino.com/Reference#t_l_httpSrv_listen
I get the following error:
Is there a way to restart the server or do I need to "createServer" again: seems wasteful?