Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. ESP8266 WiFi settings in EEPROM

ESP8266 WiFi settings in EEPROM

Scheduled Pinned Locked Moved Development
wifieepromesp8266
12 Posts 3 Posters 18.5k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • hekH hek

    If you have some idea how to solve it, please submit a PR.

    A Offline
    A Offline
    Alexander Voronin
    wrote on last edited by
    #3

    @hek This is my first try with MySensors, so just thinking of loud:

    One way: Globally redesign internal initialization sequence and add extra EEPROM arguments. Also provide function to write new SSID/password to EEPROM and reboot. Read SSID/IP/password/etc from config in TransportXXX

    Another way: Be more Arduin-ish. All standard Arduino classes have function begin or/and class initializer. So I want to call for example mySensors.begin() for basic init, and some kind of mySensorsTransportXXXBegin(ssid, password, ip, topic, etc) for specific transport init. As an option should be flag like "already connected" or "do not reconnect" for WiFi

    As for me, the second way is preferred. If I decide to make my next sensor on MySensors instead of "pure" C/Arduino, I'll refactor at least MyMainESP8266.c:loop_wrapper by removing setup call and adding separate public _begin() alternative

    YveauxY 1 Reply Last reply
    1
    • A Alexander Voronin

      @hek This is my first try with MySensors, so just thinking of loud:

      One way: Globally redesign internal initialization sequence and add extra EEPROM arguments. Also provide function to write new SSID/password to EEPROM and reboot. Read SSID/IP/password/etc from config in TransportXXX

      Another way: Be more Arduin-ish. All standard Arduino classes have function begin or/and class initializer. So I want to call for example mySensors.begin() for basic init, and some kind of mySensorsTransportXXXBegin(ssid, password, ip, topic, etc) for specific transport init. As an option should be flag like "already connected" or "do not reconnect" for WiFi

      As for me, the second way is preferred. If I decide to make my next sensor on MySensors instead of "pure" C/Arduino, I'll refactor at least MyMainESP8266.c:loop_wrapper by removing setup call and adding separate public _begin() alternative

      YveauxY Offline
      YveauxY Offline
      Yveaux
      Mod
      wrote on last edited by Yveaux
      #4

      @Alexander-Voronin I recently found out that the ESP will always store the last access point & password it connected to in flash anyway, so just connecting once with new settings should be sufficient (does however need modifications to MySensors library to not pass this stuff on connect)
      Maybe the same holds for IP address etc.

      http://yveaux.blogspot.nl

      A 1 Reply Last reply
      1
      • YveauxY Yveaux

        @Alexander-Voronin I recently found out that the ESP will always store the last access point & password it connected to in flash anyway, so just connecting once with new settings should be sufficient (does however need modifications to MySensors library to not pass this stuff on connect)
        Maybe the same holds for IP address etc.

        A Offline
        A Offline
        Alexander Voronin
        wrote on last edited by
        #5

        @Yveaux This is slightly not my case. The ESP stores only SSID/Password, but I want to store extra config for at least MQTT broker.

        The main issue is that WiFi.begin() and awaiting for WiFi.state == WL_CONNECTED logic executed before setup() so I can not invoke web-config or change hardcoded AP name. In my previous "pure" arduino sensor (https://bitbucket.org/esp8266/sensor-v2) I use WiFiMulti to connect first available pre-configured AP's, so I need at least two AP/password settings (for example home and work wifi)

        BTW, de-facto MySensors internally "ignores" last saved AP because calls begin(SSID, PWD) in MyGatewayTransportXXX.cpp but it is good idea as for me. As an option - do not call WiFi.begin() if wifi state already "connected" but required some functionality to force reconnect to /other/ AP

        So I need 4 steps:

        1. Try connect to saved AP (may be more than one)
        2. If not success, bring up softAP and Web/Telnet configurator
        3. Reconnect to new configured AP or reboot an goto step 1
        4. Start MySensors with already connected WiFi and new SSID
        1 Reply Last reply
        0
        • hekH Offline
          hekH Offline
          hek
          Admin
          wrote on last edited by
          #6

          There's a new
          before()
          you can add to init stuff before the library.

          Example:
          https://github.com/mysensors/Arduino/blob/469cbb7d0ccd4698079a44e8632f660fbe50cf18/libraries/MySensors/examples/RelayActuator/RelayActuator.ino#L49-L56

          A 1 Reply Last reply
          0
          • hekH hek

            There's a new
            before()
            you can add to init stuff before the library.

            Example:
            https://github.com/mysensors/Arduino/blob/469cbb7d0ccd4698079a44e8632f660fbe50cf18/libraries/MySensors/examples/RelayActuator/RelayActuator.ino#L49-L56

            A Offline
            A Offline
            Alexander Voronin
            wrote on last edited by
            #7

            @hek Thanks! Looks promising. I''ll try it.

            This may solve an issue with AP (compiled ok but untested char[] as MY_ESP8266_SSID) but not for MQTT transport - a lot of PSTR(MY_MQTT_XXX) "/+/+/+" code required refactoring to be used with at least const char*

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Alexander Voronin
              wrote on last edited by
              #8

              OK!
              All, except MY_MQTT_xxx_TOPIC_PREFIX can be used as variables:

              char ssid[32] = "MyAP";
              char pwd[32] = "MyPass";
              word mqttPort = 1883;
              char mqttHost[64] = "my.mqtt.example.com";
              
              #define MY_GATEWAY_ESP8266
              #define MY_GATEWAY_MQTT_CLIENT
              #define MY_ESP8266_SSID (ssid)
              #define MY_ESP8266_PASSWORD (pwd)
              
              #define MY_PORT (mqttPort)
              #define MY_CONTROLLER_URL_ADDRESS (mqttHost)
              #define MY_MQTT_CLIENT_ID  (String("MyS_") + String(ESP.getChipId(), HEX)).c_str()
              
              // DOES NOT SUPPORT VARS:
              #define MY_MQTT_PUBLISH_TOPIC_PREFIX "/MySe/00/out"
              #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "/MySe/00/in"
              
              #include <MySensor.h>
              
              void before() {
                // read config into local vars, e.g. from FS via json
                strncpy(ssid, "AltSSID", sizeof(ssid)); // example
              }
              
              void setup() {
              }
              
              void loop() {
              }
              

              FYI, The wifi manager from first post is not so useful here for me - on first look there is some issues with dhcp vs static ip, so I'll try to find another solution or write my own :)

              YveauxY 1 Reply Last reply
              0
              • A Alexander Voronin

                OK!
                All, except MY_MQTT_xxx_TOPIC_PREFIX can be used as variables:

                char ssid[32] = "MyAP";
                char pwd[32] = "MyPass";
                word mqttPort = 1883;
                char mqttHost[64] = "my.mqtt.example.com";
                
                #define MY_GATEWAY_ESP8266
                #define MY_GATEWAY_MQTT_CLIENT
                #define MY_ESP8266_SSID (ssid)
                #define MY_ESP8266_PASSWORD (pwd)
                
                #define MY_PORT (mqttPort)
                #define MY_CONTROLLER_URL_ADDRESS (mqttHost)
                #define MY_MQTT_CLIENT_ID  (String("MyS_") + String(ESP.getChipId(), HEX)).c_str()
                
                // DOES NOT SUPPORT VARS:
                #define MY_MQTT_PUBLISH_TOPIC_PREFIX "/MySe/00/out"
                #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "/MySe/00/in"
                
                #include <MySensor.h>
                
                void before() {
                  // read config into local vars, e.g. from FS via json
                  strncpy(ssid, "AltSSID", sizeof(ssid)); // example
                }
                
                void setup() {
                }
                
                void loop() {
                }
                

                FYI, The wifi manager from first post is not so useful here for me - on first look there is some issues with dhcp vs static ip, so I'll try to find another solution or write my own :)

                YveauxY Offline
                YveauxY Offline
                Yveaux
                Mod
                wrote on last edited by
                #9

                @Alexander-Voronin Great to hear your issue is solved, but this solution will permanently claim 128 of the scarce ATMega RAM...

                http://yveaux.blogspot.nl

                A YveauxY 2 Replies Last reply
                0
                • YveauxY Yveaux

                  @Alexander-Voronin Great to hear your issue is solved, but this solution will permanently claim 128 of the scarce ATMega RAM...

                  A Offline
                  A Offline
                  Alexander Voronin
                  wrote on last edited by
                  #10

                  @Yveaux Not all but enough. Hmm how do you plan to use mqtt with wifi with ATMega? ;) IMHO it is not so good :)

                  So this solution is for somebody, who need dynamic reconfiguration of system settings. Remember, that char[] sizes just example and may be reduced or changed to String(...).c_str(). But I don't know arduino well (prefer pure C) and can't predict memory usage/fragmentation on that way.

                  BTW, as an idea - add wifi and/or mqtt settings as MyMessage to be changed via "standard" way

                  1 Reply Last reply
                  0
                  • YveauxY Yveaux

                    @Alexander-Voronin Great to hear your issue is solved, but this solution will permanently claim 128 of the scarce ATMega RAM...

                    YveauxY Offline
                    YveauxY Offline
                    Yveaux
                    Mod
                    wrote on last edited by
                    #11

                    @Yveaux said:

                    scarce ATMega RAM...

                    I mean ESP RAM ofcourse... :facepunch:

                    http://yveaux.blogspot.nl

                    A 1 Reply Last reply
                    0
                    • YveauxY Yveaux

                      @Yveaux said:

                      scarce ATMega RAM...

                      I mean ESP RAM ofcourse... :facepunch:

                      A Offline
                      A Offline
                      Alexander Voronin
                      wrote on last edited by
                      #12

                      @Yveaux I have 34 of 80k RAM used for this sketch, so 128 bytes looks like "a bit more".

                      You can not use progmem with ESP and mysensors now because PSTR redefined as PSTR(x) (x) so all strings are really in RAM :(

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      14

                      Online

                      11.7k

                      Users

                      11.2k

                      Topics

                      113.0k

                      Posts


                      Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • MySensors
                      • OpenHardware.io
                      • Categories
                      • Recent
                      • Tags
                      • Popular