@@ -44,35 +44,50 @@ int arduino::WiFiClass::begin(const char* ssid, const char *passphrase) {
44
44
45
45
int arduino::WiFiClass::beginAP (const char * ssid, const char *passphrase, uint8_t channel) {
46
46
47
- #if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4)
48
- _softAP = WhdSoftAPInterface::get_default_instance ();
49
- #endif
47
+ #if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4)
48
+ _softAP = WhdSoftAPInterface::get_default_instance ();
49
+ #endif
50
50
51
51
if (_softAP == NULL ) {
52
- return WL_AP_FAILED;
52
+ return (_currentNetworkStatus = WL_AP_FAILED) ;
53
53
}
54
54
55
55
ensureDefaultAPNetworkConfiguration ();
56
56
57
+ WhdSoftAPInterface* softAPInterface = static_cast <WhdSoftAPInterface*>(_softAP);
58
+
57
59
// Set ap ssid, password and channel
58
- static_cast <WhdSoftAPInterface*>(_softAP) ->set_network (_ip, _netmask, _gateway);
59
- nsapi_error_t result = static_cast <WhdSoftAPInterface*>(_softAP) ->start (ssid, passphrase, NSAPI_SECURITY_WPA2, channel, true /* dhcp server */ , NULL , true /* cohexistance */ );
60
+ softAPInterface ->set_network (_ip, _netmask, _gateway);
61
+ nsapi_error_t result = softAPInterface ->start (ssid, passphrase, NSAPI_SECURITY_WPA2, channel, true /* dhcp server */ , NULL , true /* cohexistance */ );
60
62
61
- static_cast <WhdSoftAPInterface*>(_softAP)->register_event_handler ([](whd_interface_t ifp, const whd_event_header_t *event_header, const uint8_t *event_data, void *handler_user_data) -> void *{
62
-
63
- if (event_header->event_type == 8 ){ // 8 = connect
64
- WiFi._currentNetworkStatus = WL_AP_CONNECTED;
65
- return nullptr ;
63
+ nsapi_error_t registrationResult;
64
+ softAPInterface->unregister_event_handler ();
65
+ registrationResult = softAPInterface->register_event_handler ([](whd_interface_t ifp, const whd_event_header_t *event_header, const uint8_t *event_data, void *handler_user_data) -> void *{
66
+
67
+ if (event_header->event_type == WLC_E_ASSOC_IND){
68
+ WiFi._currentNetworkStatus = WL_AP_CONNECTED;
69
+ } else if (event_header->event_type == WLC_E_DISASSOC_IND){
70
+ WiFi._currentNetworkStatus = WL_AP_LISTENING;
71
+ }
72
+
73
+ // Default Event Handler
74
+ if ((event_header->event_type == (whd_event_num_t )WLC_E_LINK) || (event_header->event_type == WLC_E_IF)) {
75
+ whd_driver_t whd_driver = ifp->whd_driver ;
76
+ if (osSemaphoreGetCount (whd_driver->ap_info .whd_wifi_sleep_flag ) < 1 ) {
77
+ osStatus_t result = osSemaphoreRelease (whd_driver->ap_info .whd_wifi_sleep_flag );
78
+ if (result != osOK) {
79
+ printf (" Release whd_wifi_sleep_flag ERROR: %d" , result);
80
+ }
81
+ }
66
82
}
67
83
68
- if (event_header->event_type == 12 ){ // 12 = disconnect
69
- WiFi._currentNetworkStatus = WL_AP_LISTENING;
70
- return nullptr ;
71
- }
72
-
73
- return nullptr ;
84
+ return handler_user_data;
74
85
});
75
86
87
+ if (registrationResult != NSAPI_ERROR_OK) {
88
+ return (_currentNetworkStatus = WL_AP_FAILED);
89
+ }
90
+
76
91
_currentNetworkStatus = (result == NSAPI_ERROR_OK && setSSID (ssid)) ? WL_AP_LISTENING : WL_AP_FAILED;
77
92
return _currentNetworkStatus;
78
93
}
0 commit comments