mariolukas / Watterott-CO2-Ampel-Plus-Firmware

Firmware for Watterott CO2 Ampel (Plus Version)
GNU General Public License v3.0
15 stars 13 forks source link

Updating Firmware erases WiFi and MQTT settings #5

Closed reibuehl closed 3 years ago

reibuehl commented 3 years ago

When I compile a new firmware version and install it via the Arduino IDE, all settings like wifi SSID and PW and MQTT server are reset to the defaults. Shouldn't they survive a firmware update?

awatterott commented 3 years ago

The settings are in flash memory with the firmware, because the SAMD21 has no special memory for settings like an EEPROM. The bootloader does not know about the settings and will erase the complete memory on an update and so the settings will not survive.

reibuehl commented 3 years ago

Does this also happen when the firmware is installed via the mass storage upload or is this just a Arduino IDE issue?

awatterott commented 3 years ago

Its the same, both is handled by the bootloader: https://github.com/awatterott/uf2-samd21

reibuehl commented 3 years ago

I don't know the architecture and especially the way the build toolchain is integrated into the Arduino IDE, but maybe this link is helpfull: https://www.avrfreaks.net/comment/1937676#comment-1937676 Is such a option also available in the toolchain that is used by Arduino? Then it might be possible to expose such a flag in the board definition and users could select if they want to overwrite the flash or not.

awatterott commented 3 years ago

The settings are in the flash memory and will be erased/overwritten by the new firmware data on an update. It can work, when the settings are put at the end of the flash, so that there is a separation between program data and settings data. The settings are stored/read through this library: https://github.com/cmaglie/FlashStorage