You are reading a single comment by @Stevie and its replies. Click here to read the full conversation.
  • @Eric to get a server, you just replace the require("http").get(... line with require("http").createServer. There's an example here and a bit more info on the internet page.

    The actual code should look a bit like this though:

    var WIFI_NAME = "wifi_name";
    var WIFI_PASS = "wifi_key";
    
    function pageHandler(req, res) {
        res.writeHead(200);
        res.end("Hello World");
    }
    
    Serial2.setup(9600, { rx: A3, tx : A2 });
    var wifi = require("ESP8266WiFi").connect(Serial2, function(err) {
      if (err) throw err;
      wifi.reset(function(err) {
        if (err) throw err;
        console.log("Connecting to WiFi");
        wifi.connect(WIFI_NAME, WIFI_PASS, function(err) {
          if (err) throw err;
          console.log("Connected");
          // print IP address
          wifi.getIP(console.log);
          // Create a server
          require("http").createServer(pageHandler­).listen(80);
        });
      });
    });
    

    @Stevie, yes the ESP8266 is a little unreliable as a server at the moment (I'm surprised about the 300 requests for a client though - I've left one going for days without problems). I'm hoping I can do something in the driver to make the server more reliable - but it may be that I have to come up with a way to update the firmware on the ESP8266...

  • @Gordon, I have tested it with 3 different modules, always the same. I stripped down to pretty much the example code, still had that. But I heard the same also from others. It is sufficient to reset the ESP to "heal" the problem, so I am pretty sure it is not Espruino.

    +1 for a way to update the firmware!

About

Avatar for Stevie @Stevie started