WIfi STA and PPPoS client coexistance

sGuitton85
Posts: 5
Joined: Tue Aug 03, 2021 8:25 am

WIfi STA and PPPoS client coexistance

Postby sGuitton85 » Tue Aug 03, 2021 8:57 am

Hi all,

I am trying to make an application where Wifi STA and PPPoS client are coexisting, when I need a to send a HTTP request, it should be sent by the interface which is connected and has IP if only one is connected or to send it by the one which is has the priority when both are connected.

For now I am able to send my request with each interface when I initialize only this interface. Though when I init both interfaces, my requests are not successfully sent even though the interfaces are connected and has IP, also if only LTE is connected it also does not work.

I must do something wrong in my init.

Here's my Wifi STA init :
esp_err_t wifi_init(void)
{

// Initialize wifi reconnection timer
{
const esp_timer_create_args_t wifi_reconnection_timer_args = {
.callback = wifi_reconnection_timer_callback,
.arg = (void *)&wifi_reconnection_timer,
.name = "wifi-reconnection",
};
ESP_ERROR_CHECK(esp_timer_create(&wifi_reconnection_timer_args, &wifi_reconnection_timer));
};

// Initialize SNTP
{
if (setenv("TZ", "CET-1CEST,M3.5.0,M10.5.0/3", true) == -1)
{
ESP_LOGE(SNTP_TAG, "setenv failed with %d !", errno);
ESP_ERROR_CHECK(ESP_FAIL);
}
tzset();

sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setservername(0, SNTP_SERVER_ADDR);
sntp_set_time_sync_notification_cb(on_time_sync);
sntp_set_sync_mode(SNTP_SYNC_MODE_IMMED);
sntp_set_sync_interval(SNTP_SYNC_INTERVAL_MS);
sntp_init();

ESP_ERROR_CHECK(print_date_time());
};

ESP_ERROR_CHECK(esp_netif_init());

{
esp_err_t ret = esp_event_loop_create_default();
switch (ret)
{
case ESP_OK:
case ESP_ERR_INVALID_STATE:
break;

default:
ESP_ERROR_CHECK(ret);
}
}

static esp_netif_t *esp_netif = NULL;
esp_netif = esp_netif_create_default_wifi_sta();

{
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
};

#if false
// Restore factory settings
ESP_ERROR_CHECK(esp_wifi_restore());
#endif

{
static esp_event_handler_instance_t wifi_event_handler_instance;
static esp_event_handler_instance_t ip_event_handler_instance;
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
ESP_EVENT_ANY_ID,
&wifi_event_handler,
(void *)esp_netif,
&wifi_event_handler_instance));
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
IP_EVENT_STA_GOT_IP,
&wifi_event_handler,
(void *)esp_netif,
&ip_event_handler_instance));
};

ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));

// Get and set configuration
{
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_FLASH));

wifi_config_t wifi_config;
ESP_ERROR_CHECK(esp_wifi_get_config(ESP_IF_WIFI_STA, &wifi_config));

ESP_LOGI(WIFI_TAG, "SSID: %.*s (%d)\tPASSWORD: %.*s (%d)", WIFI_SSID_MAX_LEN, wifi_config.sta.ssid, strlen((const char *)wifi_config.sta.ssid), WIFI_PASSWORD_MAX_LEN, wifi_config.sta.password, strlen((const char *)wifi_config.sta.password));

if (strlen((const char *)wifi_config.sta.ssid))
{
// Set the correct value in BLE service
ESP_ERROR_CHECK(ble_set_wifi_ssid(wifi_config.sta.ssid, strlen((const char *)wifi_config.sta.ssid)));
ESP_ERROR_CHECK(leds_set_color(LED_TYPE_CHARGE, LED_COLOR_GREEN));
}
else
{
ESP_ERROR_CHECK(leds_set_color(LED_TYPE_CHARGE, LED_COLOR_WHITE));
}

// From now on, everything is done in RAM only by default
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));

ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config));
};

return ESP_OK;
}


Here's my LTE init:
esp_err_t lte_init(void)
{
esp_log_level_set(LTE_TAG, ESP_LOG_DEBUG);

gpio_pad_select_gpio(ME310G1_PWRON_PIN);
gpio_pad_select_gpio(ME310G1_ON_OFF_PIN);

ESP_ERROR_CHECK(gpio_set_direction(ME310G1_PWRON_PIN, GPIO_MODE_INPUT));
ESP_ERROR_CHECK(gpio_set_direction(ME310G1_ON_OFF_PIN, GPIO_MODE_OUTPUT));

ESP_ERROR_CHECK(me310g1_power(false));
vTaskDelay(pdMS_TO_TICKS(1000));
ESP_ERROR_CHECK(me310g1_power(true));

ESP_ERROR_CHECK(esp_netif_init());
{
esp_err_t ret = esp_event_loop_create_default();
switch (ret)
{
case ESP_OK:
case ESP_ERR_INVALID_STATE:
break;

default:
ESP_ERROR_CHECK(ret);
}
}

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));

esp_modem_dte_config_t config = ESP_MODEM_DTE_DEFAULT_CONFIG();
config.port_num = LTE_UART_NUM;
config.tx_io_num = LTE_UART_TX_GPIO_NUM;
config.rx_io_num = LTE_UART_RX_GPIO_NUM;
config.rts_io_num = UART_PIN_NO_CHANGE;
config.cts_io_num = UART_PIN_NO_CHANGE;

modem_dte_t *dte = esp_modem_dte_init(&config);

ESP_ERROR_CHECK(esp_modem_set_event_handler(dte, modem_event_handler, ESP_EVENT_ANY_ID, NULL));

esp_netif_config_t cfg = ESP_NETIF_DEFAULT_PPP();
esp_netif_t *esp_netif = esp_netif_new(&cfg);
assert(esp_netif);

void *modem_netif_adapter = esp_modem_netif_setup(dte);
esp_modem_netif_set_default_handlers(modem_netif_adapter, esp_netif);

modem_dce_t *dce = me310g1_init(dte);
assert(dce != NULL);

ESP_ERROR_CHECK(dce->set_flow_ctrl(dce, MODEM_FLOW_CONTROL_NONE));
ESP_ERROR_CHECK(dce->store_profile(dce));

ESP_LOGI(LTE_TAG, "Module: %s", dce->name);
ESP_LOGI(LTE_TAG, "Operator: %s", dce->oper);
ESP_LOGI(LTE_TAG, "IMEI: %s", dce->imei);
ESP_LOGI(LTE_TAG, "IMSI: %s", dce->imsi);

uint32_t rssi = 0, ber = 0;
ESP_ERROR_CHECK(dce->get_signal_quality(dce, &rssi, &ber));
ESP_LOGI(LTE_TAG, "rssi: %d, ber: %d", rssi, ber);

esp_netif_attach(esp_netif, modem_netif_adapter);

return ESP_OK;
}


Why is it not working anymore when both are initialized?
How can I switch between interfaces?

sGuitton85
Posts: 5
Joined: Tue Aug 03, 2021 8:25 am

Re: WIfi STA and PPPoS client coexistance

Postby sGuitton85 » Tue Aug 03, 2021 10:10 am

FYI I am working with ESP_IDF release v4.3

sGuitton85
Posts: 5
Joined: Tue Aug 03, 2021 8:25 am

Re: WIfi STA and PPPoS client coexistance

Postby sGuitton85 » Tue Aug 03, 2021 3:43 pm

Actually it seems this is due to an memory issue as I get esp-tls: mbedtls_ssl_handshake returned -0x10 MBEDTLS_ERR_MPI_ALLOC_FAILED when sending the request and if I remove some feature I am able to send the request with both interfaces initialized.

Who is online

Users browsing this forum: Baidu [Spider], HighVoltage and 128 guests