8000 Updated examples · useful-esp8266-lib/ESP8266Ping@4e60144 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4e60144

Browse files
committed
Updated examples
1 parent fa9e355 commit 4e60144

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

examples/HostPing/HostPing.ino

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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() { }

examples/SimplePing/SimplePing.ino

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
const char* ssid = "ssid";
1010
const char* password = "passphrase";
1111

12-
const IPAddress ping_dest(192, 168, 0, 1);
12+
const IPAddress remote_ip(192, 168, 0, 1);
1313

1414
void setup() {
1515
Serial.begin(115200);
@@ -31,7 +31,10 @@ void setup() {
3131
Serial.print("WiFi connected with ip ");
3232
Serial.println(WiFi.localIP());
3333

34-
if(Ping.ping(ping_dest)) {
34+
Serial.print("Pinging ip ");
35+
Serial.println(remote_ip);
36+
37+
if(Ping.ping(remote_ip)) {
3538
Serial.println("Success!!");
3639
} else {
3740
Serial.println("Error :(");

0 commit comments

Comments
 (0)
0