From 4eb4a3b24b35c9facc8b826fdae86eb3f5ebef07 Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Sun, 18 Aug 2019 15:07:09 +0900 Subject: [PATCH] Fixed Fixed missing captive portal notifications (issue #85) --- README.md | 3 + mkdocs/apiconfig.md | 4 +- mkdocs/menu.md | 2 +- src/AutoConnect.cpp | 6 +- src/AutoConnectCredential.cpp | 177 +++++++++++++++++++++++++--------- src/AutoConnectCredential.h | 4 + src/AutoConnectDefs.h | 6 +- 7 files changed, 149 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index 2987e80..42b193b 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,9 @@ Full documentation is available on https://Hieromon.github.io/AutoConnect, some ### [1.0.0] Aug. 13, 2019 - Supports AutoConnectUpdate for the OTA update. +### [0.9.12] Aug. 18, 2019 +- Fixed missing captive portal notifications on the newer mobile OS client. As a result of this fix, the SoftAP default IP address and gateway have been changed to **172.217.28.1**. (issue #85) + ### [0.9.11] July 13, 2019 - Supports new element as AutoConnectSytle that can insert the custom CSS into AutoConnectAux page. (PR#96) - Supports that `
` tags can now be added to each element. (PR #95) diff --git a/mkdocs/apiconfig.md b/mkdocs/apiconfig.md index 75e16b0..971110a 100644 --- a/mkdocs/apiconfig.md +++ b/mkdocs/apiconfig.md @@ -37,7 +37,7 @@ SoftAP's SSID. Sets IP address for Soft AP in captive portal. When AutoConnect fails the initial WiFi.begin, it starts the captive portal with the IP address specified this.
**Type**
-
IPAddressThe default value is **192.168.244.1**
+
IPAddressThe default value is **172.217.28.1**
### autoReconnect @@ -147,7 +147,7 @@ Set secondary DNS server address when using static IP address. Sets gateway address for Soft AP in captive portal. When AutoConnect fails the initial WiFi.begin, it starts the captive portal with the IP address specified this.
**Type**
-
IPAddressThe default value is **192.168.244.1**
+
IPAddressThe default value is **172.217.28.1**
### hidden diff --git a/mkdocs/menu.md b/mkdocs/menu.md index 5851450..ed40d93 100644 --- a/mkdocs/menu.md +++ b/mkdocs/menu.md @@ -3,7 +3,7 @@ ## Where the from -The AutoConnect menu appears when you access the **AutoConnect root path**. It is assigned "**/_ac**" located on the *local IP address* of ESP8266/ESP32 module by default. This location can be changed in the sketch. The following screen will appear at access to `http://{localIP}/_ac` as the root path. This is the statistics of the current WiFi connection. You can access the menu from the here, to invoke it tap at right on top. (e.g. `http://192.168.244.1/_ac` for SoftAP mode.) +The AutoConnect menu appears when you access the **AutoConnect root path**. It is assigned "**/_ac**" located on the *local IP address* of ESP8266/ESP32 module by default. This location can be changed in the sketch. The following screen will appear at access to `http://{localIP}/_ac` as the root path. This is the statistics of the current WiFi connection. You can access the menu from the here, to invoke it tap at right on top. (e.g. `http://172.217.28.1/_ac` for SoftAP mode.) diff --git a/src/AutoConnect.cpp b/src/AutoConnect.cpp index f0c9efb..be79c87 100644 --- a/src/AutoConnect.cpp +++ b/src/AutoConnect.cpp @@ -485,8 +485,10 @@ void AutoConnect::handleRequest(void) { // Save current credential if (_apConfig.autoSave == AC_SAVECREDENTIAL_AUTO) { AutoConnectCredential credit(_apConfig.boundaryOffset); - credit.save(&_credential); - AC_DBG("%s credential saved\n", reinterpret_cast(_credential.ssid)); + if (credit.save(&_credential)) + AC_DBG("%s credential saved\n", reinterpret_cast(_credential.ssid)); + else + AC_DBG("credential %s save failed\n", reinterpret_cast(_credential.ssid)); } // Ensures that keeps a connection with the current AP while the portal behaves. diff --git a/src/AutoConnectCredential.cpp b/src/AutoConnectCredential.cpp index d162b14..531292a 100644 --- a/src/AutoConnectCredential.cpp +++ b/src/AutoConnectCredential.cpp @@ -7,7 +7,7 @@ * @copyright MIT license. */ -#include +// #include #include "AutoConnectCredential.h" #define AC_IDENTIFIER "AC_CREDT" @@ -47,33 +47,43 @@ void AutoConnectCredential::_allocateEntry(void) { char id_c[sizeof(AC_IDENTIFIER) - 1]; uint8_t c; - EEPROM.begin(AC_HEADERSIZE); + _eeprom.reset(new EEPROMClass); + + // EEPROM.begin(AC_HEADERSIZE); + _eeprom->begin(AC_HEADERSIZE + sizeof(struct station_config)); // Validate the save area of the EEPROM. // If it is a valid area, retrieve the stored number of entries, // if the identifier is not saved, initialize the EEPROM area. _dp = _offset; for (c = 0; c < sizeof(id_c); c++) { - id_c[c] = static_cast(EEPROM.read(_dp++)); + // id_c[c] = static_cast(EEPROM.read(_dp++)); + id_c[c] = static_cast(_eeprom->read(_dp++)); } if (!strncmp(id_c, AC_IDENTIFIER, sizeof(id_c))) { - _entries = EEPROM.read(static_cast(_dp++)); - _containSize = EEPROM.read(static_cast(_dp++)); - _containSize += EEPROM.read(static_cast(_dp)) << 8; + // _entries = EEPROM.read(static_cast(_dp++)); + // _containSize = EEPROM.read(static_cast(_dp++)); + // _containSize += EEPROM.read(static_cast(_dp)) << 8; + _entries = _eeprom->read(static_cast(_dp++)); + _containSize = _eeprom->read(static_cast(_dp++)); + _containSize += _eeprom->read(static_cast(_dp)) << 8; } else { _entries = 0; _containSize = 0; } - EEPROM.end(); + // EEPROM.end(); + _eeprom->end(); } /** * The destructor ends EEPROM access. */ AutoConnectCredential::~AutoConnectCredential() { - EEPROM.end(); + // EEPROM.end(); + _eeprom->end(); + _eeprom.reset(); } /** @@ -88,31 +98,42 @@ bool AutoConnectCredential::del(const char* ssid) { if (load(ssid, &entry) >= 0) { // Saved credential detected, _ep has the entry location. - EEPROM.begin(AC_HEADERSIZE + _containSize); + // EEPROM.begin(AC_HEADERSIZE + _containSize); + _eeprom->begin(AC_HEADERSIZE + _containSize); _dp = _ep; // Erase SSID - while (EEPROM.read(_dp) != 0x00) - EEPROM.write(_dp++, 0xff); + // while (EEPROM.read(_dp) != 0x00) + // EEPROM.write(_dp++, 0xff); + while (_eeprom->read(_dp) != 0x00) + _eeprom->write(_dp++, 0xff); // Erase Password - EEPROM.write(_dp++, 0xff); - while (EEPROM.read(_dp) != 0x00) - EEPROM.write(_dp++, 0xff); + // EEPROM.write(_dp++, 0xff); + _eeprom->write(_dp++, 0xff); + // while (EEPROM.read(_dp) != 0x00) + // EEPROM.write(_dp++, 0xff); + while (_eeprom->read(_dp) != 0x00) + _eeprom->write(_dp++, 0xff); // Erase BSSID - EEPROM.write(_dp++, 0xff); + // EEPROM.write(_dp++, 0xff); + _eeprom->write(_dp++, 0xff); for (uint8_t i = 0; i < sizeof(station_config::bssid); i++) - EEPROM.write(_dp++, 0xff); + // EEPROM.write(_dp++, 0xff); + _eeprom->write(_dp++, 0xff); // End 0xff writing, update headers. _entries--; - EEPROM.write(_offset + static_cast(sizeof(AC_IDENTIFIER)) - 1, _entries); + // EEPROM.write(_offset + static_cast(sizeof(AC_IDENTIFIER)) - 1, _entries); + _eeprom->write(_offset + static_cast(sizeof(AC_IDENTIFIER)) - 1, _entries); // commit it. - rc = EEPROM.commit(); + // rc = EEPROM.commit(); + rc = _eeprom->commit(); delay(10); - EEPROM.end(); + // EEPROM.end(); + _eeprom->end(); } return rc; } @@ -131,7 +152,9 @@ int8_t AutoConnectCredential::load(const char* ssid, struct station_config* conf _dp = AC_HEADERSIZE; if (_entries) { - EEPROM.begin(AC_HEADERSIZE + _containSize); + Serial.printf("load: length series, AC_HEADERSIZE(%d), _containSize(%d)\n", AC_HEADERSIZE, _containSize); + // EEPROM.begin(AC_HEADERSIZE + _containSize); + _eeprom->begin(AC_HEADERSIZE + _containSize); for (uint8_t i = 0; i < _entries; i++) { _retrieveEntry(reinterpret_cast(config->ssid), reinterpret_cast(config->password), config->bssid); if (!strcmp(ssid, (const char*)config->ssid)) { @@ -139,7 +162,8 @@ int8_t AutoConnectCredential::load(const char* ssid, struct station_config* conf break; } } - EEPROM.end(); + // EEPROM.end(); + _eeprom->end(); } return entry; } @@ -156,10 +180,13 @@ int8_t AutoConnectCredential::load(const char* ssid, struct station_config* conf bool AutoConnectCredential::load(int8_t entry, struct station_config* config) { _dp = AC_HEADERSIZE; if (_entries && entry < _entries) { - EEPROM.begin(AC_HEADERSIZE + _containSize); + Serial.printf("load: length series, AC_HEADERSIZE(%d), _containSize(%d)\n", AC_HEADERSIZE, _containSize); + // EEPROM.begin(AC_HEADERSIZE + _containSize); + _eeprom->begin(AC_HEADERSIZE + _containSize); while (entry-- >= 0) _retrieveEntry(reinterpret_cast(config->ssid), reinterpret_cast(config->password), config->bssid); - EEPROM.end(); + // EEPROM.end(); + _eeprom->end(); return true; } else { @@ -181,48 +208,78 @@ bool AutoConnectCredential::save(const struct station_config* config) { struct station_config stage; int8_t entry; bool rep = false; + bool rc; // Detect same entry for replacement. entry = load((const char*)(config->ssid), &stage); // Saving start. - EEPROM.begin(AC_HEADERSIZE + _containSize + sizeof(struct station_config)); + // EEPROM.begin(AC_HEADERSIZE + _containSize + sizeof(struct station_config)); + _eeprom->begin(AC_HEADERSIZE + _containSize + sizeof(struct station_config)); + Serial.printf("save: length series: AC_HEADERSIZE(%d), _containSize(%d), sizeof(struct station_config)(%d)\n", AC_HEADERSIZE, _containSize, sizeof(struct station_config)); // Determine insertion or replacement. if (entry >= 0) { // An entry with the same SSID was found, release the area for replacement. _dp = _ep; for (uint8_t dm = 2; dm; _dp++) { - if (EEPROM.read(_dp) == '\0') + // uint8_t c = EEPROM.read(_dp); + uint8_t c = _eeprom->read(_dp); + Serial.printf("(RD)<- %04x %02x %c\n", _dp, c, c < 0x20 ? '.' : c); +// if (EEPROM.read(_dp) == '\0') + if (c == '\0') dm--; - EEPROM.write(_dp, 0xff); // Clear SSID, Passphrase + Serial.printf("(WR)-> %04x 0xff .\n", _dp); + // EEPROM.write(_dp, 0xff); // Clear SSID, Passphrase + _eeprom->write(_dp, 0xff); // Clear SSID, Passphrase + } + for (uint8_t i = 0; i < sizeof(station_config::bssid); i++) { + Serial.printf("(WR)-> %04x 0xff .\n", _dp); + // EEPROM.write(_dp++, 0xff); // Clear BSSID + _eeprom->write(_dp++, 0xff); // Clear BSSID } - for (uint8_t i = 0; i < sizeof(station_config::bssid); i++) - EEPROM.write(_dp++, 0xff); // Clear BSSID } else { // Same entry not found. increase the entry. _entries++; int i; - for (i = 0; i < static_cast(sizeof(_id)) - 1; i++) - EEPROM.write(i + _offset, (uint8_t)_id[i]); - EEPROM.write(i + _offset, _entries); + for (i = 0; i < static_cast(sizeof(_id)) - 1; i++) { + Serial.printf("(WR)-> %04x %02x %c\n", i + _offset, (uint8_t)_id[i], (uint8_t)_id[i] < 0x20 ? '.' : (char)_id[i]); + // EEPROM.write(i + _offset, (uint8_t)_id[i]); + _eeprom->write(i + _offset, (uint8_t)_id[i]); + } + Serial.printf("(WR)-> %04x %02x %c\n", i + _offset, _entries, _entries < 0x20 ? '.' : (char)_entries); + // EEPROM.write(i + _offset, _entries); + _eeprom->write(i + _offset, _entries); } + rc = _eeprom->commit(); + delay(10); + if (!rc) Serial.printf("commit error\n"); + // Seek insertion point, evaluate capacity to insert the new entry. uint16_t eSize = strlen((const char*)config->ssid) + strlen((const char*)config->password) + sizeof(station_config::bssid) + 2; + Serial.printf("new entry size:%d\n", eSize); for (_dp = AC_HEADERSIZE; _dp < _containSize + AC_HEADERSIZE; _dp++) { - if (EEPROM.read(_dp) == 0xff) { + // uint8_t c = EEPROM.read(_dp); + uint8_t c = _eeprom->read(_dp); + Serial.printf("(RD)<- %04x %02x %c\n", _dp, c, c < 0x20 ? '.' : c); + if (c == 0xff) { uint16_t fp = _dp; - while (EEPROM.read(++_dp) == 0xff) {} + Serial.printf("skip from %04x\n", _dp); + // while (EEPROM.read(++_dp) == 0xff) {} + while (_eeprom->read(++_dp) == 0xff) {} + Serial.printf("skip to %04x\n", _dp); if (_dp - fp >= eSize) { _dp = fp; rep = true; + Serial.printf("rep position:%02x\n", _dp); break; } _dp--; } } + Serial.printf("insertion position:%02x\n", _dp); // Save new entry uint8_t c; @@ -230,29 +287,46 @@ bool AutoConnectCredential::save(const struct station_config* config) { dt = config->ssid; do { // Write SSID c = *dt++; - EEPROM.write(_dp++, c); + Serial.printf("(WR)-> %04x %02x %c\n", _dp, c, c < 0x20 ? '.' : (char)c); + // EEPROM.write(_dp++, c); + _eeprom->write(_dp++, c); } while (c != '\0'); dt = config->password; do { // Write password c = *dt++; - EEPROM.write(_dp++, c); + Serial.printf("(WR)-> %04x %02x %c\n", _dp, c, c < 0x20 ? '.' : (char)c); + // EEPROM.write(_dp++, c); + _eeprom->write(_dp++, c); } while (c != '\0'); - for (uint8_t i = 0; i < sizeof(station_config::bssid); i++) - EEPROM.write(_dp++, config->bssid[i]); // write BSSID + for (uint8_t i = 0; i < sizeof(station_config::bssid); i++) { + Serial.printf("(WR)-> %04x %02x %c\n", _dp, config->bssid[i], config->bssid[i] < 0x20 ? '.' : (char)config->bssid[i]); + // EEPROM.write(_dp++, config->bssid[i]); // write BSSID + _eeprom->write(_dp++, config->bssid[i]); // write BSSID + } // Terminate container, mark to the end of credential area. // When the entry is replaced, not mark a terminator. if (!rep) { - EEPROM.write(_dp, '\0'); + Serial.printf("!rep\n"); + Serial.printf("(WR)-> %04x 00 .\n", _dp); + // EEPROM.write(_dp, '\0'); + _eeprom->write(_dp, '\0'); // Update container size _containSize = _dp - AC_HEADERSIZE; - EEPROM.write(_offset + sizeof(AC_IDENTIFIER) - 1 + sizeof(uint8_t), (uint8_t)_containSize); - EEPROM.write(_offset + sizeof(AC_IDENTIFIER) - 1 + sizeof(uint8_t) + 1, (uint8_t)(_containSize >> 8)); + // EEPROM.write(_offset + sizeof(AC_IDENTIFIER) - 1 + sizeof(uint8_t), (uint8_t)_containSize); + _eeprom->write(_offset + sizeof(AC_IDENTIFIER) - 1 + sizeof(uint8_t), (uint8_t)_containSize); + Serial.printf("(WR)-> %04x %02x %c\n", _offset + sizeof(AC_IDENTIFIER) - 1 + sizeof(uint8_t), (uint8_t)_containSize, (uint8_t)_containSize < 0x20 ? '.' : (uint8_t)_containSize); + // EEPROM.write(_offset + sizeof(AC_IDENTIFIER) - 1 + sizeof(uint8_t) + 1, (uint8_t)(_containSize >> 8)); + _eeprom->write(_offset + sizeof(AC_IDENTIFIER) - 1 + sizeof(uint8_t) + 1, (uint8_t)(_containSize >> 8)); + Serial.printf("(WR)-> %04x %02x %c\n", _offset + sizeof(AC_IDENTIFIER) - 1 + sizeof(uint8_t) + 1, (uint8_t)(_containSize >> 8), (uint8_t)(_containSize >> 8) < 0x20 ? '.' : (uint8_t)(_containSize >> 8)); } - bool rc = EEPROM.commit(); + // bool rc = EEPROM.commit(); + rc &= _eeprom->commit(); delay(10); - EEPROM.end(); + if (!rc) Serial.printf("commit error\n"); + // EEPROM.end(); + _eeprom->end(); return rc; } @@ -266,23 +340,34 @@ bool AutoConnectCredential::save(const struct station_config* config) { void AutoConnectCredential::_retrieveEntry(char* ssid, char* password, uint8_t* bssid) { uint8_t ec; + Serial.println("_retrieveEntry:<-"); // Skip unavailable entry. - while ((ec = EEPROM.read(_dp++)) == 0xff) {} + Serial.printf("skip from %04x\n", _dp); + // while ((ec = EEPROM.read(_dp++)) == 0xff) {} + while ((ec = _eeprom->read(_dp++)) == 0xff) {} + Serial.printf("skip to %04x\n", _dp); // Retrieve SSID _ep = _dp - 1; *ssid++ = ec; do { - ec = EEPROM.read(_dp++); + // ec = EEPROM.read(_dp++); + ec = _eeprom->read(_dp++); + Serial.printf("(RD)<- %04x %02x %c\n", _dp - 1, ec, ec < 0x20 ? '.' : ec); *ssid++ = ec; } while (ec != '\0'); // Retrieve Password do { - ec = EEPROM.read(_dp++); + // ec = EEPROM.read(_dp++); + ec = _eeprom->read(_dp++); + Serial.printf("(RD)<- %04x %02x %c\n", _dp - 1, ec, ec < 0x20 ? '.' : ec); *password++ = ec; } while (ec != '\0'); // Retrieve BSSID for (uint8_t i = 0; i < sizeof(station_config::bssid); i++) { - bssid[i] = EEPROM.read(_dp++); + // bssid[i] = EEPROM.read(_dp++); + bssid[i] = _eeprom->read(_dp++); + Serial.printf("(RD)<- %04x %02x %c\n", _dp - 1, bssid[i], bssid[i] < 0x20 ? '.' : bssid[i]); } + Serial.println("_retrieveEntry:->"); } diff --git a/src/AutoConnectCredential.h b/src/AutoConnectCredential.h index c84fb43..017f31a 100644 --- a/src/AutoConnectCredential.h +++ b/src/AutoConnectCredential.h @@ -10,6 +10,7 @@ #ifndef _AUTOCONNECTCREDENTIAL_H_ #define _AUTOCONNECTCREDENTIAL_H_ +#include #include #if defined(ARDUINO_ARCH_ESP8266) extern "C" { @@ -24,6 +25,8 @@ struct station_config { uint8_t bssid[6]; wifi_fast_scan_threshold_t threshold; }; +#define NO_GLOBAL_EEPROM +#include #endif /** Credential storage area offset specifier in EEPROM. @@ -55,6 +58,7 @@ class AutoConnectCredential { int _dp; /**< The current address in EEPROM */ int _ep; /**< The current entry address in EEPROM */ uint16_t _offset; /**< The offset for the saved area of credentials in EEPROM. */ + std::unique_ptr _eeprom; /**< shared EEPROM class */ }; #endif // _AUTOCONNECTCREDENTIAL_H_ diff --git a/src/AutoConnectDefs.h b/src/AutoConnectDefs.h index b61cd86..97e8fd5 100644 --- a/src/AutoConnectDefs.h +++ b/src/AutoConnectDefs.h @@ -48,10 +48,12 @@ #endif // !AUTOCONNECT_PSK #ifndef AUTOCONNECT_AP_IP -#define AUTOCONNECT_AP_IP 0x01F4A8C0 //*< 192.168.244.1 */ +// #define AUTOCONNECT_AP_IP 0x01F4A8C0 //*< 192.168.244.1 */ +#define AUTOCONNECT_AP_IP 0x011CD9AC //*< 172.217.28.1 */ #endif // !AUTOCONNECT_AP_IP #ifndef AUTOCONNECT_AP_GW -#define AUTOCONNECT_AP_GW 0x01F4A8C0 //*< 192.168.244.1 */ +// #define AUTOCONNECT_AP_GW 0x01F4A8C0 //*< 192.168.244.1 */ +#define AUTOCONNECT_AP_GW 0x011CD9AC //*< 172.217.28.1 */ #endif // !AUTOCONNECT_AP_GW #ifndef AUTOCONNECT_AP_NM #define AUTOCONNECT_AP_NM 0x00FFFFFF //*< 255.255.255.0 */