• Oh Gordon you genius!

    Flow control works, you just have to reconfigure the UART to enable it.

    AT+UART=<baudrate>,<databits>,<stopbits>,<parity>,<flow control>

    : flow control
    ‣ 0: flow control is not enabled
    ‣ 1: enable RTS
    ‣ 2: enable CTS
    ‣ 3: enable both RTS and CTS

    not sure what RTS is, but CTS works fine.

    Also, looks like we now have the baud range that ESP8266 supports:

    The range of baud rates supported: 110~115200*40.

    From my reading I think the *40 has something to do with the clock speed of the serial line?

    Because 115200*40 is 4608000, and that is the baud rate I set that got me into my very nasty mess of needing to reflash the ESP8266. I'm guessing the Espruino just can't go that high.

    var wifi = require("EspruinoWiFi");
    var http = require('http');
    var indexOK = "<html><head><link rel='stylesheet' href='1'><link rel='stylesheet' href='2'></head><body>OK!</body></html>";
    var indexBAD = "<html><head><link rel='stylesheet' href='1'><link rel='stylesheet' href='2'><link rel='stylesheet' href='3'></head><body>NOT OK!</body></html>";
    var indexVERYBAD = "<html><head><link rel='stylesheet' href='1'><link rel='stylesheet' href='2'><link rel='stylesheet' href='3'><link rel='stylesheet' href='4'></head><body>NOT OK!</body></html>";
    
    function generateJunk(length) {
      var text = "";
      var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    
      for(var i = 0; i < length; i++) {
        text += possible.charAt(Math.floor(Math.random() * possible.length));
      }
    
      return text;
    }
    
    function handleHTTPRequest(req, res) {
      //Flow control close
      digitalWrite(A15,1);
      switch (req.url) {
          case '/':
            res.writeHead(200, {
              "Content-Type": "text/html",
            });
    //        res.end(indexOK);
            res.end(indexVERYBAD);
            break;
          default:
          // Generate some CPU load
          
            var junk = generateJunk(1024);
            //console.log(process.memory());
            res.writeHead(200, {
              "Content-Type": "text/css",
            });
            res.end(junk);
        }
      //flow control open
      digitalWrite(A15,0);
    }
    
    
    wifi.startAP('test', {
      password: 'mytestap123',
      authMode: 'wpa2',
    }, function(err) {
      if (err) { throw err; }
    
      var at = wifi.at;
    
      at.cmd('AT+UART_CUR=115200,8,1,0,2\r\n', 10000, function (data) {
        if (data === 'OK') {
          // Flow control open
          digitalWrite(A15,0);
          // Reconfigure serial 
          Serial2.setup(115200, { rx: A3, tx : A2 });
    
          //Flush anything in at's buffer
          at.cmd('AT\r\n', 1000, function(data) {
            console.log(data);
            console.log('http server started');
            http.createServer(handleHTTPRequest).listen(80);
          });
        }
      });
    });
    
About

Avatar for dave_irvine @dave_irvine started