• OK I was trying to keep the example super simple which is why I wasn't responding to the incoming http requests.

    Here is a more in-depth example that I can't get to work.

    Flow should be like this:

    1. Connect Espruino to real AP
    2. Espruino becomes an AP
    3. Espruino starts HTTP server
    4. Connect device to Espruino, browse to 192.168.4.1
    5. Espruino gets http request, then fetches an internet resource via the real AP.
    6. Espruino takes the response from the internet resource and sends it back to the device that made the http request.

      const wifi = require("EspruinoWiFi");
      const http = require('http');
      
      const startServer = () => {
      http.createServer(function (req, res) {
      console.log('got http request');
      console.log(req);
          
      if (req.url === '/') {
        res.writeHead(200);
      
        getPage((data) => {
          console.log('got http response');
          console.log(data);
          console.log('send http response back to requester');
          res.end(data);
        });
      }
          
      }).listen(80);
      console.log('http server started');
      };
      
      const getPage = (callback) => {
      console.log('get page');
        
      http.get("http://www.pur3.co.uk/hello.tx­t", function(res) {
      let data = '';
      console.log("Response: ", res);
          
      res.on('data', function(d) {
        data += d;
      });
          
      res.on('end', () => {
        console.log('get request ended');
        callback(data);
      });
      });
      };
      
      wifi.connect('realAP', {
      password: 'realPW'
      }, (err) => {
      if (err) { throw err; }
      console.log('wifi connected');
      wifi.startAP('ourAP', {
      password: 'ourPW',
      authMode: 'wpa2',
      }, (err) => {
      if (err) { throw err; }
      console.log('ap started');
      startServer();
      });
      });
      
About

Avatar for dave_irvine @dave_irvine started