• Mon 2017.02.13

    What is the suggested best practices methodology to detect and configure the Wifi settings for a new module that has yet to connect to a local LAN using only a browser?

    I've run into a snafu attempting to connect an IoT device to the LAN using only the browser. The Espruino examples hard code the ssid and password

    1. espruino.com/ESP8266_Flashing­#initial-flashing-on-windows
    2. espruino.com/wifi_humidity
    3. github.com/MaBecker/esp8266/blob­/master/Espruino/JoinWifi.js

    [ Credit @MaBe #3 web page to connect to an access point source code used as a framework for this discussion ]

    into the existing code, use wifi.save(), which works great if you are the developer and know your way around known equipment.

    But, what if you want to take your really cool IoT bot device to another location to show off? The risk exists that the I.P. addr may conflict with an existing device on the new LAN as usually I.P. addresses are dynmically assigned in order from a known range. e.g. 192.168.1.x ( where on my router, 0 <= x < 64 and can be statically assigned 64 <= x <= 253 ) We also wont have access to the WebIDE and likely can only interact with our device using the browser on our tablet/phone.

    My router seems to always assign the same I.P. address as it doesn't appear to have a feature to remove an assigned entry once the IoT device connects, even after I restart the IoT device w/o a un and p/w.

    Ideally, one would want to load up a browser and type in an address to reconfigure it. The Catch-22 how do you connect to that device from a browser, when the local router will attempt to (re-)assign the next I.P. in it's list, not the one our IoT device now has hard coded. More interesting is what occurs if our IoT device has a low I.P. value which likely is a conflict in the new environment.

    Using 192.168.1.254 from the browser allows (Windows 10 and U-Verse gateway-router) access to the router settings and does show the I.P. address of the new device once it has been detected.

    The big question:

    But how does one start a configuration exchange with a device when the I.P. can't be known until after the router assigns it, after detection?

    Since we wont know what the new I.P. address is, we wont be able to type an address in the browser address bar, something like 192.168.1.55 to fetch a login page hard coded into our IoT device running as a server.

    The Wifi class doesn't appear to have a clear function class Wifi

    and setIP() will only allow valid I.P. from within the router assigned range (can't use 0.0.0.0) - the Catch-22 how to preload an I.P. addr for a module that will get assigned a unique new value as it is detected.

    Since the we want the user to open a browser and enter that I.P. address in order to interact with the module, how does one detect that unknown state/value in code, the very first time, so as to allow a connect and wifi.save() ?

    Could it be as simple as creating a known name and assign it using wifi.setDHCPHostname() but how does one start a session from the browser without it's I.P. address?

    Trying to make this opaque and easy for bewildered end users without the headache(s) that seem to go along with auto detection. Short of reflashing the chip (which we don't want our users to perform) mine won't forget it's assigned I.P. even after playing with wifi.setDHCPHostname() Within the router range, 192.168.1.254 wont allow me to re-assign a new I.P. and forget the original detected I.P. address. Perplexing.

  • Someone was attempting it on here. The approach seemed to be to run the ESP8266 as an Access Point and Station (the default).

    In AP mode the IP address is a known 192.168.4.1.

    A simple webserver hosts a form to accept SSID and password credentials, which can be used as an input to connect to the main Wifi network as a station, if I can find the thread I'll update here.

    Edit: Nothing jumps out in the forum, it might have been a discussion on gitter. But that was the approach taken

  • Thanks @Ollie,

    The key phrase was 'AP Mode' and the default addr of 192.168.4.1

    Was the example you may have seen, the one that MaBe posted at Github, the link in #3 above?

    or . . . . as Google turned up, was this the forum post: AP mode, webserver redirect?

    Still looking for a good networking explanation or wikipedia article . . . .

  • There is another way of doing this.....
    You can fire up a hotspot on your phone.... and get the esp8266 to connect to your phone..

    From there you could have a page that then asks for ssid and password you want to join...

    The set up a setwatch on the flash button, so if that is pressed, it
    Changes the network back to you phone ssid, so this way you can switch between the two networks.

    You could even set up a timeout instead of getting triggered by a button. If the last saved network is not found within say 30 secs, reconnect to your phone hotspot.

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

Catch-22 on IoT Wifi LAN I.P. addr detection best practices

Posted by Avatar for Robin @Robin

Actions