@@ -204,6 +204,20 @@ STATIC void require_if(mp_obj_t wlan_if, int if_no) {
204
204
}
205
205
206
206
STATIC mp_obj_t get_wlan (size_t n_args , const mp_obj_t * args ) {
207
+ static int initialized = 0 ;
208
+ if (!initialized ) {
209
+ ESP_LOGD ("modnetwork" , "esp_event_loop_init done" );
210
+ wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT ();
211
+ ESP_LOGD ("modnetwork" , "Initializing WiFi" );
212
+ ESP_EXCEPTIONS ( esp_wifi_init (& cfg ) );
213
+ ESP_EXCEPTIONS ( esp_wifi_set_storage (WIFI_STORAGE_RAM ) );
214
+ ESP_LOGD ("modnetwork" , "Initialized" );
215
+ ESP_EXCEPTIONS ( esp_wifi_set_mode (0 ) );
216
+ ESP_EXCEPTIONS ( esp_wifi_start () );
217
+ ESP_LOGD ("modnetwork" , "Started" );
218
+ initialized = 1 ;
219
+ }
220
+
207
221
int idx = (
D9A5
n_args > 0 ) ? mp_obj_get_int (args [0 ]) : WIFI_IF_STA ;
208
222
if (idx == WIFI_IF_STA ) {
209
223
return MP_OBJ_FROM_PTR (& wlan_sta_obj );
@@ -284,7 +298,7 @@ STATIC mp_obj_t get_lan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
284
298
lan_if_obj_t * self = MP_OBJ_TO_PTR (& lan_obj );
285
299
286
300
if (self -> initialized ) {
287
- mp_raise_msg ( & mp_type_OSError , "ethernet already initialized" );
301
+ return MP_OBJ_FROM_PTR ( & lan_obj );
288
302
}
289
303
290
304
enum { ARG_id , ARG_mdc , ARG_mdio , ARG_power , ARG_phy_addr , ARG_phy_type };
@@ -345,15 +359,6 @@ STATIC mp_obj_t esp_initialize() {
345
359
tcpip_adapter_init ();
346
360
ESP_LOGD ("modnetwork" , "Initializing Event Loop" );
347
361
ESP_EXCEPTIONS ( esp_event_loop_init (event_handler , NULL ) );
348
- ESP_LOGD ("modnetwork" , "esp_event_loop_init done" );
349
- wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT ();
350
- ESP_LOGD ("modnetwork" , "Initializing WiFi" );
351
- ESP_EXCEPTIONS ( esp_wifi_init (& cfg ) );
352
- ESP_EXCEPTIONS ( esp_wifi_set_storage (WIFI_STORAGE_RAM ) );
353
- ESP_LOGD ("modnetwork" , "Initialized" );
354
- ESP_EXCEPTIONS ( esp_wifi_set_mode (0 ) );
355
- ESP_EXCEPTIONS ( esp_wifi_start () );
356
- ESP_LOGD ("modnetwork" , "Started" );
357
362
initialized = 1 ;
358
363
}
359
364
return mp_const_none ;
0 commit comments