Continuous Network/ Server Tester with Arduino Uno with WiFi

You can use an Arduino Uno with WiFi to constantly check on the ping response from servers and networked devices.

Libraries Required for this Demonstration:

  • Adafruit SSD1306
  • Adafruit GFX

Note: Remember to change the I2C address within the example sketch.

Functional Parts in the Project:

#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <WiFiNINA.h>

#define greenLED 8
#define redLED 9

#define OLED_WIDTH 128
#define OLED_HEIGHT 64
#define OLED_ADDR   0x3C

Adafruit_SSD1306 display(OLED_WIDTH, OLED_HEIGHT);

char ssid[] = "test";
char pass[] = "";

int status = WL_IDLE_STATUS;

String google = "www.google.com";
String salesforce = "www.salesforce.com";
IPAddress localServer(172, 16, 42, 5);

int googleResult;
int salesforceResult;
int serverResult;
int gatewayResult;

void setup() {
  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);

  Serial.begin(9600);
  display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);

  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to Network named: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);
    delay(10000);
  }

  String ssid = WiFi.SSID();
  IPAddress ip = WiFi.localIP();
  IPAddress gateway = WiFi.gatewayIP();
  IPAddress subnet = WiFi.subnetMask();

  display.clearDisplay();

  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  display.println("Net Tester");

  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 17);
  display.print("SSID:   ");
  display.println(ssid);
  display.print("IP:     ");
  display.println(ip);
  display.print("Subnet: ");
  display.println(subnet);
  display.print("Gateway:");
  display.println(gateway);

  display.display();

  delay(5000);
}

void loop() {

  IPAddress gateway = WiFi.gatewayIP();
  googleResult = WiFi.ping(google);
  salesforceResult = WiFi.ping(salesforce);
  serverResult = WiFi.ping(localServer);
  gatewayResult = WiFi.ping(gateway);
  long counter = millis();

  display.clearDisplay();

  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  display.println("Net Tester");

  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 17);
  display.print("Gateway:   ");
  display.println(gatewayResult);
  display.print("Local Server:   ");
  display.println(serverResult);
  display.print("Google:   ");
  display.println(googleResult);
  display.print("Salesforce:   ");
  display.println(salesforceResult);
  display.println(counter);

  display.display();

  if (gatewayResult < 0 || serverResult < 0 || googleResult < 0 || salesforceResult < 0) {
    digitalWrite(greenLED, LOW);
    digitalWrite(redLED, HIGH);
  } else {
    digitalWrite(greenLED, HIGH);
    digitalWrite(redLED, LOW);
  }

  delay(5000);
}

Be the first to comment

Leave a Reply