Skip to content

Commit f323d99

Browse files
committed
Changes for #389
1 parent 4a2f74c commit f323d99

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

cpp_utils/WiFi.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,20 @@ WiFi::WiFi()
5454
{
5555
m_eventLoopStarted = false;
5656
m_initCalled = false;
57-
m_pWifiEventHandler = new WiFiEventHandler();
57+
//m_pWifiEventHandler = new WiFiEventHandler();
5858
m_apConnected = false; // Are we connected to an access point?
5959
} // WiFi
6060

61+
6162
/**
6263
* @brief Deletes the event handler that was used by the class
6364
*/
6465
WiFi::~WiFi() {
65-
delete m_pWifiEventHandler;
66-
}
66+
if (m_pWifiEventHandler != nullptr) {
67+
delete m_pWifiEventHandler;
68+
m_pWifiEventHandler = nullptr;
69+
}
70+
} // ~WiFi
6771

6872

6973
/**
@@ -229,7 +233,12 @@ void WiFi::dump() {
229233
WiFi *pWiFi = (WiFi *)ctx; // retrieve the WiFi object from the passed in context.
230234

231235
// Invoke the event handler.
232-
esp_err_t rc = pWiFi->m_pWifiEventHandler->getEventHandler()(pWiFi->m_pWifiEventHandler, event);
236+
esp_err_t rc;
237+
if (pWiFi->m_pWifiEventHandler != nullptr) {
238+
rc = pWiFi->m_pWifiEventHandler->getEventHandler()(pWiFi->m_pWifiEventHandler, event);
239+
} else {
240+
rc = ESP_OK;
241+
}
233242

234243
// If the event we received indicates that we now have an IP address or that a connection was disconnected then unlock the mutex that
235244
// indicates we are waiting for a connection complete.

networking/bootwifi/BootWiFi.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,12 @@ class BootWifiEventHandler: public WiFiEventHandler {
253253
};
254254

255255

256+
/**
257+
* Boot WiFi
258+
*/
256259
void BootWiFi::bootWiFi2() {
257260
ESP_LOGD(LOG_TAG, ">> bootWiFi2");
261+
258262
// Check for a GPIO override which occurs when a physical Pin is high
259263
// during the test. This can force the ability to check for new configuration
260264
// even if the existing configured access point is available.
@@ -306,17 +310,22 @@ void BootWiFi::setAccessPointCredentials(std::string ssid, std::string password)
306310
} // setAccessPointCredentials
307311

308312

313+
314+
/**
315+
* @brief Main entry point into booting WiFi
316+
*/
309317
void BootWiFi::boot() {
310318
ESP_LOGD(LOG_TAG, ">> boot");
311319
ESP_LOGD(LOG_TAG, " +----------+");
312320
ESP_LOGD(LOG_TAG, " | BootWiFi |");
313321
ESP_LOGD(LOG_TAG, " +----------+");
314322
ESP_LOGD(LOG_TAG, " Access point credentials: %s/%s", m_ssid.c_str(), m_password.c_str());
315-
m_completeSemaphore.take("boot"); // Take the semaphore which will be unlocked when we complete booting.
323+
m_completeSemaphore.take("boot"); // Take the semaphore which will be unlocked when we complete booting.
316324
bootWiFi2();
317-
m_completeSemaphore.wait("boot"); // Wait for the semaphore that indicated we have completed booting.
325+
m_completeSemaphore.wait("boot"); // Wait for the semaphore that indicated we have completed booting.
326+
m_wifi.setWifiEventHandler(nullptr); // Remove the WiFi boot handler when we have completed booting.
318327
ESP_LOGD(LOG_TAG, "<< boot");
319-
}
328+
} // boot
320329

321330
BootWiFi::BootWiFi() {
322331
m_httpServerStarted = false;

0 commit comments

Comments
 (0)