@@ -75,6 +75,7 @@ ESP8266::ESP8266(PinName tx, PinName rx, bool debug, PinName rts, PinName cts)
75
75
_parser.oob (" ALREADY CONNECTED" , callback (this , &ESP8266::_oob_conn_already));
76
76
_parser.oob (" ERROR" , callback (this , &ESP8266::_oob_err));
77
77
_parser.oob (" ready" , callback (this , &ESP8266::_oob_ready));
78
+ _parser.oob (" +CWLAP:" , callback (this , &ESP8266::_oob_scan_results));
78
79
// Don't expect to find anything about the watchdog reset in official documentation
79
80
// https://techtutorialsx.com/2017/01/21/esp8266-watchdog-functions/
80
81
_parser.oob (" wdt reset" , callback (this , &ESP8266::_oob_watchdog_reset));
@@ -446,27 +447,25 @@ int8_t ESP8266::rssi()
446
447
447
448
int ESP8266::scan (WiFiAccessPoint *res, unsigned limit)
448
449
{
449
- unsigned cnt = 0 ;
450
- nsapi_wifi_ap_t ap;
451
-
452
450
_smutex.lock ();
453
- set_timeout (ESP8266_CONNECT_TIMEOUT);
454
451
455
- if (!_parser.send (" AT+CWLAP" )) {
456
- _smutex.unlock ();
457
- return NSAPI_ERROR_DEVICE_ERROR;
458
- }
452
+ set_timeout (ESP8266_CONNECT_TIMEOUT);
459
453
460
- while (_recv_ap (&ap)) {
461
- if (cnt < limit) {
462
- res[cnt] = WiFiAccessPoint (ap);
463
- }
454
+ _scan_r.res = res;
455
+ _scan_r.limit = limit;
456
+ _scan_r.cnt = 0 ;
464
457
465
- cnt++;
466
- if (limit != 0 && cnt >= limit) {
467
- break ;
458
+ if (!(_parser.send (" AT+CWLAP" ) && _parser.recv (" OK\n " ))) {
459
+ tr_warning (" scan(): AP info parsing aborted" );
460
+ // Lets be happy about partial success and not return NSAPI_ERROR_DEVICE_ERROR
461
+ if (!_scan_r.cnt ) {
462
+ _scan_r.cnt = NSAPI_ERROR_DEVICE_ERROR;
468
463
}
469
464
}
465
+
466
+ int cnt = _scan_r.cnt ;
467
+ _scan_r.res = NULL ;
468
+
470
469
set_timeout ();
471
470
_smutex.unlock ();
472
471
@@ -966,7 +965,7 @@ void ESP8266::attach(Callback<void()> status_cb)
966
965
967
966
bool ESP8266::_recv_ap (nsapi_wifi_ap_t *ap)
968
967
{
969
- int sec;
968
+ int sec = NSAPI_SECURITY_UNKNOWN ;
970
969
int dummy;
971
970
bool ret;
972
971
@@ -992,7 +991,11 @@ bool ESP8266::_recv_ap(nsapi_wifi_ap_t *ap)
992
991
&ap->channel ,
993
992
&dummy,
994
993
&dummy);
994
+ }
995
995
996
+ if (!ret) {
997
+ _parser.abort ();
998
+ tr_warning (" _recv_ap(): AP info missing" );
996
999
}
997
1000
998
1001
ap->security = sec < 5 ? (nsapi_security_t )sec : NSAPI_SECURITY_UNKNOWN;
@@ -1063,6 +1066,19 @@ void ESP8266::_oob_tcp_data_hdlr()
1063
1066
_sock_i[_sock_active_id].tcp_data_rcvd = len;
1064
1067
}
1065
1068
1069
+ void ESP8266::_oob_scan_results ()
1070
+ {
1071
+ nsapi_wifi_ap_t ap;
1072
+
1073
+ if (_recv_ap (&ap)) {
1074
+ if (_scan_r.res && _scan_r.cnt < _scan_r.limit ) {
1075
+ _scan_r.res [_scan_r.cnt ] = WiFiAccessPoint (ap);
1076
+ }
1077
+
1078
+ _scan_r.cnt ++;
1079
+ }
1080
+ }
1081
+
1066
1082
void ESP8266::_oob_connect_err ()
1067
1083
{
1068
1084
_fail = false ;
0 commit comments