conflict when using esp-modem and ethernet or wifi

timboesp
Posts: 18
Joined: Fri Apr 26, 2019 6:24 pm

conflict when using esp-modem and ethernet or wifi

Postby timboesp » Tue May 16, 2023 6:41 am

Hi,
I'm trying to program my ESP32 to have wifi, ethernet, and PPPoE connection with a SIM7600. However, my design is based on two
different examples, one for wifi/ethernet connections and other for cellular modem PPPoE, I get a conflict and I have apparently not
coded them to work at the same time. I can connect over wifi, or ethernet or both fine. I can also get the cellular modem to connect to the internet by itself fine. However mixing wifi or ethernet with cellular causes an error:

Code: Select all

ESP_ERROR_CHECK failed: esp_err_t 0x103 (ESP_ERR_INVALID_STATE) at 0x400897f0
Please help me understand what I'm missing in terms of making the eth_start(), wifi_start() from connect.c also work with the modem_setup() for the modem.

All my code builds on Ubuntu 22.04 using esp-idf v4.4, running on the ESP32 4G LTE Gateway board. This board has an Ethernet as well as SIM7600G.

Using an example from [PCBArtists][/https://pcbartists.com/product/esp32-4g ... eway-gen1/] for their ESP32 4G LTE Gateway board
I am able to connect to the internet. See an extract below of the function that sets up the modem connection over PPPoE. This example relies on esp-modem managed component.

My ethernet/wifi connection code is taken from espressif's v4.4 esp-idf installation ~/esp/esp-idf/examples/common_components/protocol_examples_common/connect.c, functions eth_start() and wifi_start(), or start()

Please help.

Code: Select all


static esp_modem_dce_t *dce;
static esp_netif_t *esp_netif;

void modem_setup (void) {
    ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, &on_ip_event, NULL));
    ESP_ERROR_CHECK(esp_event_handler_register(NETIF_PPP_STATUS, ESP_EVENT_ANY_ID, &on_ppp_changed, NULL));

    /* Configure the PPP netif */
    esp_modem_dce_config_t dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG("1nce.com");
    esp_netif_config_t netif_ppp_config = ESP_NETIF_DEFAULT_PPP();
    esp_netif = esp_netif_new(&netif_ppp_config);
    assert(esp_netif);

    event_group = xEventGroupCreate();

    /* Configure the DTE */
    esp_modem_dte_config_t dte_config = ESP_MODEM_DTE_DEFAULT_CONFIG();
    /* setup UART specific configuration based on kconfig options */
        dte_config.uart_config.tx_io_num = MODEM_UART_TX_PIN;
        dte_config.uart_config.rx_io_num = MODEM_UART_RX_PIN;
        dte_config.uart_config.rts_io_num = MODEM_UART_RTS_PIN;
        dte_config.uart_config.cts_io_num = MODEM_UART_CTS_PIN;
        dte_config.uart_config.flow_control = FLOW_CONTROL;
        dte_config.uart_config.rx_buffer_size = MODEM_UART_RX_BUFFER_SIZE;
        dte_config.uart_config.tx_buffer_size = MODEM_UART_TX_BUFFER_SIZE;
        dte_config.uart_config.event_queue_size = MODEM_UART_EVENT_QUEUE_SIZE;
        dte_config.task_stack_size = MODEM_UART_EVENT_TASK_STACK_SIZE;
        dte_config.task_priority = MODEM_UART_EVENT_TASK_PRIORITY;
        dte_config.dte_buffer_size = MODEM_UART_RX_BUFFER_SIZE / 2;

    ESP_LOGI(TAG, "Initializing esp_modem for the SIM7600 module...");
    dce = esp_modem_new_dev(ESP_MODEM_DCE_SIM7600, &dte_config, &dce_config, esp_netif);
    assert(dce);

    xEventGroupClearBits(event_group, MODEM_CONNECT_BIT | MODEM_GOT_DATA_BIT | USB_DISCONNECTED_BIT);

    int rssi, ber;
    esp_err_t err = esp_modem_get_signal_quality(dce, &rssi, &ber);
    if (err != ESP_OK) {
        ESP_LOGE(TAG, "esp_modem_get_signal_quality failed with %d %s", err, esp_err_to_name(err));
        return;
    }
    ESP_LOGI(TAG, "Signal quality: rssi=%d, ber=%d", rssi, ber);

    err = esp_modem_set_mode(dce, ESP_MODEM_MODE_DATA);
    if (err != ESP_OK) {
        ESP_LOGE(TAG, "esp_modem_set_mode(ESP_MODEM_MODE_DATA) failed with %d", err);
        return;
    }

    ESP_LOGI(TAGSIM7600, "Waiting for IP address");
    xEventGroupWaitBits (event_group, MODEM_CONNECT_BIT, pdFALSE, pdFALSE, portMAX_DELAY);
}

Who is online

Users browsing this forum: No registered users and 189 guests