-
Notifications
You must be signed in to change notification settings - Fork 1
/
sourcecode.c
82 lines (63 loc) · 1.96 KB
/
sourcecode.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <ESP8266WiFi.h>
#include <ESP8266Ping.h>
//defining pins
//edit here if you want to add more LEDs
#define LED1 5 //(D5)
#define LED2 0 //(D3)
//Wi-Fi name and password
const char* ssid = "Y2kz";
const char* password = "Y2kz1234";
//whatever domain you like which responds to ICMP
const char* remote_host = "www.google.com";
String avg_time_ms;
int i;
//initial startup
void setup() {
//serial rate
Serial.begin(115200);
//pinMode edit here if you want to add more
//you can set multiple LEDs for different ping rate
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
delay(1);
Serial.println();
Serial.println("Connecting to WiFi");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print("."); //just wait :(
}
Serial.println();
Serial.print("WiFi connected with ip "); // Just a pre message
Serial.println(WiFi.localIP());
Serial.print("Pinging host "); // Just a pre message
Serial.println(remote_host);
}
//loop
void loop() {
if (Ping.ping(remote_host))
{
Ping.ping(remote_host, 10); //10 time ping to google, You can change value to higher or lower
i = Ping.averageTime();
avg_time_ms = Ping.averageTime();
Serial.println(i);
if (i > 1 && i < 900) // change here for offline timeout ping period
{
digitalWrite(LED1, LOW); //clearing the pre state condition
digitalWrite(LED2, LOW); //edit if you add more pins
delay(1);
digitalWrite(LED2, HIGH);
Serial.print(" Internet condition Online "); //online serial output :)
}
//add more conditions here - if you want multiple ping level
}
else
{
Serial.println("Error :( "); // :(
digitalWrite(LED1, LOW); //clearing the pre state condition
digitalWrite(LED2, LOW); //edit if you add more pins
delay(1);
digitalWrite(LED1, HIGH);
Serial.print(" Internet condition Offline "); //offline serial output :(
}
}