Fixed compilation error of no getBytesLength member with arduino-esp32 1.0.1 or earlier. issue #125

pull/129/head
Hieromon Ikasamo 5 years ago
parent 3938f5af64
commit f04ac4ba2c
  1. 6
      src/AutoConnectCredential.cpp
  2. 31
      src/AutoConnectCredential.h

@ -2,8 +2,8 @@
* AutoConnectCredential class dispatcher. * AutoConnectCredential class dispatcher.
* @file AutoConnectCredential.cpp * @file AutoConnectCredential.cpp
* @author hieromon@gmail.com * @author hieromon@gmail.com
* @version 1.0.0 * @version 1.0.2
* @date 2019-08-15 * @date 2019-09-16
* @copyright MIT license. * @copyright MIT license.
*/ */
@ -520,7 +520,7 @@ bool AutoConnectCredential::_del(const char* ssid, const bool commit) {
uint8_t AutoConnectCredential::_import(void) { uint8_t AutoConnectCredential::_import(void) {
uint8_t cn = 0; uint8_t cn = 0;
if (_pref->begin(AC_CREDENTIAL_NVSNAME, true)) { if (_pref->begin(AC_CREDENTIAL_NVSNAME, true)) {
size_t psz = _pref->getBytesLength(AC_CREDENTIAL_NVSKEY); size_t psz = AutoConnectUtil::getPrefBytesLength<Preferences>(_pref.get(), AC_CREDENTIAL_NVSKEY);
if (psz) { if (psz) {
uint8_t* credtPool = (uint8_t*)malloc(psz); uint8_t* credtPool = (uint8_t*)malloc(psz);
if (credtPool) { if (credtPool) {

@ -2,8 +2,8 @@
* Declaration of AutoConnectCredential class. * Declaration of AutoConnectCredential class.
* @file AutoConnectCredential.h * @file AutoConnectCredential.h
* @author hieromon@gmail.com * @author hieromon@gmail.com
* @version 1.0.0 * @version 1.0.2
* @date 2019-08-15 * @date 2019-09-16
* @copyright MIT license. * @copyright MIT license.
*/ */
@ -40,6 +40,7 @@ uint8_t bssid[6];
wifi_fast_scan_threshold_t threshold; wifi_fast_scan_threshold_t threshold;
}; };
#endif #endif
#include "AutoConnectDefs.h"
/** /**
* Credential storage area offset specifier in EEPROM. * Credential storage area offset specifier in EEPROM.
@ -105,12 +106,38 @@ class AutoConnectCredential : public AutoConnectCredentialBase {
#else #else
// #pragma message "AutoConnectCredential applies the Preferences" // #pragma message "AutoConnectCredential applies the Preferences"
#include <type_traits>
#include <map> #include <map>
#include <Preferences.h> #include <Preferences.h>
#include <nvs.h>
#define AC_CREDENTIAL_NVSNAME AC_IDENTIFIER #define AC_CREDENTIAL_NVSNAME AC_IDENTIFIER
#define AC_CREDENTIAL_NVSKEY AC_CREDENTIAL_NVSNAME #define AC_CREDENTIAL_NVSKEY AC_CREDENTIAL_NVSNAME
namespace AutoConnectUtil {
AC_HAS_FUNC(getBytesLength);
template<typename T>
typename std::enable_if<AutoConnectUtil::has_func_getBytesLength<T>::value, size_t>::type getPrefBytesLength(T* pref, const char* key) {
return pref->getBytesLength(key);
}
template<typename T>
typename std::enable_if<!AutoConnectUtil::has_func_getBytesLength<T>::value, size_t>::type getPrefBytesLength(T* pref, const char* key) {
AC_UNUSED(pref);
uint32_t handle;
size_t len;
esp_err_t err = nvs_open(AC_CREDENTIAL_NVSNAME, NVS_READONLY, &handle);
if (err)
len = 0;
else {
(void)nvs_get_blob(handle, key, NULL, &len);
nvs_close(handle);
}
return len;
}
}
/** AutoConnectCredential class using Preferences for ESP32 */ /** AutoConnectCredential class using Preferences for ESP32 */
class AutoConnectCredential : public AutoConnectCredentialBase { class AutoConnectCredential : public AutoConnectCredentialBase {
public: public:

Loading…
Cancel
Save