Skip to content

Commit

Permalink
Merge pull request #11304 from AnttiKauppila/esp8266_fix
Browse files Browse the repository at this point in the history
RSSI getter fixed for ESP8266
  • Loading branch information
0xc0170 authored Aug 29, 2019
2 parents 4d2078e + 2bdf3bb commit 56a8227
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions components/wifi/esp8266-driver/ESP8266/ESP8266.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ const char *ESP8266::netmask()

int8_t ESP8266::rssi()
{
int8_t rssi;
int8_t rssi = 0;
char bssid[18];

_smutex.lock();
Expand All @@ -437,17 +437,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;
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();

Expand Down Expand Up @@ -481,6 +491,7 @@ int ESP8266::scan(WiFiAccessPoint *res, unsigned limit, scan_mode mode, unsigned
}
}


int cnt = _scan_r.cnt;
_scan_r.res = NULL;

Expand Down

0 comments on commit 56a8227

Please sign in to comment.