You are reading a single comment by @samppa and its replies. Click here to read the full conversation.
  • Ok got it working with:

    var WIFI_NAME = "ssid";
    var WIFI_OPTIONS = { password : "pw" };
    var wifi = require("EspruinoWiFi");
    wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) { ...
    

    But the behavior is the same as with separate ESP8266 module: HTTP request is well received and handled by this code, but response does not arrive to browser when making the request:

    var wifi = require("EspruinoWiFi");
    wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) {
      if (err) {
        console.log("ERROR connect:"); 
        console.log(err);
        wifi.stopAP();
      } else {
        console.log("Connected");
        wifi.getIP(function (err, ip) {
          if (err) { console.log("ERROR getIP():"); console.log(err); return; }
          console.log("Web server ip: " + ip.ip);
          var http = require("http");
          http.createServer( function(req, res) {
            console.log("Client req: " + req.url);
            if (req.url == "/favicon.ico") {
              res.writeHead(200, {'Content-Type': 'image/x-icon'});
              res.write(favicon);
              console.log("Client served with favicon.ico");
            } else {
              res.writeHead(200, {'Content-Type': 'application/json', 'Connection': 'close'});
              var values = "\nsensors(["+
                  "{\"sensor\":\"A0\",\"value\":\""+analogRead(A0)+"\"},"+
                  "{\"sensor\":\"A1\",\"value\":\""+analogRead(A1)+"\"},"+
                  "{\"sensor\":\"A2\",\"value\":\""+analogRead(A2)+"\"},"+
                  "{\"sensor\":\"A3\",\"value\":\""+analogRead(A3)+"\"},"+
                  "{\"sensor\":\"A4\",\"value\":\""+analogRead(A4)+"\"},"+
                  "{\"sensor\":\"A5\",\"value\":\""+analogRead(A5)+"\"}])";
              res.write(values); 
              console.log("Client served with: " + values);
            }
            res.end(); 
          }).listen(80);
        });
      }
    });
    
    

    Console says "Client served with: ...", but that response never arrives to chrome browser that I am testing with.

    What is wrong with the code above or the setup (EspruinoWifi plugged into laptop USB)?

About

Avatar for samppa @samppa started