You can ping servers by domain name or IP address and use the response time as a value for a variable.
Functional Parts in the Project:
- Arduino WiFi Rev 2 – https://store.arduino.cc/usa/arduino-uno-wifi-rev2
#include <WiFiNINA.h>
char ssid[] = "test";
char pass[] = "";
int status = WL_IDLE_STATUS;
String hostName = "www.google.com";
IPAddress localServer(172, 16, 42, 5);
int googleResult;
int serverResult;
void setup() {
Serial.begin(9600);
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to Network named: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
delay(10000);
}
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
}
void loop() {
googleResult = WiFi.ping(hostName);
serverResult = WiFi.ping(localServer);
Serial.print("Google.com: ");
Serial.println(googleResult);
Serial.print("Local Server: ");
Serial.println(serverResult);
delay(2000);
}
Be the first to comment