Code:
// Use primary serial over USB interface for logging output
SerialLogHandler logHandler(LOG_LEVEL_ALL, { // Logging level for non-application messages
{ "app", LOG_LEVEL_ALL } // Logging level for application messages
});
// polling interval
const long interval = 2000;
// setup() runs once, when the device is first turned on.
void setup() {
// Put initialization like pinMode and begin functions here.
// Format text message
Log.info("System version: %s", (const char*)System.version());
}
unsigned long lastTime = 0;
// loop() runs over and over again, as quickly as it can execute.
void loop() {
// The core of your code will likely live here.
unsigned long now = System.millis();
if ((now - lastTime) >= interval) {
lastTime = now;
while (!WiFi.ready()) {
Particle.process();
}
Log.trace("Wifi available");
Log.info("ip: %s", WiFi.localIP().toString().c_str());
Log.info("subnet: %s", WiFi.subnetMask().toString().c_str());
Log.info("gateway: %s", WiFi.gatewayIP().toString().c_str());
Log.info("Pinging started...");
IPAddress remoteIP(8, 8, 8, 8);
remoteIP = WiFi.resolve("www.google.com");
if(remoteIP) {
// IP address was resolved
Log.info("ip address: %s", remoteIP.toString().c_str());
int numberOfReceivedPackage = WiFi.ping(remoteIP, 10);
Log.info("ping res=%d", numberOfReceivedPackage);
} else {
// name resolution failed
Log.error("Resolution failed");
}
}
}