Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not reset system config when config version changed. #18

Open
gusarov opened this issue Jan 9, 2019 · 11 comments
Open

Do not reset system config when config version changed. #18

gusarov opened this issue Jan 9, 2019 · 11 comments

Comments

@gusarov
Copy link

gusarov commented Jan 9, 2019

Suggestion:
Let's separate system config (ap password, siid, etc) and custom config versioning.
I assume a version for system config part can be hardcoded and will be only affected when user upgrades to the next release, where those configs layout been changed. While the rest of config is versioned by developer. In this case, when developer changes his custom config layout & bumps a version (or user uploads new firmware), he will not be forced to start over again and configure IoT via AP mode. Device will continue to connect (because those builtin setting will be preserved). User will be able to login on iot inside wifi and update new custom config much easier and faster.
Digging in more details, I suppose system-part data should go first to avoid any offsets (I suppose it already goes first?). This means, when system part is changed - both parts must be reset (PS: if only we don't add some padding for future upgrades)

system version custom version system settings custom setting
- - - -
- changed - reset
changed - reset reset
changed changed reset reset
@prampec
Copy link
Owner

prampec commented Jan 9, 2019

That make sense. However (as mentioned in the README) I do only recommend to configure the system in AP mode. I will think about this.

@1TekPro
Copy link

1TekPro commented Feb 3, 2019

@prampec Any update on this issue?

@prampec
Copy link
Owner

prampec commented Feb 3, 2019

I understand the problem, and I can agree, that forcing AP mode on every update is not the proper way to handle the things. But I'm still not sure, that the mentioned solution the right one solve this problem.

@1TekPro
Copy link

1TekPro commented Feb 3, 2019

@prampec Maybe have support for a "developer" option?
I constantly run into this issue. With multiple sketches using eeps and only 1 test board, I have to erase flash often.

@prampec
Copy link
Owner

prampec commented Apr 14, 2021

Version v3.0.0 is out, but this one is not included in it. I still not decided how to do this properly.

@EricDuminil
Copy link
Contributor

I don't know if this solution is acceptable from a security point of view, but it has worked well for my needs:

  • I define AP password, Wifi SSID and Wifi Password in my_config.h, which I do not save in git. I have a my_config.template.h in git, with:
#  define AP_PASSWORD ""
#  define WIFI_SSID     ""
#  define WIFI_PASSWORD ""
  • I include my_config.h in my sketch
  • I add those lines to setup() , before calling iotWebConf.init():
iotWebConf.getApPasswordParameter()->defaultValue = AP_PASSWORD;
iotWebConf.getWifiSsidParameter()->defaultValue = WIFI_SSID;
iotWebConf.getWifiPasswordParameter()->defaultValue = WIFI_PASSWORD;
  • Since the defaults for those 3 values will always be defined, even if the config version changes or has been reset, I don't need those lines anymore, and delete them from IoTWebConf.cpp (Take this with a grain of salt, I don't know if it has other implications):
  if (!validConfig)
  {
    // -- No config
    this->_apPassword[0] = '\0';
    this->_wifiParameters._wifiSsid[0] = '\0';
    this->_wifiParameters._wifiPassword[0] = '\0';
  }

I can nuke the EEPROM, change config_version or change IOTWEBCONF_CONFIG_START : after a reset, the thing will always connect to my WiFi, and I won't have to type long passwords on my smartphone.

Additionally, I defined some serial commands (similar to https://github.com/prampec/IotWebConf/blob/master/examples/IotWebConf11AdvancedRuntime/IotWebConf11AdvancedRuntime.ino), in order to change SSID and WiFi password from the serial monitor :

> ssid my_other_wifi
Calling : ssid('my_other_wifi')
Setting WiFi ssid to my_other_wifi
> pwd my_other_password
Calling : pwd('my_other_password')
Setting WiFi password to my_other_password
> save_config
Calling : save_config()
Config version: a11
Config size: 431
Saving configuration

I could post the corresponding code if anyone is interested.

@prampec
Copy link
Owner

prampec commented Mar 2, 2022

Yes. This is definitely an elegant solution.

@EricDuminil
Copy link
Contributor

@prampec : Good to know, thanks.

I'm not sure I understand the purpose of :

 if (!validConfig)
  {
    // -- No config
    this->_apPassword[0] = '\0';
    this->_wifiParameters._wifiSsid[0] = '\0';
    this->_wifiParameters._wifiPassword[0] = '\0';
  }

Are those ever needed? From my limited tests, even if EEPROM is full of random bits and the defaults are not set, the values will be set to an empty string.

@EricDuminil
Copy link
Contributor

EricDuminil commented Mar 7, 2022

If anyone's interested in setting passwords and ssid via Serial, there's an example at https://github.com/EricDuminil/IotWebConf/blob/example/shell_commands/examples/IotWebConf18ShellCommands/IotWebConf18ShellCommands.ino

The sketch is a bit long, but most of it could be moved to shell.h and shell.cpp.

Those commands are defined:

    ap 0/1 (Enables/disables access point).
    ap_pwd abc (Sets AP password to abc).
    name abc (Sets ThingName to abc).
    reset (Restarts the ESP).
    reset_config (Resets the complete IotWeb config).
    save_config (Saves the config to EEPROM).
    ssid name (Sets SSID to name).
    wifi 0/1 (Enables/disables WiFi).
    wifi_pwd abc (Sets WiFi password to abc).

It's possible to copy-paste multiple commands at once (at least with PlatformIO monitor), and set everything in one go, without having to type long passwords on a smartphone:

name my_thing
wifi_pwd my_wifi_password
ssid my_ssid
ap_pwd my_ap_password
save_config

The purpose is similar to https://github.com/prampec/IotWebConf/tree/master/examples/IotWebConf11AdvancedRuntime, but I dare say it should be easier to adapt and add new functions.

@NilsRo
Copy link

NilsRo commented Oct 31, 2022

Any news to preserve system config? Had to go out in the rain today because I reset the config as it show senseless entries and as found here loos the WiFi settings also. Would be really nice to get it separated...should be possible to achieve by reserving a fixed amount of bytes for AP Password, SSID, Password in front of the custom data stored in the eeprom.

@NilsRo
Copy link

NilsRo commented Nov 6, 2022

Implement a workaround with preferences.h which restores system settings. Perhaps in long term iotWebConf could change to preferences lib which is also available for ESP8266.

NilsRo/HotWaterRecirculatingPump@59bc86e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants