Ping#
The Ping component implements a ping service using the ICMPv6 protocol. It can send ICMPv6 Echo Request, receive corresponding responses, and calculate round-trip latency.
Applications can emit a single ping packet using the sl_wisun_ping_request() API. To receive the pong response, the sl_wisun_ping_response() API is called. The sl_wisun_ping() function offers a straightforward solution for periodic ping packet transmission and reception. To halt the process, use the sl_wisun_ping_stop() function.
Ping test parameters such as size, number of pings sent, and timeout for response absence are configurable. Initialization of the component is done by calling the sl_wisun_ping_init() function.
The following example demonstrates how the ping request can be called:
#include "sl_wisun_ping.h"
static void ping_remote(void) {
int32_t ret = 0;
sockaddr_in6_t remote_addr = { 0 };
sl_status_t status = SL_STATUS_FAIL;
// Create address structure from ping
ret = inet_pton(AF_INET6,
"2001:db8::1",
&remote_addr.sin6_addr);
if (ret != 1) {
// Error handling
return;
}
// Send and receive ping requests and responses
status = sl_wisun_ping(&remote_addr, // Ping remote_addr IPv6 address
10, // with 10 packets
512, // packet length is 512 bytes
NULL, // Custom statitistic handler is not required
NULL); // Request/Response handler is not required
if (status != SL_STATUS_OK) {
// Error handling
return;
}
}