8000 #179 · tsaitsai/esp32-snippets@a7066c3 · GitHub
[go: up one dir, main page]

Skip to content

Commit a7066c3

Browse files
committed
1 parent 371d9f7 commit a7066c3

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

cpp_utils/I2C.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ uint8_t I2C::getAddress() const
9797
*/
9898
void I2C::init(uint8_t address, gpio_num_t sdaPin, gpio_num_t sclPin, uint32_t clockSpeed, i2c_port_t portNum) {
9999
ESP_LOGD(LOG_TAG, ">> I2c::init. address=%d, sda=%d, scl=%d, clockSpeed=%d, portNum=%d", address, sdaPin, sclPin, clockSpeed, portNum);
100-
asser(portNum < I2C_NUM_MAX);
100+
assert(portNum < I2C_NUM_MAX);
101101
m_portNum = portNum;
102102
m_sdaPin = sdaPin;
103103
m_sclPin = sclPin;

cpp_utils/WiFi.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,15 @@ void WiFi::connectAP(const std::string& ssid, const std::string& password, bool
187187
abort();
188188
}
189189

190-
m_gotIpEvt.take("connectAP");
190+
m_connectFinished.take("connectAP"); // Take the semaphore to wait for a connection.
191+
191192
errRc = ::esp_wifi_connect();
192193
if (errRc != ESP_OK) {
193194
ESP_LOGE(LOG_TAG, "esp_wifi_connect: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
194195
abort();
195196
}
196-
m_gotIpEvt.wait("connectAP");
197+
198+
m_connectFinished.wait("connectAP"); // Wait for the completion of the connection.
197199
ESP_LOGD(LOG_TAG, "<< connectAP");
198200
} // connectAP
199201

@@ -226,11 +228,12 @@ void WiFi::dump() {
226228
// Invoke the event handler.
227229
esp_err_t rc = pWiFi->m_pWifiEventHandler->getEventHandler()(pWiFi->m_pWifiEventHandler, event);
228230

229-
// If the event we received indicates that we now have an IP address then unlock the mutex that
230-
// indicates we are waiting for an IP.
231-
if (event->event_id == SYSTEM_EVENT_STA_GOT_IP) {
232-
pWiFi->m_gotIpEvt.give();
231+
// If the event we received indicates that we now have an IP address or that a connection was disconnected then unlock the mutex that
232+
// indicates we are waiting for a connection complete.
233+
if (event->event_id == SYSTEM_EVENT_STA_GOT_IP || event->event_id == SYSTEM_EVENT_STA_DISCONNECTED) {
234+
pWiFi->m_connectFinished.give();
233235
}
236+
234237
return rc;
235238
} // eventHandler
236239

cpp_utils/WiFi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class WiFi {
114114
uint8_t m_dnsCount=0;
115115
bool m_eventLoopStarted;
116116
bool m_initCalled;
117-
FreeRTOS::Semaphore m_gotIpEvt = FreeRTOS::Semaphore("GotIpEvt");
117+
FreeRTOS::Semaphore m_connectFinished = FreeRTOS::Semaphore("ConnectFinished");
118118

119119
public:
120120
WiFi();

0 commit comments

Comments
 (0)
0