You are reading a single comment by @ClearMemory041063 and its replies. Click here to read the full conversation.
  • The example above is on a Pico.
    It is an attempt to zero in on the bug first found in the following code.

    For the ESP8266 -01 try this code

    //WSDesp8266A/js 27Jan2018
    // using process.memory to fix bug
    
    //http//192.168.1.6:8080
    //ESP8266 with Espruino flahed
    
    
    // list of Wifi and passwords
    var SSID="ssid";
    var key="keykey";
    var Startagain=0;
    var myinterval;
    
    var n =100, chk=2*1024;
    var tdata=new Uint8Array(chk);
    var i;
    for(i=0;i<1024;i++){
      tdata[i]=0x30;
      tdata[i+1024]=0x31;
    }//next i
    
    var page = 
    "<html>\r\n<body>\r\n<textarea id=\"demo\" rows=\"32\" cols=\"64\"></textarea>\r\n<script>\r\nvar ws;\r\nvar data=\"\";\r\n//setTimeout(function(){\r\nws = new WebSocket(\"ws://\" + location.host + \"/my_websocket\", \"protocolOne\");\r\nws.onmessage = function (event) { \r\ndata+=event.data;\r\ndocument.getElementById(\"demo\").innerHTML = data.length;\r\nws.send(\"Hello to Espruino!\"); \r\n };\r\n//setTimeout(function() { ws.send(\"Hello to Espruino!\"); }, //1000);}\r\n//,1000);\r\n\r\n</script></body>\r\n</html>\r\n"
    ;
    function onPageRequest(req, res) {
      res.writeHead(200, {'Content-Type': 'text/html'});
      res.end(page);
    }
    
    function test(){
    
    console.log("Start connection process");
    var wifi = require("Wifi");
     console.log("Try Connecting to WiFi ",SSID);
     wifi.connect(SSID,{password:key}, function(err) {
      console.log(err);
       if (err){Startagain=1;return;
    }
     console.log("connected? err=", err, "info=", wifi.getIP());
         console.log("Wi-Fi Connected");
         clearInterval( myinterval);
         var t=getTime();
    var server = require('ws').createServer(onPageRequest);
    server.listen(8080);
    server.on("websocket", function(ws) {
        ws.on('message',function(msg) {
        n--;
      print("n=",n,"t:",(getTime()-t).toFixed(3),"sec");
          print("[WS] "+JSON.stringify(msg));
          if(n){
            ws.send(E.toString(tdata));
            process.memory();
          }
        });
      t=getTime();
      ws.send(E.toString(tdata));
      process.memory();
      print("n=",n,"t:",(getTime()-t).toFixed(3),"sec");
    });
     });//end connect
    }//end test
    
    myinterval=setInterval(function () {
      console.log("Test for error");
      if(Startagain){
       Startagain=0;
       test();
      }//end of Startagain
    }, 2000);
    
    test();
    
    
About