(service, uuid.toString()));
} // setByUUID
@@ -89,7 +89,44 @@ void BLEServiceMap::handleGATTServerEvent(
esp_ble_gatts_cb_param_t *param) {
// Invoke the handler for every Service we have.
for (auto &myPair : m_uuidMap) {
- myPair.second->handleGATTServerEvent(event, gatts_if, param);
+ myPair.first->handleGATTServerEvent(event, gatts_if, param);
}
}
+
+/**
+ * @brief Get the first service in the map.
+ * @return The first service in the map.
+ */
+BLEService* BLEServiceMap::getFirst() {
+ m_iterator = m_uuidMap.begin();
+ if (m_iterator == m_uuidMap.end()) {
+ return nullptr;
+ }
+ BLEService* pRet = m_iterator->first;
+ m_iterator++;
+ return pRet;
+} // getFirst
+
+/**
+ * @brief Get the next service in the map.
+ * @return The next service in the map.
+ */
+BLEService* BLEServiceMap::getNext() {
+ if (m_iterator == m_uuidMap.end()) {
+ return nullptr;
+ }
+ BLEService* pRet = m_iterator->first;
+ m_iterator++;
+ return pRet;
+} // getNext
+
+/**
+ * @brief Removes service from maps.
+ * @return N/A.
+ */
+void BLEServiceMap::removeService(BLEService *service){
+ m_handleMap.erase(service->getHandle());
+ m_uuidMap.erase(service);
+} // removeService
+
#endif /* CONFIG_BT_ENABLED */
diff --git a/lib/ESP32_BLE_Arduino/src/BLEUtils.cpp b/lib/ESP32_BLE_Arduino/src/BLEUtils.cpp
index ff4ebfa..a33ee27 100644
--- a/lib/ESP32_BLE_Arduino/src/BLEUtils.cpp
+++ b/lib/ESP32_BLE_Arduino/src/BLEUtils.cpp
@@ -1654,7 +1654,7 @@ void BLEUtils::dumpGattServerEvent(
evtParam->add_char_descr.attr_handle,
evtParam->add_char_descr.service_handle,
evtParam->add_char_descr.service_handle,
- BLEUUID(evtParam->add_char_descr.char_uuid).toString().c_str());
+ BLEUUID(evtParam->add_char_descr.descr_uuid).toString().c_str());
break;
} // ESP_GATTS_ADD_CHAR_DESCR_EVT
diff --git a/lib/WiFiManager/README.md b/lib/WiFiManager/README.md
index a329f2b..3782339 100644
--- a/lib/WiFiManager/README.md
+++ b/lib/WiFiManager/README.md
@@ -1,3 +1,5 @@
+## Current development going on here :arrow_right: [Development Branch](https://github.com/tzapu/WiFiManager/tree/development)
+
# WiFiManager
ESP8266 WiFi Connection manager with fallback web configuration portal
@@ -43,16 +45,19 @@ First attempt at a library. Lots more changes and fixes to do. Contributions are
 
## Wishlist
-- ~~remove dependency on EEPROM library~~
-- ~~move HTML Strings to PROGMEM~~
-- ~~cleanup and streamline code~~ (although this is ongoing)
-- if timeout is set, extend it when a page is fetched in AP mode
-- ~~add ability to configure more parameters than ssid/password~~
-- ~~maybe allow setting ip of ESP after reboot~~
-- ~~add to Arduino Library Manager~~
-- ~~add to PlatformIO~~
-- add multiple sets of network credentials
-- ~~allow users to customize CSS~~
+- [x] remove dependency on EEPROM library
+- [x] move HTML Strings to PROGMEM
+- [x] cleanup and streamline code (although this is ongoing)
+- [x] if timeout is set, extend it when a page is fetched in AP mode
+- [x] add ability to configure more parameters than ssid/password
+- [x] maybe allow setting ip of ESP after reboot
+- [x] add to Arduino Library Manager
+- [x] add to PlatformIO
+- [ ] add multiple sets of network credentials
+- [x] allow users to customize CSS
+- [ ] ESP32 support or instructions
+- [ ] rewrite documentation for simplicity, based on scenarios/goals
+- [ ] rely on the SDK's built in auto connect more than forcing a connect
## Quick Start
diff --git a/lib/WiFiManager/WiFiManager.cpp b/lib/WiFiManager/WiFiManager.cpp
index 3fbbb42..2e7884d 100644
--- a/lib/WiFiManager/WiFiManager.cpp
+++ b/lib/WiFiManager/WiFiManager.cpp
@@ -5,7 +5,7 @@
inspired by:
http://www.esp8266.com/viewtopic.php?f=29&t=2520
https://github.com/chriscook8/esp-arduino-apboot
- https://github.com/esp8266/Arduino/tree/esp8266/hardware/esp8266com/esp8266/libraries/DNSServer/examples/CaptivePortalAdvanced
+ https://github.com/esp8266/Arduino/tree/master/libraries/DNSServer/examples/CaptivePortalAdvanced
Built by AlexT https://github.com/tzapu
Licensed under MIT license
**************************************************************/
@@ -34,7 +34,7 @@ void WiFiManagerParameter::init(const char *id, const char *placeholder, const c
_placeholder = placeholder;
_length = length;
_value = new char[length + 1];
- for (int i = 0; i < length; i++) {
+ for (int i = 0; i < length + 1; i++) {
_value[i] = 0;
}
if (defaultValue != NULL) {
@@ -44,6 +44,12 @@ void WiFiManagerParameter::init(const char *id, const char *placeholder, const c
_customHTML = custom;
}
+WiFiManagerParameter::~WiFiManagerParameter() {
+ if (_value != NULL) {
+ delete[] _value;
+ }
+}
+
const char* WiFiManagerParameter::getValue() {
return _value;
}
@@ -60,14 +66,42 @@ const char* WiFiManagerParameter::getCustomHTML() {
return _customHTML;
}
+
WiFiManager::WiFiManager() {
+ _max_params = WIFI_MANAGER_MAX_PARAMS;
+ _params = (WiFiManagerParameter**)malloc(_max_params * sizeof(WiFiManagerParameter*));
}
-void WiFiManager::addParameter(WiFiManagerParameter *p) {
+WiFiManager::~WiFiManager()
+{
+ if (_params != NULL)
+ {
+ DEBUG_WM(F("freeing allocated params!"));
+ free(_params);
+ }
+}
+
+bool WiFiManager::addParameter(WiFiManagerParameter *p) {
+ if(_paramsCount + 1 > _max_params)
+ {
+ // rezise the params array
+ _max_params += WIFI_MANAGER_MAX_PARAMS;
+ DEBUG_WM(F("Increasing _max_params to:"));
+ DEBUG_WM(_max_params);
+ WiFiManagerParameter** new_params = (WiFiManagerParameter**)realloc(_params, _max_params * sizeof(WiFiManagerParameter*));
+ if (new_params != NULL) {
+ _params = new_params;
+ } else {
+ DEBUG_WM(F("ERROR: failed to realloc params, size not increased!"));
+ return false;
+ }
+ }
+
_params[_paramsCount] = p;
_paramsCount++;
- DEBUG_WM("Adding parameter");
+ DEBUG_WM(F("Adding parameter"));
DEBUG_WM(p->getID());
+ return true;
}
void WiFiManager::setupConfigPortal() {
@@ -109,14 +143,14 @@ void WiFiManager::setupConfigPortal() {
dnsServer->start(DNS_PORT, "*", WiFi.softAPIP());
/* Setup web pages: root, wifi config pages, SO captive portal detectors and not found. */
- server->on("/", std::bind(&WiFiManager::handleRoot, this));
- server->on("/wifi", std::bind(&WiFiManager::handleWifi, this, true));
- server->on("/0wifi", std::bind(&WiFiManager::handleWifi, this, false));
- server->on("/wifisave", std::bind(&WiFiManager::handleWifiSave, this));
- server->on("/i", std::bind(&WiFiManager::handleInfo, this));
- server->on("/r", std::bind(&WiFiManager::handleReset, this));
+ server->on(String(F("/")), std::bind(&WiFiManager::handleRoot, this));
+ server->on(String(F("/wifi")), std::bind(&WiFiManager::handleWifi, this, true));
+ server->on(String(F("/0wifi")), std::bind(&WiFiManager::handleWifi, this, false));
+ server->on(String(F("/wifisave")), std::bind(&WiFiManager::handleWifiSave, this));
+ server->on(String(F("/i")), std::bind(&WiFiManager::handleInfo, this));
+ server->on(String(F("/r")), std::bind(&WiFiManager::handleReset, this));
//server->on("/generate_204", std::bind(&WiFiManager::handle204, this)); //Android/Chrome OS captive portal check.
- server->on("/fwlink", std::bind(&WiFiManager::handleRoot, this)); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler.
+ server->on(String(F("/fwlink")), std::bind(&WiFiManager::handleRoot, this)); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler.
server->onNotFound (std::bind(&WiFiManager::handleNotFound, this));
server->begin(); // Web server start
DEBUG_WM(F("HTTP server started"));
@@ -149,10 +183,34 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {
return startConfigPortal(apName, apPassword);
}
+boolean WiFiManager::configPortalHasTimeout(){
+ if(_configPortalTimeout == 0 || wifi_softap_get_station_num() > 0){
+ _configPortalStart = millis(); // kludge, bump configportal start time to skew timeouts
+ return false;
+ }
+ return (millis() > _configPortalStart + _configPortalTimeout);
+}
+
+boolean WiFiManager::startConfigPortal() {
+ String ssid = "ESP" + String(ESP.getChipId());
+ return startConfigPortal(ssid.c_str(), NULL);
+}
+
boolean WiFiManager::startConfigPortal(char const *apName, char const *apPassword) {
- //setup AP
- WiFi.mode(WIFI_AP_STA);
- DEBUG_WM("SET AP STA");
+
+ if(!WiFi.isConnected()){
+ WiFi.persistent(false);
+ // disconnect sta, start ap
+ WiFi.disconnect(); // this alone is not enough to stop the autoconnecter
+ WiFi.mode(WIFI_AP);
+ WiFi.persistent(true);
+ }
+ else {
+ //setup AP
+ WiFi.mode(WIFI_AP_STA);
+ DEBUG_WM(F("SET AP STA"));
+ }
+
_apName = apName;
_apPassword = apPassword;
@@ -165,7 +223,11 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo
connect = false;
setupConfigPortal();
- while (_configPortalTimeout == 0 || millis() < _configPortalStart + _configPortalTimeout) {
+ while(1){
+
+ // check if timeout
+ if(configPortalHasTimeout()) break;
+
//DNS
dnsServer->processNextRequest();
//HTTP
@@ -222,7 +284,7 @@ int WiFiManager::connectWifi(String ssid, String pass) {
}
//fix for auto connect racing issue
if (WiFi.status() == WL_CONNECTED) {
- DEBUG_WM("Already connected. Bailing out.");
+ DEBUG_WM(F("Already connected. Bailing out."));
return WL_CONNECTED;
}
//check if we have ssid and pass and force those, if not, try with last saved values
@@ -230,7 +292,7 @@ int WiFiManager::connectWifi(String ssid, String pass) {
WiFi.begin(ssid.c_str(), pass.c_str());
} else {
if (WiFi.SSID()) {
- DEBUG_WM("Using last saved values, should be faster");
+ DEBUG_WM(F("Using last saved values, should be faster"));
//trying to fix connection in progress hanging
ETS_UART_INTR_DISABLE();
wifi_station_disconnect();
@@ -238,7 +300,7 @@ int WiFiManager::connectWifi(String ssid, String pass) {
WiFi.begin();
} else {
- DEBUG_WM("No saved credentials");
+ DEBUG_WM(F("No saved credentials"));
}
}
@@ -246,11 +308,13 @@ int WiFiManager::connectWifi(String ssid, String pass) {
DEBUG_WM ("Connection result: ");
DEBUG_WM ( connRes );
//not connected, WPS enabled, no pass - first attempt
+ #ifdef NO_EXTRA_4K_HEAP
if (_tryWPS && connRes != WL_CONNECTED && pass == "") {
startWPS();
//should be connected at the end of WPS
connRes = waitForConnectResult();
}
+ #endif
return connRes;
}
@@ -278,9 +342,9 @@ uint8_t WiFiManager::waitForConnectResult() {
}
void WiFiManager::startWPS() {
- DEBUG_WM("START WPS");
+ DEBUG_WM(F("START WPS"));
WiFi.beginWPSConfig();
- DEBUG_WM("END WPS");
+ DEBUG_WM(F("END WPS"));
}
/*
String WiFiManager::getSSID() {
@@ -362,13 +426,14 @@ void WiFiManager::handleRoot() {
page += FPSTR(HTTP_STYLE);
page += _customHeadElement;
page += FPSTR(HTTP_HEAD_END);
- page += "";
+ page += String(F(""));
page += _apName;
- page += "
";
- page += F("WiFiManager
");
+ page += String(F("
"));
+ page += String(F("WiFiManager
"));
page += FPSTR(HTTP_PORTAL_OPTIONS);
page += FPSTR(HTTP_END);
+ server->sendHeader("Content-Length", String(page.length()));
server->send(200, "text/html", page);
}
@@ -459,7 +524,7 @@ void WiFiManager::handleWifi(boolean scan) {
}
page += FPSTR(HTTP_FORM_START);
- char parLength[2];
+ char parLength[5];
// add the extra parameters to the form
for (int i = 0; i < _paramsCount; i++) {
if (_params[i] == NULL) {
@@ -471,7 +536,7 @@ void WiFiManager::handleWifi(boolean scan) {
pitem.replace("{i}", _params[i]->getID());
pitem.replace("{n}", _params[i]->getID());
pitem.replace("{p}", _params[i]->getPlaceholder());
- snprintf(parLength, 2, "%d", _params[i]->getValueLength());
+ snprintf(parLength, 5, "%d", _params[i]->getValueLength());
pitem.replace("{l}", parLength);
pitem.replace("{v}", _params[i]->getValue());
pitem.replace("{c}", _params[i]->getCustomHTML());
@@ -522,6 +587,7 @@ void WiFiManager::handleWifi(boolean scan) {
page += FPSTR(HTTP_END);
+ server->sendHeader("Content-Length", String(page.length()));
server->send(200, "text/html", page);
@@ -544,7 +610,7 @@ void WiFiManager::handleWifiSave() {
//read parameter
String value = server->arg(_params[i]->getID()).c_str();
//store it in array
- value.toCharArray(_params[i]->_value, _params[i]->_length);
+ value.toCharArray(_params[i]->_value, _params[i]->_length + 1);
DEBUG_WM(F("Parameter"));
DEBUG_WM(_params[i]->getID());
DEBUG_WM(value);
@@ -579,6 +645,7 @@ void WiFiManager::handleWifiSave() {
page += FPSTR(HTTP_SAVED);
page += FPSTR(HTTP_END);
+ server->sendHeader("Content-Length", String(page.length()));
server->send(200, "text/html", page);
DEBUG_WM(F("Sent wifi save page"));
@@ -621,6 +688,7 @@ void WiFiManager::handleInfo() {
page += F("");
page += FPSTR(HTTP_END);
+ server->sendHeader("Content-Length", String(page.length()));
server->send(200, "text/html", page);
DEBUG_WM(F("Sent info page"));
@@ -638,6 +706,8 @@ void WiFiManager::handleReset() {
page += FPSTR(HTTP_HEAD_END);
page += F("Module will reset in a few seconds.");
page += FPSTR(HTTP_END);
+
+ server->sendHeader("Content-Length", String(page.length()));
server->send(200, "text/html", page);
DEBUG_WM(F("Sent reset page"));
@@ -646,17 +716,6 @@ void WiFiManager::handleReset() {
delay(2000);
}
-
-
-//removed as mentioned here https://github.com/tzapu/WiFiManager/issues/114
-/*void WiFiManager::handle204() {
- DEBUG_WM(F("204 No Response"));
- server->sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
- server->sendHeader("Pragma", "no-cache");
- server->sendHeader("Expires", "-1");
- server->send ( 204, "text/plain", "");
-}*/
-
void WiFiManager::handleNotFound() {
if (captivePortal()) { // If captive portal redirect instead of displaying the error page.
return;
@@ -676,6 +735,7 @@ void WiFiManager::handleNotFound() {
server->sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
server->sendHeader("Pragma", "no-cache");
server->sendHeader("Expires", "-1");
+ server->sendHeader("Content-Length", String(message.length()));
server->send ( 404, "text/plain", message );
}
@@ -737,7 +797,7 @@ int WiFiManager::getRSSIasQuality(int RSSI) {
/** Is this an IP? */
boolean WiFiManager::isIp(String str) {
- for (int i = 0; i < str.length(); i++) {
+ for (size_t i = 0; i < str.length(); i++) {
int c = str.charAt(i);
if (c != '.' && (c < '0' || c > '9')) {
return false;
diff --git a/lib/WiFiManager/WiFiManager.h b/lib/WiFiManager/WiFiManager.h
index 827c985..3da163e 100644
--- a/lib/WiFiManager/WiFiManager.h
+++ b/lib/WiFiManager/WiFiManager.h
@@ -5,7 +5,7 @@
inspired by:
http://www.esp8266.com/viewtopic.php?f=29&t=2520
https://github.com/chriscook8/esp-arduino-apboot
- https://github.com/esp8266/Arduino/tree/esp8266/hardware/esp8266com/esp8266/libraries/DNSServer/examples/CaptivePortalAdvanced
+ https://github.com/esp8266/Arduino/tree/master/libraries/DNSServer/examples/CaptivePortalAdvanced
Built by AlexT https://github.com/tzapu
Licensed under MIT license
**************************************************************/
@@ -29,19 +29,26 @@ const char HTTP_HEAD_END[] PROGMEM = "{v} {r}%
";
const char HTTP_FORM_START[] PROGMEM = "";
const char HTTP_SCAN_LINK[] PROGMEM = "
";
const char HTTP_SAVED[] PROGMEM = "Credentials Saved
Trying to connect ESP to network.
If it fails reconnect to AP to try again
";
const char HTTP_END[] PROGMEM = "