Network

ping() [Network]

Since 6.3.0:

Network.ping() allows you to ping an IP address and returns the number of packets received as an int or a negative error code.

This is an ICMP ping, not the Particle cloud ping and does not use data operations. It uses the default network, which is typically WiFi, Cellular, or Ethernet. If the default network is cellular it will use cellular data, so it should not be used excessively.

// PROTOTYPES
int ping(IPAddress remoteIP, unsigned nTries = 1, unsigned timeoutMs = DEFAULT_PING_TIMEOUT);
int ping(String hostname, unsigned nTries = 1, unsigned timeoutMs = DEFAULT_PING_TIMEOUT);
int ping(IPAddress remoteIP, std::chrono::milliseconds timeout, unsigned nTries = 1);
int ping(String hostname, std::chrono::milliseconds timeout, unsigned nTries = 1);

When using a hostname, a DNS lookup is done. If the hostname is not found, a negative result code (SYSTEM_ERROR_NOT_FOUND, -150) is returned.

The DEFAULT_PING_TIMEOUT is 4000 milliseconds (4 seconds).

These methods are only avaiable in Device OS 6.3.0 and later. They are available in the WiFi, Cellular, Ethernet, and Network classes.