How to ping to all three interfaces- ethernet,GSM and Wifi-sta
Posted: Fri Apr 28, 2023 6:07 am
Hello plz help me to ping at IP "8.8.8.8" from three interfaces.
I have tried with the following code
but that gives be error of ping handle being null
void ping_all_interfaces()
{
// Get the interface keys
uint32_t a32InterfaceKey[3];
uint8_t u8KeyIndex = 0U;
esp_netif_t *ifscan = esp_netif_next(NULL);
while (ifscan != NULL && u8KeyIndex < 3) {
a32InterfaceKey[u8KeyIndex++] = (uint32_t) esp_netif_get_ifkey(ifscan);
ifscan = esp_netif_next(ifscan);
}
// Set the target address
ip_addr_t target_addr;
memset(&target_addr, 0, sizeof(target_addr));
struct in_addr addr;
inet_pton(AF_INET, "8.8.8.8", &addr);
inet_addr_to_ip4addr(ip_2_ip4(&target_addr), &addr);
// Create ping sessions for all three interfaces
for (int i = 0; i < 3; i++) {
esp_ping_config_t ping_config = ESP_PING_DEFAULT_CONFIG();
ping_config.target_addr = target_addr;
ping_config.count = ESP_PING_COUNT_INFINITE;
ping_config.interface = &a32InterfaceKey;
esp_ping_handle_t ping;
esp_ping_callbacks_t cbs;
cbs.on_ping_success = on_ping_success;
cbs.on_ping_timeout = on_ping_timeout;
cbs.on_ping_end = on_ping_end;
cbs.cb_args = NULL;
if (esp_ping_new_session(&ping_config, &cbs, &ping) == ESP_OK) {
if (esp_ping_start(ping) == ESP_OK) {
ESP_LOGI(TAG, "Started ping session for interface %d", i);
} else {
ESP_LOGE(TAG, "Failed to start ping session for interface %d", i);
}
} else {
ESP_LOGE(TAG, "Failed to create ping session for interface %d", i);
}
}
}
the moment I remove the " ping_config.interface = &a32InterfaceKey; " from the code it is working
Please help me ASAP
I have tried with the following code
but that gives be error of ping handle being null
void ping_all_interfaces()
{
// Get the interface keys
uint32_t a32InterfaceKey[3];
uint8_t u8KeyIndex = 0U;
esp_netif_t *ifscan = esp_netif_next(NULL);
while (ifscan != NULL && u8KeyIndex < 3) {
a32InterfaceKey[u8KeyIndex++] = (uint32_t) esp_netif_get_ifkey(ifscan);
ifscan = esp_netif_next(ifscan);
}
// Set the target address
ip_addr_t target_addr;
memset(&target_addr, 0, sizeof(target_addr));
struct in_addr addr;
inet_pton(AF_INET, "8.8.8.8", &addr);
inet_addr_to_ip4addr(ip_2_ip4(&target_addr), &addr);
// Create ping sessions for all three interfaces
for (int i = 0; i < 3; i++) {
esp_ping_config_t ping_config = ESP_PING_DEFAULT_CONFIG();
ping_config.target_addr = target_addr;
ping_config.count = ESP_PING_COUNT_INFINITE;
ping_config.interface = &a32InterfaceKey;
esp_ping_handle_t ping;
esp_ping_callbacks_t cbs;
cbs.on_ping_success = on_ping_success;
cbs.on_ping_timeout = on_ping_timeout;
cbs.on_ping_end = on_ping_end;
cbs.cb_args = NULL;
if (esp_ping_new_session(&ping_config, &cbs, &ping) == ESP_OK) {
if (esp_ping_start(ping) == ESP_OK) {
ESP_LOGI(TAG, "Started ping session for interface %d", i);
} else {
ESP_LOGE(TAG, "Failed to start ping session for interface %d", i);
}
} else {
ESP_LOGE(TAG, "Failed to create ping session for interface %d", i);
}
}
}
the moment I remove the " ping_config.interface = &a32InterfaceKey; " from the code it is working
Please help me ASAP