Gateway and dynamic wifi configuration



  • Hello,

    I'm looking for an implementation of gateway based with esp8266 with a possibility to change SSID/password by web page and not static configuration as mysensors examples.
    What is your solution ?

    I'm trying wifimanager library but i have some difficulties about MY_WIFI_SSID and MY_WIFI_PASSWORD used by Mysensors but not wifimanager. Is it possible to use wifimanager with mysensors ?

    Tristan



  • Preprocessor directives like MY_WIFI_SSID are expanded before the code is compiled and cannot be changed at runtime. But you can replace the string literal with a variable:

    char dynamic_ssid[16] = "ssid";
    char dynamic_pw[16] = "123456";
    
    #define MY_WIFI_SSID dynamic_ssid
    #define MY_WIFI_PASSWORD dynamic_pw
    

    What you could do now, is storing the new value for SSID and PW somewhere in the flash memory of the ESP when you change it (with wifimanager or whatever you may use for this purpose) and initiate a reboot of the ESP.

    Then you could read the values from flash into the two char arrays. You'd want to do this in before(), so that MY_WIFI_SSID and MY_WIFI_PASSWORD represent the new values before MySensors initializes the WiFi connection.

    void before() 
    {
        // Read SSID and PW from flash and
        // assign to dynamic_ssid and dynamic_pw
    }
    

    In this case MySensors would always try to establish a WiFi connection with the login data you've stored in flash when the gateway boots up.


    Addendum: There are some threads with similar ideas from a few years ago here and here.

    Also, rebooting the ESP as mentioned above isn't neccessary. It's sufficient to call WiFi.disconnect() and WiFi.begin() with the new login data to connect to a different network.

    Another approach to this could be to send new login data to some V_TEXT childs from a controller to the gateway.

    There is also this project which seems to provide a custom web interface to configure WiFi and MQTT connections.



  • Thanks for your explanation and links 🙂


Log in to reply
 

Suggested Topics

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts