File tree 2 files changed +23
-7
lines changed 2 files changed +23
-7
lines changed Original file line number Diff line number Diff line change @@ -383,10 +383,11 @@ parameter should be `id`.
383
383
* 0 -- visible
384
384
* 1 -- hidden
385
385
386
- .. method :: wlan.status()
386
+ .. method :: wlan.status([param] )
387
387
388
388
Return the current status of the wireless connection.
389
389
390
+ When called with no argument the return value describes the network link status.
390
391
The possible statuses are defined as constants:
391
392
392
393
* ``STAT_IDLE `` -- no connection and no activity,
@@ -396,6 +397,9 @@ parameter should be `id`.
396
397
* ``STAT_CONNECT_FAIL `` -- failed due to other problems,
397
398
* ``STAT_GOT_IP `` -- connection successful.
398
399
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
+
399
403
.. method :: wlan.isconnected()
400
404
401
405
In case of STA mode, returns ``True `` if connected to a WiFi access
Original file line number Diff line number Diff line change @@ -150,14 +150,26 @@ STATIC mp_obj_t esp_disconnect(mp_obj_t self_in) {
150
150
}
151
151
STATIC MP_DEFINE_CONST_FUN_OBJ_1 (esp_disconnect_obj , esp_disconnect );
152
152
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" );
157
170
}
158
- return MP_OBJ_NEW_SMALL_INT (-1 );
159
171
}
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 );
161
173
162
174
STATIC mp_obj_t * esp_scan_list = NULL ;
163
175
You can’t perform that action at this time.
0 commit comments