Page 1 of 1

How to reconnect to idf_monitor.py after sleep?

Posted: Sun Dec 28, 2025 1:19 pm
by wifitier
I use VS Code together with ESP-IDF 5.5 and ESP VS-Extension to program an ESP32-H2. I use

Code: Select all

esp_light_sleep_start()
to save power in inactive states. When the ESP is sent to sleep, the USB-CDC connection to idf_monitor.py get's lost, which is pretty understandable, because the USB port is powered down as well. But how can i get the idf monitor to automatically reconnect as soon as the ESP woke up again?
When i restart the monitor (by clicking on the monitor-symbol in the lower taskpane of VS Code) this will RESET the ESP, which is not what i want. But also after the wakeup the USB-CDC is not working anymore until a hardware reset. I think i need to reactivate it somehow? ChatGPT told me to do it this way:

Code: Select all

void reinit_usb_cdc() {
    // USB-CDC neu initialisieren nach Sleep
    usb_serial_jtag_driver_config_t usb_serial_config = {
        .rx_buffer_size = 1024,
        .tx_buffer_size = 1024,
    };
    
    // Kurz warten für USB Enumeration
    vTaskDelay(pdMS_TO_TICKS(100));
    
    usb_serial_jtag_driver_install(&usb_serial_config);
    esp_vfs_usb_serial_jtag_use_driver();
    
    vTaskDelay(pdMS_TO_TICKS(500)); // Zeit für Verbindungsaufbau
}
But as AI often lies, what do you suggest?

Re: How to reconnect to idf_monitor.py after sleep?

Posted: Mon Dec 29, 2025 2:44 pm
by technicalsquirrel
Using the VSCode extension I found it automatically tries to reconnect.