RSSI getter fixed for ESP8266

pull/11304/head
Antti Kauppila 2019-08-23 12:20:21 +03:00
parent 2c3ce9629e
commit a074721d18
1 changed files with 16 additions and 5 deletions

View File

@ -427,7 +427,7 @@ const char *ESP8266::netmask()
int8_t ESP8266::rssi()
{
int8_t rssi;
int8_t rssi = 0;
char bssid[18];
_smutex.lock();
@ -438,17 +438,27 @@ int8_t ESP8266::rssi()
_smutex.unlock();
return 0;
}
set_timeout();
_smutex.unlock();
WiFiAccessPoint ap[1];
_scan_r.res = ap;
_scan_r.limit = 1;
_scan_r.cnt = 0;
_smutex.lock();
set_timeout(ESP8266_CONNECT_TIMEOUT);
if (!(_parser.send("AT+CWLAP=\"\",\"%s\",", bssid)
&& _parser.recv("+CWLAP:(%*d,\"%*[^\"]\",%hhd,", &rssi)
&& _parser.recv("OK\n"))) {
_smutex.unlock();
return 0;
&& _parser.recv("OK\n"))) {
rssi = 0;
} else if(_scan_r.cnt == 1) {
//All OK so read and return rssi
rssi = ap[0].get_rssi();
}
_scan_r.cnt = 0;
_scan_r.res = NULL;
set_timeout();
_smutex.unlock();
@ -482,6 +492,7 @@ int ESP8266::scan(WiFiAccessPoint *res, unsigned limit, scan_mode mode, unsigned
}
}
int cnt = _scan_r.cnt;
_scan_r.res = NULL;