summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/library/network.rst6
-rw-r--r--ports/esp8266/modnetwork.c24
2 files changed, 23 insertions, 7 deletions
diff --git a/docs/library/network.rst b/docs/library/network.rst
index a1190a574..a113209e0 100644
--- a/docs/library/network.rst
+++ b/docs/library/network.rst
@@ -383,10 +383,11 @@ parameter should be `id`.
* 0 -- visible
* 1 -- hidden
- .. method:: wlan.status()
+ .. method:: wlan.status([param])
Return the current status of the wireless connection.
+ When called with no argument the return value describes the network link status.
The possible statuses are defined as constants:
* ``STAT_IDLE`` -- no connection and no activity,
@@ -396,6 +397,9 @@ parameter should be `id`.
* ``STAT_CONNECT_FAIL`` -- failed due to other problems,
* ``STAT_GOT_IP`` -- connection successful.
+ When called with one argument *param* should be a string naming the status
+ parameter to retrieve. Supported parameters in WiFI STA mode are: ``'rssi'``.
+
.. method:: wlan.isconnected()
In case of STA mode, returns ``True`` if connected to a WiFi access
diff --git a/ports/esp8266/modnetwork.c b/ports/esp8266/modnetwork.c
index f7da5b751..00a84c446 100644
--- a/ports/esp8266/modnetwork.c
+++ b/ports/esp8266/modnetwork.c
@@ -150,14 +150,26 @@ STATIC mp_obj_t esp_disconnect(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_disconnect_obj, esp_disconnect);
-STATIC mp_obj_t esp_status(mp_obj_t self_in) {
- wlan_if_obj_t *self = MP_OBJ_TO_PTR(self_in);
- if (self->if_id == STATION_IF) {
- return MP_OBJ_NEW_SMALL_INT(wifi_station_get_connect_status());
+STATIC mp_obj_t esp_status(size_t n_args, const mp_obj_t *args) {
+ wlan_if_obj_t *self = MP_OBJ_TO_PTR(args[0]);
+ if (n_args == 1) {
+ // Get link status
+ if (self->if_id == STATION_IF) {
+ return MP_OBJ_NEW_SMALL_INT(wifi_station_get_connect_status());
+ }
+ return MP_OBJ_NEW_SMALL_INT(-1);
+ } else {
+ // Get specific status parameter
+ switch (mp_obj_str_get_qstr(args[1])) {
+ case MP_QSTR_rssi:
+ if (self->if_id == STATION_IF) {
+ return MP_OBJ_NEW_SMALL_INT(wifi_station_get_rssi());
+ }
+ }
+ mp_raise_ValueError("unknown status param");
}
- return MP_OBJ_NEW_SMALL_INT(-1);
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp_status_obj, esp_status);
+STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(esp_status_obj, 1, 2, esp_status);
STATIC mp_obj_t *esp_scan_list = NULL;