Chapter 2. API Reference
(continued from previous page)
freeaddrinfo(res);
esp_ping_config_t ping_config = ESP_PING_DEFAULT_CONFIG();
ping_config.target_addr = target_addr; // target IP address
ping_config.count = ESP_PING_COUNT_INFINITE; // ping in infinite mode, esp_
,→ping_stop can stop it
/* set callback functions */
esp_ping_callbacks_t cbs;
cbs.on_ping_success = test_on_ping_success;
cbs.on_ping_timeout = test_on_ping_timeout;
cbs.on_ping_end = test_on_ping_end;
cbs.cb_args = "foo"; // arguments that will feed to all callback functions,␣
,→can be NULL
cbs.cb_args = eth_event_group;
esp_ping_handle_t ping;
esp_ping_new_session(&ping_config, &cbs, &ping);
}
Start and Stop ping session You can start and stop ping session with the handle returned by
esp_ping_new_session. Note that, the ping session won’t start automatically after creation. If the ping
session is stopped, and restart again, the sequence number in ICMP packets will recount from zero again.
Delete a ping session If a ping session won’t be used any more, you can delete it with
esp_ping_delete_session. Please make sure the ping session is in stop state (i.e. you have called
esp_ping_stop before or the ping session has finished all the procedures) when you call this function.
Get runtime statistics As the example code above, you can call esp_ping_get_profile to get different
runtime statistics of ping session in the callback function.
Application Example
ICMP echo example: protocols/icmp_echo
API Reference
Header File
• components/lwip/include/apps/ping/ping_sock.h
Functions
esp_err_t esp_ping_new_session(const esp_ping_config_t *config, const esp_ping_callbacks_t
*cbs, esp_ping_handle_t *hdl_out)
Create a ping session.
Return
• ESP_ERR_INVALID_ARG: invalid parameters (e.g. configuration is null, etc)
• ESP_ERR_NO_MEM: out of memory
• ESP_FAIL: other internal error (e.g. socket error)
• ESP_OK: create ping session successfully, user can take the ping handle to do follow-on jobs
Parameters
• config: ping configuration
• cbs: a bunch of callback functions invoked by internal ping task
• hdl_out: handle of ping session
Espressif Systems 597
Submit Document Feedback
Release v4.4