File tree Expand file tree Collapse file tree 2 files changed +48
-2
lines changed Expand file tree Collapse file tree 2 files changed +48
-2
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * This example show how to ping a remote machine using it's hostname
3
+ */
4
+
5
+ #include < ESP8266WiFi.h>
6
+ #include < ESP8266Ping.h>
7
+
8
+ const char * ssid = " ssid" ;
9
+ const char * password = " passphrase" ;
10
+
11
+ const char * remote_host = " www.google.com" ;
12
+
13
+ void setup () {
14
+ Serial.begin (115200 );
15
+ delay (10 );
16
+
17
+ // We start by connecting to a WiFi network
18
+
19
+ Serial.println ();
20
+ Serial.println (" Connecting to WiFi" );
21
+
22
+ WiFi.begin (ssid, password);
23
+
24
+ while (WiFi.status () != WL_CONNECTED) {
25
+ delay (100 );
26
+ Serial.print (" ." );
27
+ }
28
+
29
+ Serial.println ();
30
+ Serial.print (" WiFi connected with ip " );
31
+ Serial.println (WiFi.localIP ());
32
+
33
+ Serial.print (" Pinging host " );
34
+ Serial.println (remote_host);
35
+
36
+ if (Ping.ping (remote_host)) {
37
+ Serial.println (" Success!!" );
38
+ } else {
39
+ Serial.println (" Error :(" );
40
+ }
41
+ }
42
+
43
+ void loop () { }
Original file line number Diff line number Diff line change 9
9
const char * ssid = " ssid" ;
10
10
const char * password = " passphrase" ;
11
11
12
- const IPAddress ping_dest (192 , 168 , 0 , 1 );
12
+ const IPAddress remote_ip (192 , 168 , 0 , 1 );
13
13
14
14
void setup () {
15
15
Serial.begin (115200 );
@@ -31,7 +31,10 @@ void setup() {
31
31
Serial.print (" WiFi connected with ip " );
32
32
Serial.println (WiFi.localIP ());
33
33
34
- if (Ping.ping (ping_dest)) {
34
+ Serial.print (" Pinging ip " );
35
+ Serial.println (remote_ip);
36
+
37
+ if (Ping.ping (remote_ip)) {
35
38
Serial.println (" Success!!" );
36
39
} else {
37
40
Serial.println (" Error :(" );
You can’t perform that action at this time.
0 commit comments