@@ -57,6 +57,8 @@ extern "C" {
57
57
#include " sdkconfig.h"
58
58
59
59
static esp_netif_t *esp_netifs[ESP_IF_MAX] = {NULL , NULL , NULL };
60
+ // a static handle for event callback
61
+ static network_event_handle_t evt_handle{0 };
60
62
61
63
esp_netif_t *get_esp_interface_netif (esp_interface_t interface) {
62
64
if (interface < ESP_IF_MAX) {
@@ -67,7 +69,7 @@ esp_netif_t *get_esp_interface_netif(esp_interface_t interface) {
67
69
68
70
static void _arduino_event_cb (void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) {
69
71
arduino_event_t arduino_event;
70
- arduino_event.event_id = ARDUINO_EVENT_MAX ;
72
+ arduino_event.event_id = ARDUINO_EVENT_ANY ;
71
73
72
74
/*
73
75
* SCAN
@@ -163,7 +165,7 @@ static void _arduino_event_cb(void *arg, esp_event_base_t event_base, int32_t ev
163
165
#endif
164
166
}
165
167
166
- if (arduino_event.event_id < ARDUINO_EVENT_MAX ) {
168
+ if (arduino_event.event_id != ARDUINO_EVENT_ANY ) {
167
169
Network.postEvent (&arduino_event);
168
170
}
169
171
}
@@ -409,12 +411,13 @@ wifi_ps_type_t WiFiGenericClass::_sleepEnabled = WIFI_PS_MIN_MODEM;
409
411
410
412
WiFiGenericClass::WiFiGenericClass () {}
411
413
412
- const char *WiFiGenericClass::disconnectReasonName (wifi_err_reason_t reason) {
413
- return WiFi.STA .disconnectReasonName (reason);
414
+ WiFiGenericClass::~WiFiGenericClass (){
415
+ Network.removeEvent (evt_handle);
416
+ evt_handle = 0 ;
414
417
}
415
418
416
- const char *WiFiGenericClass::eventName ( arduino_event_id_t id ) {
417
- return Network. eventName (id );
419
+ const char *WiFiGenericClass::disconnectReasonName ( wifi_err_reason_t reason ) {
420
+ return WiFi. STA . disconnectReasonName (reason );
418
421
}
419
422
420
423
const char *WiFiGenericClass::getHostname () {
@@ -437,17 +440,18 @@ void WiFiGenericClass::_eventCallback(arduino_event_t *event) {
437
440
// log_d("Arduino Event: %d - %s", event->event_id, WiFi.eventName(event->event_id));
438
441
if (event->event_id == ARDUINO_EVENT_WIFI_SCAN_DONE) {
439
442
WiFiScanClass::_scanDone ();
443
+ }
440
444
#if !CONFIG_ESP_WIFI_REMOTE_ENABLED
441
- } else if (event->event_id == ARDUINO_EVENT_SC_GOT_SSID_PSWD) {
445
+ else if (event->event_id == ARDUINO_EVENT_SC_GOT_SSID_PSWD) {
442
446
WiFi.begin (
443
447
(const char *)event->event_info .sc_got_ssid_pswd .ssid , (const char *)event->event_info .sc_got_ssid_pswd .password , 0 ,
444
448
((event->event_info .sc_got_ssid_pswd .bssid_set == true ) ? event->event_info .sc_got_ssid_pswd .bssid : NULL )
445
449
);
446
450
} else if (event->event_id == ARDUINO_EVENT_SC_SEND_ACK_DONE) {
447
451
esp_smartconfig_stop ();
448
452
WiFiSTAClass::_smartConfigDone = true ;
449
- #endif
450
453
}
454
+ #endif
451
455
}
452
456
453
457
/* *
@@ -527,7 +531,8 @@ bool WiFiGenericClass::mode(wifi_mode_t m) {
527
531
if (!wifiLowLevelInit (_persistent)) {
528
532
return false ;
529
533
}
530
- Network.onSysEvent (_eventCallback);
534
+ if (!evt_handle)
535
+ evt_handle = Network.onSysEvent (_eventCallback);
531
536
}
532
537
533
538
if (((m & WIFI_MODE_STA) != 0 ) && ((cm & WIFI_MODE_STA) == 0 )) {
@@ -552,7 +557,8 @@ bool WiFiGenericClass::mode(wifi_mode_t m) {
552
557
// we are disabling AP interface
553
558
WiFi.AP .onDisable ();
554
559
}
555
- Network.removeEvent (_eventCallback);
560
+ Network.removeEvent (evt_handle);
561
+ evt_handle = 0 ;
556
562
return true ;
557
563
}
558
564
0 commit comments