8000 esp8266/modnetwork: Implement WLAN.status('rssi') for STA interface. · micropython/micropython@c5fe610 · GitHub
[go: up one dir, main page]

Skip to content

Commit c5fe610

Browse files
committed
esp8266/modnetwork: Implement WLAN.status('rssi') for STA interface.
This will return the RSSI of the AP that the STA is connected to.
1 parent 01dcd5b commit c5fe610

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

docs/library/network.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,11 @@ parameter should be `id`.
383383
* 0 -- visible
384384
* 1 -- hidden
385385

386-
.. method:: wlan.status()
386+
.. method:: wlan.status([param])
387387

388388
Return the current status of the wireless connection.
389389

390+
When called with no argument the return value describes the network link status.
390391
The possible statuses are defined as constants:
391392

392393
* ``STAT_IDLE`` -- no connection and no activity,
@@ -396,6 +397,9 @@ parameter should be `id`.
396397
* ``STAT_CONNECT_FAIL`` -- failed due to other problems,
397398
* ``STAT_GOT_IP`` -- connection successful.
398399

400+
When called with one argument *param* should be a string naming the status
401+
parameter to retrieve. Supported parameters in WiFI STA mode are: ``'rssi'``.
402+
399403
.. method:: wlan.isconnected()
400404

401405
In case of STA mode, returns ``True`` if connected to a WiFi access

ports/esp8266/modnetwork.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,26 @@ STATIC mp_obj_t esp_disconnect(mp_obj_t self_in) {
150150
}
151151
STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_disconnect_obj, esp_disconnect);
152152

153-
STATIC mp_obj_t esp_status(mp_obj_t self_in) {
154-
wlan_if_obj_t *self = MP_OBJ_TO_PTR(self_in);
155-
if (self->if_id == STATION_IF) {
156-
return MP_OBJ_NEW_SMALL_INT(wifi_station_get_connect_status());
153+
STATIC mp_obj_t esp_status(size_t n_args, const mp_obj_t *args) {
154+
wlan_if_obj_t *self = MP_OBJ_TO_PTR(args[0]);
155+
if (n_args == 1) {
156+
// Get link status
157+
if (self->if_id == STATION_IF) {
158+
return MP_OBJ_NEW_SMALL_INT(wifi_station_get_connect_status());
159+
}
160+
return MP_OBJ_NEW_SMALL_INT(-1);
161+
} else {
162+
// Get specific status parameter
163+
switch (mp_obj_str_get_qstr(args[1])) {
164+
case MP_QSTR_rssi:
165+
if (self->if_id == STATION_IF) {
166+
return MP_OBJ_NEW_SMALL_INT(wifi_station_get_rssi());
167+
}
168+
}
169+
mp_raise_ValueError("unknown status param");
157170
}
158-
return MP_OBJ_NEW_SMALL_INT(-1);
159171
}
160-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_status_obj, esp_status);
172+
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_status_obj, 1, 2, esp_status);
161173

162174
STATIC mp_obj_t *esp_scan_list = NULL;
163175

0 commit comments

Comments
 (0)
0