diff --git a/examples/EEPROM/EEPROM.ino b/examples/EEPROM/EEPROM.ino index 5baee9b..3e4b829 100644 --- a/examples/EEPROM/EEPROM.ino +++ b/examples/EEPROM/EEPROM.ino @@ -9,7 +9,7 @@ configuration for the Sketch. When Sketch stores the own configuration data in the EEPROM, it must avoid conflict with the credentials stored by AutoConnect. - AutoConnectConfig::boundayOffet designation helps with the conflict, + AutoConnectConfig::boundaryOffset designation helps with the conflict, but it is inadequate. Sketch uses AutoConnect::getCredentialSize to get the size of the actual EEPROM area that should be handled for the own custom data I/O. @@ -117,8 +117,8 @@ String onEEPROM(AutoConnectAux& page, PageArgument& args) { // EEPROM.begin is the sum of the size of the own custom data and // the size of the currently stored AutoConnect credentials. // eg. - // sizeof(EEPROM_CONFIG_t) + portal.getCredentialSize() - EEPROM.begin(sizeof(EEPROM_CONFIG_t) + portal.getCredentialSize()); + // EEPROM.begin(portal.getEEPROMUsedSize()) + EEPROM.begin(portal.getEEPROMUsedSize()); EEPROM.get(0, eepromConfig); EEPROM.end(); @@ -136,7 +136,7 @@ String onEEPROMWrite(AutoConnectAux& page, PageArgument& args) { strncpy(eepromConfig.data2, page["data2"].value.c_str(), sizeof(EEPROM_CONFIG_t::data2)); strncpy(eepromConfig.data3, page["data3"].value.c_str(), sizeof(EEPROM_CONFIG_t::data3)); - EEPROM.begin(sizeof(EEPROM_CONFIG_t) + portal.getCredentialSize()); + EEPROM.begin(portal.getEEPROMUsedSize()); EEPROM.put(0, eepromConfig); EEPROM.commit(); EEPROM.end(); diff --git a/src/AutoConnect.cpp b/src/AutoConnect.cpp index 936cc87..fa68dcf 100644 --- a/src/AutoConnect.cpp +++ b/src/AutoConnect.cpp @@ -747,12 +747,17 @@ bool AutoConnect::_loadAvailCredential(const char* ssid, const AC_PRINCIPLE_t pr } /** - * Get current AutoConnectCredential size + * Get current AutoConnectCredential size. + * This function is available only for ESP8266 use. * @return Size of the AutoConnectCredential */ -uint16_t AutoConnect::getCredentialSize(void) { +uint16_t AutoConnect::getEEPROMUsedSize(void) { +#if defined(ARDUINO_ARCH_ESP8266) AutoConnectCredential credentials(_apConfig.boundaryOffset); - return credentials.dataSize(); + return _apConfig.boundaryOffset + credentials.dataSize(); +#elif defined(ARDUINO_ARCH_ESP32) + return 0; +#endif } /** diff --git a/src/AutoConnect.h b/src/AutoConnect.h index 671802a..95eac36 100644 --- a/src/AutoConnect.h +++ b/src/AutoConnect.h @@ -252,7 +252,7 @@ class AutoConnect { String where(void) const { return _auxUri; } inline void enableMenu(const uint16_t items) { _apConfig.menuItems |= items; } inline void disableMenu(const uint16_t items) { _apConfig.menuItems &= (0xffff ^ items); } - uint16_t getCredentialSize(void); + uint16_t getEEPROMUsedSize(void); /** For AutoConnectAux described in JSON */ #ifdef AUTOCONNECT_USE_JSON