• 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):

    >process.version
    ="1v99"
    >process.env
    ={
      "VERSION": "1v99",
      "GIT_COMMIT": "f0d66ba",
      "BOARD": "ESP32",
      "FLASH": 0, "RAM": 524288,
      "SERIAL": "30aea40f-0074",
      "CONSOLE": "Telnet",
      "MODULES": "Flash,Storage,fs," ... "r,crypto,neopixel",
      "EXPTR": 1073485304 }
    
    

    First time I upload and try to fire up the server, it works. The second time:

    ERROR: Socket bind failed
    Uncaught InternalError: Unable to create socket
     at line 11 col 60
    ...(onPageRequest).listen(7348);
    

    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=test­pass

    Upload code again. Watch for error in console.

    var http = require("http");
    
    
    
    function startup() {
    	E.setTimeZone(-5);
    	fetchTime();
        require("http").createServer(onPageReque­st).listen(7348);
    }
    
    function fetchTime() {
    	require("http").get("http://drazzy.com/t­ime.shtml", function(res) {
      		var contents = "";
      		res.on('data', function(data) { contents += data; });
      		res.on('close', function() { setTime(contents); });
    	}).on('error', function(e) {
      		console.log("ERROR", e);
    	});
    }
    
    var CORS={'Access-Control-Allow-Origin':'*'}­;
    // Network
    
    function onPageRequest(req, res) {
      var a = url.parse(req.url, true);
      var resu=0;
      if (a.pathname=="/favicon.ico") {
        resu=404;
      } else {
        resu = handleCmd(a.pathname,a.query,res);
      }
      if (resu > 0) {
      	  res.writeHead(resu,CORS);
      	  if (resu==200) {res.write('{"error":false,"code":200,"t­ext":"OK"}');}
      	  else if (resu==404) {res.write('{"error":true,"code":404,"te­xt":"Not Found"}');}
      	  else if (resu==403) {res.write('{"error":true,"code":403,"te­xt":"Unauthorized Client"}');}
      	  else if (resu==400) {res.write('{"error":true,"code":400,"te­xt":"Bad Request"}');}
      } else if (resu===0) {
      	  res.writeHead(500,CORS);
      	  res.write('{"error":true,"code":500,"tex­t":"Unknown Error"}');
      }
      res.end();
    }
    
    
    function handleCmd(path,query,res) {
    	console.log(path);
    	console.log(query);
    	if (query.un!="testuser" || query.pw!="testpass") { 
    		return 403;
    	}
    	if (path=="/status") {
    		res.writeHead(200,CORS);
    		res.write(JSON.stringify(cs));
            return -1;
    	} else {
    		return 404;
    	}
    }
    
    var cs={ //cs=Current State
    	DoorUp:0,
    	DoorDown:0,
    	Fridge:0,
    	Humidity:null,
    	Temperature:null,
    	Pressure:null,
    	Light:null
    };
    cs.Fargo=new Uint8Array(8);
    
    function onInit() {
    	setTimeout("startup()",5000);
    }
    onInit();
    

    Powercycling the board fixes it.

    Also, sometimes when I click send to Espruino, the following is printed to console:

    
    >WARNING: --- gap_setScan 0
    WARNING: Scan stop failed
    WARNING: set rssi scan not implemeted yet
    WARNING: has central connection not implemented yet
    

    Much thanks to everyone for all the work they've put into the ESP32 support.

About

Avatar for DrAzzy @DrAzzy started