-
• #2
The issue is the the build is compiled with 10 sockets.
When you reset, the sockets are not closed. Part of the reason for this, is one of the sockets was the telnet server socket - you would loose your connection to the board.If you saved the result of you your server connect as a global:
var server=require("http").createServer(onPageRequest).listen(7348);
Then before the reset - you could do
server.close()
This will shut down the connect and close the socket.
By the way, are using using a telnet connection? It is so much faster than the com port connection.
Oh - and your call to get the time - rather than have a page that returns the time - you can get the time out of the header..
-
• #3
When you reset, the sockets are not closed.
Something seems odd there - if you call
reset()
it should calljswrap_net_kill
which should shut all the open sockets (except the Telnet one, because it's handled separately). It works on ESP8266, so I think something might be broken on the ESP32 port. -
• #4
Following the calls from
jswrap_net_kill
it ends up here in the ESP32 case - so it has been implemented, so I think something else is going on.I have also observed this behaviour in the ESP8266 build.
-
• #5
Hmm, yeah - it seems like something that would be good to fix, since it is a nuisance during development to have to power cycle the board after each upload.
I will try manually doing server.close()
I am using the telnet connection - I think this is one of the most compelling features of the ESP8266/ESP32. It's so much more convenient than having to fiddle with wires to upload.
For doing the time with the header, how do I access the headers from within Espruino? It doesn't appear to be supported (based on my reading of the reference) As I understand it, the callbacks provide an httpCRs and httpCRq object - but the API reference for these does not mention any method to get the headers.
-
• #6
I think
httpCRq
has aheaders
field on it? -
• #7
> require("http").get("http://drazzy.com/time.shtml", function(res) { console.log({GMT:res.headers.Date}); var contents = ""; res.on('data', function(data) { contents += data; }); res.on('close', function() { console.log(contents); setTime(contents); }); }).on('error', function(e) { : console.log("ERROR", e); : }); =undefined { "GMT": "Wed, 13 Jun 2018 11:22:54 GMT" } Wed Jun 13 11:22:54 2018
-
• #8
Thanks.
I've created an issue for the incomplete API documentation. https://github.com/espruino/EspruinoDocs/issues/441
-
• #9
@DrAzzy
The initial problem you had should be largely sorted by this fix:https://github.com/espruino/Espruino/commit/5c9c7b5c561eda7408b2e5d8194f8127a6a5d5f6
It allows the port to be reused.
-
• #10
I think I got this issue on an ESP32 with 2v01 when trying to use MQTT / tinyMQTT.
reset(1)
, reset button, power cycling does not solve the problem. The board can connect to wifi, ping works.
What really puzzles me is that I have an ESP32 with tinyMQTT that works.With MQTT the error message is
ERROR: Connect failed (err 104)
With tinyMQTT the error message is:ERROR: Connect failed (err 104) Uncaught InternalError: Unable to create socket
at this call:
a.cl=require("net").connect({host:a.svr,port:a.prt},b)
Edit: A simple http get does work.
Edit2: A simple http server works:function onPageRequest(req, res) { print('page req', req); res.writeHead(200); res.end("Ok."); } require("http").createServer(onPageRequest).listen(80);
It looks like there's a problem with servers not getting cleaned up when the board is reset (for example, when you click "send to Espruino" in the IDE):
First time I upload and try to fire up the server, it works. The second time:
It isn't clear to me yet exactly what the key factor is that makes this fail, but the code below readily reproduces it for me. Upload code once.
Request in browser:
(board IP address):7348/status?un=testuser&pw=testpass
Upload code again. Watch for error in console.
Powercycling the board fixes it.
Also, sometimes when I click send to Espruino, the following is printed to console:
Much thanks to everyone for all the work they've put into the ESP32 support.