Setting static IP before connecting?

Posted on
  • So I found this threat where wifi.setIP() was implemented to set a static IP for an ESP8266. These docs mention "You must be connected to an access point to be able to call this successfully". I thought I misinterpreted it, because: why setting a static IP once connected? Turns out the documentation is right: calling wifi.setIP() before connecting to wifi, does nothing. Calling it once connected actually changes the IP-address.

    I want to get rid of DHCP in the first place. I'm building a battery-fed deep sleep project. DHCP is terribly slow and takes around 4 seconds (which is 40% of the total time needed for measuring and transmitting the results).

    Any thoughts on this?

  • Reference http://www.espruino.com/Reference#l_Wifi­_connect mentions that options will have a way to pass expected ip address to use rather than dhcp... but as said: will - as future enhancement.

    On the other hand, your access point may have the option to not do dhcp at all or for not for particular MAC addresses and define the repsective ip to use. May be you can control it there.

  • DHCP is terribly slow and takes around 4 seconds

    No, scan and connect to access point is the time consumer, not DHCP.

    Using channel and bssid in Wifi.connect() speeds this up to one sec,
    watch issue #1640 and
    #1595.

  • @allObjects Thanks for the intel on possible future enhancements ;) I doubt though if setting a static IP on the AP-side will speed up things. It doesn't change the DHCP-negotiation as such, as far as I know, but just returns the same IP all of the time.

    Thanks @MaBe, I'll look into it! Unfortunately, my AP automatically jumps channels, depending on other network signals. So using a particular channel won't work. The BSSID sounds promising though (or would this only help in a situation with multiple AP's sharing one SSID?).

  • The bssid is the kicker, as far as I understand.

    @Thijsmans: If you like I can share my latest build which include this fixes via github , just let me know, so another person can run some test with it - what do you think?

  • Would love to test, but I can't compile it myself because of a lack of skills ;-)

  • choose the last travis build it is merged

  • Benchmarked and... well done MaBe :)

    A full report can be found @ my Tweakblog, which is dutch but translate pretty accurate using Google.

  • thanks for testing and posting your results.

  • @Thijsmans: Either there was a huge improvement in espruino (2v03), or your WIFI AP and DHCP server are both slow. For me using DHCP the connection is usually up in 2.18 seconds. I tested also with channel and bssid, but this didn't change anything for me.

    My code:

    var wifi = require("Wifi");
    var test = function() {
    wifi.disconnect();
    var startTime = getTime();
    wifi.connect(wifi.getDetails().ssid,{pas­sword: wifi.getDetails().password},
      function(err) {
        var endTime = getTime();
        var duration =  endTime - startTime;    
              if (err) {
                console.log('Wifi setup error, duration/s=' + duration );
              } else {
                console.log('Wifi connection is up, duration/s=' + duration );
              }
    });
    }
    
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Setting static IP before connecting?

Posted by Avatar for Thijsmans @Thijsmans

Actions