Ping a Web Server with an ESP8266

Description: A Wemos Lolin D1 Mini Pro V2 pings a website to check to see if it’s status is Online or Offline. If the website is Online the green LED will light up and if it’s Offline the red will light up.

Ping a Web Server with an ESP8266

Notes: Download and install the ESP8266Ping Library from Github or from within the Library Manager in the Arduino IDE. Make sure to replace “Network Name” and “Password” in the code below with your WiFi network. Also, set the baud rate to 9600 in the Serial Monitor.

Serial Monitor - Ping a Web Server

Supplies:

1 –  Breadboard 400 Points
1 – Wemos Lolin D1 Mini Pro V2
2 – LEDs
1 – 220 Ohm Resistor

Arduino Code:

#include <ESP8266WiFi.h>
#include <ESP8266Ping.h>

#define LED_Green 12
#define LED_Red 16

const char* ssid     = "Network Name";
const char* password = "Password";

const char* remote_host = "tropicalengineer.com";

void setup() {

  pinMode(LED_Green, OUTPUT);
  pinMode(LED_Red, OUTPUT);
  
  Serial.begin(9600);
  delay(10);

  Serial.println("");
  Serial.println("");
  Serial.println("Connecting to WiFi");
  
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    
    delay(100);
    Serial.print(".");
    
  }

  Serial.println("");
  Serial.print("Local IP Address: ");  
  Serial.print(WiFi.localIP());

  Serial.println("");
  Serial.print("Pinging: ");
  Serial.print(remote_host);
  Serial.println("");
  Serial.println("");

}

void loop() { 
  
    if(Ping.ping(remote_host)) {
    Serial.println("Online");
    delay(1000);
    digitalWrite(LED_Green, HIGH);
    digitalWrite(LED_Red, LOW);
    
  } else {
    
    Serial.println("Offline");
    delay(1000);
    digitalWrite(LED_Green, LOW);
    digitalWrite(LED_Red, HIGH);
    
  }
}

Leave a Comment

− 5 = 4