• In the case of two WiFi modules together, the http lib definitely doesn't know which one to use - it's not designed to handle that at all.

    However when you have AP and client on the same ESP8266 it's different, since the ESP8266 doesn't differentiate between connections.

    For starters, you're never sending any HTTP response for the server, so every request gets left open and it's hardly surprising you have issues.

    The simple HTTP server example from the Internet page works fine:

    const startServer = () => {
      http.createServer(function (req, res) {
        res.writeHead(200);
        res.end("Hello World");
      }).listen(80);
      console.log('http server started');
    };
    

    And even after sending a response, your code appears to work for me:

    const startServer = () => {
      http.createServer(function (req, res) {
        console.log('got http request');
        console.log(req);
        res.end("Hello world");
        getPage((data) => {
          console.log('got http response');
          console.log(data);
        });
      }).listen(80);
      console.log('http server started');
    };
    

    Although occasionally I don't get a response, but then I do have WiFi that keeps dropping out here.

    Also worth noting that const and let act just like var in Espruino, so may not work as you expect. They're not part of ES5, but I've had to put placeholders in because everyone kept using them :)

About

Avatar for Gordon @Gordon started