44 lines
811 B
C++
44 lines
811 B
C++
/*
|
|
* This example show how to ping a remote machine using it's hostname
|
|
*/
|
|
|
|
#include <WiFi.h>
|
|
#include <ESP32Ping.h>
|
|
|
|
const char* ssid = "ssid";
|
|
const char* password = "passphrase";
|
|
|
|
const char* remote_host = "www.google.com";
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
delay(10);
|
|
|
|
// We start by connecting to a WiFi network
|
|
|
|
Serial.println();
|
|
Serial.println("Connecting to WiFi");
|
|
|
|
WiFi.begin(ssid, password);
|
|
|
|
while (WiFi.status() != WL_CONNECTED) {
|
|
delay(100);
|
|
Serial.print(".");
|
|
}
|
|
|
|
Serial.println();
|
|
Serial.print("WiFi connected with ip ");
|
|
Serial.println(WiFi.localIP());
|
|
|
|
Serial.print("Pinging host ");
|
|
Serial.println(remote_host);
|
|
|
|
if(Ping.ping(remote_host)) {
|
|
Serial.println("Success!!");
|
|
} else {
|
|
Serial.println("Error :(");
|
|
}
|
|
}
|
|
|
|
void loop() { }
|