@@ -208,6 +208,74 @@ STATIC mp_obj_t esp_ifconfig(mp_obj_t self_in) {
208208}
209209STATIC MP_DEFINE_CONST_FUN_OBJ_1 (esp_ifconfig_obj , esp_ifconfig );
210210
211+ STATIC mp_obj_t esp_config (size_t n_args , const mp_obj_t * args , mp_map_t * kwargs ) {
212+ if (n_args != 1 && kwargs -> used != 0 ) {
213+ nlr_raise (mp_obj_new_exception_msg (& mp_type_TypeError ,
214+ "either pos or kw args are allowed" ));
215+ }
216+
217+ wlan_if_obj_t * self = MP_OBJ_TO_PTR (args [0 ]);
218+ union {
219+ struct station_config sta ;
220+ struct softap_config ap ;
221+ } cfg ;
222+
223+ if (self -> if_id == STATION_IF ) {
224+ error_check (wifi_station_get_config (& cfg .sta ), "can't get STA config" );
225+ } else {
226+ error_check (wifi_softap_get_config (& cfg .ap ), "can't get AP config" );
227+ }
228+
229+ if (kwargs -> used != 0 ) {
230+
231+ for (mp_uint_t i = 0 ; i < kwargs -> alloc ; i ++ ) {
232+ if (MP_MAP_SLOT_IS_FILLED (kwargs , i )) {
233+ #define QS (x ) (uintptr_t)MP_OBJ_NEW_QSTR(x)
234+ switch ((uintptr_t )kwargs -> table [i ].key ) {
235+ case QS (MP_QSTR_essid ): {
236+ mp_uint_t len ;
237+ const char * s = mp_obj_str_get_data (kwargs -> table [i ].value , & len );
238+ len = MIN (len , sizeof (cfg .ap .ssid ));
239+ memcpy (cfg .ap .ssid , s , len );
240+ cfg .ap .ssid_len = len ;
241+ break ;
242+ }
243+ default :
244+ goto unknown ;
245+ }
246+ #undef QS
247+ }
248+ }
249+
250+ if (self -> if_id == STATION_IF ) {
251+ error_check (wifi_station_set_config (& cfg .sta ), "can't set STA config" );
252+ } else {
253+ error_check (wifi_softap_set_config (& cfg .ap ), "can't set AP config" );
254+ }
255+
256+ return mp_const_none ;
257+ }
258+
259+ // Get config
260+
261+ if (n_args != 2 ) {
262+ nlr_raise (mp_obj_new_exception_msg (& mp_type_TypeError ,
263+ "can query only one param" ));
264+ }
265+
266+ #define QS (x ) (uintptr_t)MP_OBJ_NEW_QSTR(x)
267+ switch ((uintptr_t )args [1 ]) {
268+ case QS (MP_QSTR_essid ):
269+ return mp_obj_new_str ((char * )cfg .ap .ssid , cfg .ap .ssid_len , false);
270+ }
271+ #undef QS
272+
273+ unknown :
274+ nlr_raise (mp_obj_new_exception_msg (& mp_type_ValueError ,
275+ "unknown config param" ));
276+ }
277+ STATIC MP_DEFINE_CONST_FUN_OBJ_KW (esp_config_obj , 1 , esp_config );
278+
211279STATIC const mp_map_elem_t wlan_if_locals_dict_table [] = {
212280 { MP_OBJ_NEW_QSTR (MP_QSTR_active ), (mp_obj_t )& esp_active_obj },
213281 { MP_OBJ_NEW_QSTR (MP_QSTR_connect ), (mp_obj_t )& esp_connect_obj },
@@ -216,6 +284,7 @@ STATIC const mp_map_elem_t wlan_if_locals_dict_table[] = {
216284 { MP_OBJ_NEW_QSTR (MP_QSTR_scan ), (mp_obj_t )& esp_scan_obj },
217285 { MP_OBJ_NEW_QSTR (MP_QSTR_isconnected ), (mp_obj_t )& esp_isconnected_obj },
218286 { MP_OBJ_NEW_QSTR (MP_QSTR_mac ), (mp_obj_t )& esp_mac_obj },
287+ { MP_OBJ_NEW_QSTR (MP_QSTR_config ), (mp_obj_t )& esp_config_obj },
219288 { MP_OBJ_NEW_QSTR (MP_QSTR_ifconfig ), (mp_obj_t )& esp_ifconfig_obj },
220289};
221290
0 commit comments