• Problem identified

    the res.on('drain') is slow to trigger.
    Hypothesis Somewhere in the firmware is a setInterval that is used to test if the drain buffer is empty. Without delving into the source code, there seems to be an issue with the frequency that the drain empty condition is tested and an emit to the ondrain is issued.
    The Aruduino code runs faster because the drain empty condition is recognised immediately

    The following code was executed on a Pico connected via serial port to an Esp8266 at 115 Kbaud. It uses a setTimeout function to issue emit commands at a higher rate. It doesn't test for the amount of data in the drain buffer and thus is an incomplete fix.

    var n = 4, chk=5*1024;
    var tdata=new Uint8Array(chk);
    var i;
    for(i=0;i<1024;i++){
      tdata[i]=0x30;
      tdata[i+1024]=0x31;
      tdata[i+1024*2]=0x32;
      tdata[i+1024*3]=0x33;
      tdata[i+1024*4]=0x34;
    }//next i
    
    function onPageRequest(req, res) {
     res.writeHead(200, {'Content-Type': 'text/plain'});
     var t=getTime();
     res.on('drain',function() {
      print("n=",n,"t:",(getTime()-t).toFixed(3),"sec");
      if (n===0){ res.end();
       print("n=",n,"t:",(getTime()-t).toFixed(3),"sec");
      }else {  
       res.write(E.toString(tdata));  
        n--;
       setTimeout(function () {
    //    console.log("Hello World");
        res.emit('drain');
       }, 400);
        }//end else
      });//end opr
     }//end function
    
    1v95 Copyright 2017 G.Williams
    >2
    Start connection process
    end require
    =undefined
    Reset the ESP8266
    end reset
    Test for error
    Try Connecting to WiFi  faux
    end connect
    Test for error
    Test for error
    Test for error
    null
    end getIP
    IP=  192.168.1.9
    null
    Wi-Fi Connected
    n= 4 t: 0.008 sec
    n= 3 t: 0.443 sec
    n= 2 t: 0.883 sec
    n= 1 t: 1.305 sec
    n= 0 t: 1.742 sec
    n= 0 t: 1.743 sec
    n= 0 t: 0.008 sec
    n= 0 t: 0.009 sec
    

    @Gordon any comments on the hypothesis?

    @Polypod please give it a try on your Esp8266 with flashed Espruino and see if you can get similar results.

    I just saw your latest post about the Arduino using Websockets and not HTML. My limited experience with websockets left me with the impression that they are much faster than using HTML.

About