Architecture: WiFi support for WiFi enabled boards ...

Posted on
Page
of 3
First Prev
/ 3
  • Some basic tests of the AP functionality. All fine for me.

    var wifi = require("Wifi");
    
    // Start AP
    wifi.startAP("My_AP", {password:"testing1"}, function(){
        console.log("Access Point created"); // Tested OK
        setTimeout(function(){
          // Stop AP
          wifi.stopAP(function(){
            console.log("Access Point stopped"); // Tested OK
          });
        }, 60000);
    });
    
    // Events
    wifi.on('sta_joined', function(params) {
      console.log("Event fired: sta_joined");
      console.log("Params:" + JSON.stringify(params)); // Tested OK
    });
    
    wifi.on('sta_left', function(params) {
      console.log("Event fired: sta_left");
      console.log("Params:" + JSON.stringify(params)); // Tested OK
    });
    

    I'm not sure I grasp the signifcance of the save() and restore() methods. Do these not overlap espruino save() and onInit() functions i.e the espruino program (which includes wifi configuration) must start at boot time for ESP8266 to do anything useful?

  • starting some tests, hit by this: cannot change the mode... stuck in mode = ap

    >var Wifi = require("Wifi");
    >Wifi.getStatus();
    ={
      "mode": "ap",
      "station": "off",
      "ap": "enabled",
      "phy": "11n",
      "powersave": "ps-poll",
      "savedMode": "off"
     }
    >Wifi.setConfig({mode : "sta+ap"});
    >Wifi.getStatus();
    ={
      "mode": "ap",
      "station": "off",
      "ap": "enabled",
      "phy": "11n",
      "powersave": "ps-poll",
      "savedMode": "off"
     }
    

    mode is changing when changing phy and powersave like this ?!

    >var Wifi = require("Wifi");
    >Wifi.setConfig( {phy : "11g",powersave : "none"} );
    >Wifi.getStatus();
    ={
      "mode": "sta+ap",
      "station": "off",
      "ap": "enabled",
      "phy": "11g",
      "powersave": "none",
      "savedMode": "off"
     }
    
  • got further, just connected and mode switches to "sta+ap"

    this works fine

    Wifi.getHostByName("bbc.co.uk", function(params){
    :      fn="Wifi.getHostByName()";
    :      console.log(fn+" params:" + JSON.stringify(params)); // Tested OK
    :    });
    =undefined
    Wifi.getHostByName() params:"212.58.244.22"
    

    and this dumps

    > Wifi.getHostByName("bbc.co.ukk", function(params){
    :      fn="Wifi.getHostByName()";
    :      console.log(fn+" params:" + JSON.stringify(params)); // Tested ERR
    :    });
    =undefined
    >
     ets Jan  8 2013,rst cause:1, boot mode:(3,7)
    load 0x40100000, len 1396, room 16
    tail 4
    chksum 0x89
    load 0x3ffe8000, len 776, room 4
    tail 4
    chksum 0xe8
    load 0x3ffe8308, len 540, room 4
    tail 8
    chksum 0xc0
    csum 0xc0
    2nd boot version : 1.4(b1)
      SPI Speed      : 80MHz
      SPI Mode       : QIO
      SPI Flash Size & Map: 32Mbit(512KB+512KB)
    jump to run user1 @ 1000
    
  • results of tests

    // tested //
    // ok Wifi.connect(ssid, options, callback)
    // ok Wifi.disconnect(callback)
    // ok Wifi.getAPDetails(callback)
    // ok Wifi.getAPIP(callback)
    // ok Wifi.getDetails(callback)
    // ok Wifi.getDHCPHostname(callback)
    // ok Wifi.getHostByName(hostname, callback)
    // ok Wifi.getIP(callback)
    // ok Wifi.getStatus(callback)
    // ok Wifi.scan(callback)
    // ok Wifi.setConfig(settings)
    // er Wifi.setDHCPHostname(hostname) if hostname is unknown
    // ok Wifi.startAP(ssid, options, callback)
    // ok Wifi.stopAP(callback)
    // ok event Wifi.auth_change(details)
    // ok event Wifi.associated(details)
    // ok event Wifi.connected(details)
    // ok event Wifi.disconnected(details)
    // ok event Wifi.sta_joined(details)
    // ok event Wifi.sta_left(details)
    // ok event Wifi.probe_recv(details)
    
    // open //
    // Wifi.restore()
    // Wifi.save(what)
    // event Wifi.dhcp_timeout() ? what fires that one ?
    
  • Wifi.setConfig({mode : "sta+ap"});

    setConfig does not take a "mode" param, and the docs are correct. But I can see how this is confusing to an esp8266 coder. the "opmode" is only changed indirectly by connect/scan/disconnect/startAP/stopAP.

    mode is changing when changing phy and powersave like this ?!

    Mhh, I'll have to look into this and see whether I can repro.
    Update: I cannot repro. Can you help me understand how you get there?

    and this dumps

    Ooops, not good. Looks like a WDT reset, so something must take too long... I'll have to try and repro...
    Update: repro is easy, bad DBG printout, and clearly a gap in the test coverage...

    Thanks much for testing!!!

  • I'm not sure I grasp the signifcance of the save() and restore() methods. Do these not overlap espruino save() and onInit() functions i.e the espruino program (which includes wifi configuration) must start at boot time for ESP8266 to do anything useful?

    The Wifi.save() method saves the Wifi config independent of any JS program that may or may not be loaded. I think you should move away from configuring the wifi in each program and instead configure it on each module once. This will become more useful when the IDE connects via wifi, at that point it's nice to have a stable connection whether you have a program loaded that works or not. Also, I want to add a "failsafe" mode to the Wifi that makes it turn on AP mode if it hasn't made a STA connection a minute after power-up. This way when you take your module to a different location it doesn't become unreachable.

  • @tve I like the idea : start "ap" when "sta" fails by default !

    ignore this, cannot produce anymore

    mode is changing when changing phy and powersave like this ?!

    what about

    // event Wifi.dhcp_timeout() ? what fires that one ?

    try to test save("clear") and restore()

    Wifi.save("clear");
    resert();
    ........
    var Wifi = require("Wifi");
    Wifi.restore();
    Wifi.getStatus();
    ={
      "mode": "off",
      "station": "off",
      "ap": "disabled",
      "phy": "11g",
      "powersave": "none",
      "savedMode": "off"
     }
    Wifi.getDetails();
    ={
      "status": "off",
      "ssid": "mySSID",
      "password": "myPassword",
      "savedSsid": null }
    >Wifi.getAPDetails();
    ={
      "status": "disabled",
      "authMode": "wpa2",
      "hidden": false, "maxConn": 4,
      "ssid": "ESP001",
      "password": "esp00001",
      "savedSsid": null }
    > 
    

    so it clears the overall wifi configuration and keeps station and access point configuration.
    Is that what you implemented for "clear" ?

  • Mhh, I think this is one thing I didn't test very well either. Doesn't lend itself to automated testing. Lemme look more tomorrow and make sure the docs state what it does.

  • FYI, I fixed all issues brought up above (except save()/restore()) except for the "ERROR: Not connected to the internet", which came up in gitter, where I know what the problem is but not how to fix it. I'll make a new build as soon as I find out from Gordon what to do.

  • New build ready: https://s3.voneicken.com/espruino/esprui­no_1v83.tve_fix-sockets_e62bff7_esp8266.­tgz
    Docs: http://s3.voneicken.com/espruino/functio­ns.html#t_Wifi
    Fixes all open Wifi library issues, except that getStatus() always reports savedMode: "off".
    This build attempts to fix sockets issues around closing&errors and now allows DNS names in connect call. I have only done minimal testing of the sockets stuff, so I'm sure there are issues there. I do not expect that this build is ready for prime time yet, but we are getting into the home stretch, I believe!

  • How do I teach the IDE that Wifi is a built-in module?

    It'll 'just happen' next time I update the website with a new release (it gets listed in the json/ESP8266_BOARD.json file on espruino.com).

    wrt callback parameters: It's a pretty standard JS/NodeJS thing to have:

    function (err, data) {
      if (err) {
        console.log("Oh no!");
        return;
      }
      // ...
    }
    

    It's not pretty, but it's what everyone does. It'd be nice to be able to keep that kind of thing wherever possible.

  • Did you have specific functions in mind WRT the error callback parameter?

  • Yet another new build: http://s3.voneicken.com/espruino/espruin­o_1v84.tve_master_e56e06c_esp8266.tgz
    Docs unchanged: http://s3.voneicken.com/espruino/functio­ns.html#t_Wifi

    This build improves socket error handling and adds flow control so large amounts of incoming data don't cause out of memory errors.
    The issue with Wifi.getStatus() always reporting savedMode: "off" is not yet fixed.
    Due to an Espressif SDK memory corruption bug I spent more time tracking down that bug and less testing the new build :-(.

  • I guess things like getAPIP, getIP, getHostByName.

    So they could all return null/undefined on error - maybe that's good enough? But if you want to return an error message then there really needs to be another way of doing it - and the way most NodeJS things do it (for better or worse) is function(err, data)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Architecture: WiFi support for WiFi enabled boards ...

Posted by Avatar for Kolban @Kolban

Actions