Skip to content

Commit dc18ac7

Browse files
committed
Minor tweaks to WiFiPing example
1 parent a5bcc23 commit dc18ac7

File tree

1 file changed

+138
-138
lines changed

1 file changed

+138
-138
lines changed

examples/WiFiPing/WiFiPing.ino

Lines changed: 138 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,138 +1,138 @@
1-
/*
2-
3-
This example connects to a encrypted Wifi network (WPA/WPA2).
4-
Then it prints the MAC address of the Wifi shield,
5-
the IP address obtained, and other network details.
6-
Then it continuously pings given host specified by IP Address or name.
7-
8-
Circuit:
9-
* WiFi shield attached / MKR1000
10-
11-
created 13 July 2010
12-
by dlf (Metodo2 srl)
13-
modified 09 June 2016
14-
by Petar Georgiev
15-
*/
16-
#include <SPI.h>
17-
#include <WiFi101.h>
18-
19-
char ssid[] = "yourNetwork"; // your network SSID (name)
20-
char pass[] = "secretPassword"; // your network password
21-
int status = WL_IDLE_STATUS; // the Wifi radio's status
22-
23-
// Specify IP address or hostname
24-
String hostName = "www.google.com";
25-
int pingResult;
26-
27-
void setup() {
28-
// Initialize serial and wait for port to open:
29-
Serial.begin(9600);
30-
while (!Serial) {
31-
; // wait for serial port to connect. Needed for native USB port only
32-
}
33-
34-
// check for the presence of the shield:
35-
if (WiFi.status() == WL_NO_SHIELD) {
36-
Serial.println("WiFi shield not present");
37-
// don't continue:
38-
while (true);
39-
}
40-
41-
// attempt to connect to Wifi network:
42-
while ( status != WL_CONNECTED) {
43-
Serial.print("Attempting to connect to WPA SSID: ");
44-
Serial.println(ssid);
45-
// Connect to WPA/WPA2 network:
46-
status = WiFi.begin(ssid, pass);
47-
48-
// wait 5 seconds for connection:
49-
delay(5000);
50-
}
51-
52-
// you're connected now, so print out the data:
53-
Serial.print("You're connected to the network");
54-
printCurrentNet();
55-
printWifiData();
56-
57-
}
58-
59-
void loop() {
60-
Serial.print("Pinging ");
61-
Serial.print(hostName);
62-
Serial.print(": ");
63-
64-
pingResult = WiFi.ping(hostName);
65-
66-
if (pingResult >= 0) {
67-
Serial.print("SUCCESS! RTT = ");
68-
Serial.println(pingResult);
69-
} else {
70-
Serial.print("FAILED! Error code: ");
71-
Serial.println(pingResult);
72-
}
73-
74-
delay(1000);
75-
}
76-
77-
void printWifiData() {
78-
// print your WiFi shield's IP address:
79-
IPAddress ip = WiFi.localIP();
80-
Serial.print("IP address : ");
81-
Serial.println(ip);
82-
83-
Serial.print("Subnet mask: ");
84-
Serial.println((IPAddress)WiFi.subnetMask());
85-
86-
Serial.print("Gateway IP : ");
87-
Serial.println((IPAddress)WiFi.gatewayIP());
88-
89-
// print your MAC address:
90-
byte mac[6];
91-
WiFi.macAddress(mac);
92-
Serial.print("MAC address: ");
93-
Serial.print(mac[5], HEX);
94-
Serial.print(":");
95-
Serial.print(mac[4], HEX);
96-
Serial.print(":");
97-
Serial.print(mac[3], HEX);
98-
Serial.print(":");
99-
Serial.print(mac[2], HEX);
100-
Serial.print(":");
101-
Serial.print(mac[1], HEX);
102-
Serial.print(":");
103-
Serial.println(mac[0], HEX);
104-
Serial.println();
105-
}
106-
107-
void printCurrentNet() {
108-
// print the SSID of the network you're attached to:
109-
Serial.print("SSID: ");
110-
Serial.println(WiFi.SSID());
111-
112-
// print the MAC address of the router you're attached to:
113-
byte bssid[6];
114-
WiFi.BSSID(bssid);
115-
Serial.print("BSSID: ");
116-
Serial.print(bssid[5], HEX);
117-
Serial.print(":");
118-
Serial.print(bssid[4], HEX);
119-
Serial.print(":");
120-
Serial.print(bssid[3], HEX);
121-
Serial.print(":");
122-
Serial.print(bssid[2], HEX);
123-
Serial.print(":");
124-
Serial.print(bssid[1], HEX);
125-
Serial.print(":");
126-
Serial.println(bssid[0], HEX);
127-
128-
// print the received signal strength:
129-
long rssi = WiFi.RSSI();
130-
Serial.print("signal strength (RSSI): ");
131-
Serial.println(rssi);
132-
133-
// print the encryption type:
134-
byte encryption = WiFi.encryptionType();
135-
Serial.print("Encryption Type: ");
136-
Serial.println(encryption, HEX);
137-
Serial.println();
138-
}
1+
/*
2+
3+
This example connects to a encrypted Wifi network (WPA/WPA2).
4+
Then it prints the MAC address of the Wifi shield,
5+
the IP address obtained, and other network details.
6+
Then it continuously pings given host specified by IP Address or name.
7+
8+
Circuit:
9+
WiFi shield attached / MKR1000
10+
11+
created 13 July 2010
12+
by dlf (Metodo2 srl)
13+
modified 09 June 2016
14+
by Petar Georgiev
15+
*/
16+
#include <SPI.h>
17+
#include <WiFi101.h>
18+
19+
char ssid[] = "yourNetwork"; // your network SSID (name)
20+
char pass[] = "secretPassword"; // your network password
21+
int status = WL_IDLE_STATUS; // the Wifi radio's status
22+
23+
// Specify IP address or hostname
24+
String hostName = "www.google.com";
25+
int pingResult;
26+
27+
void setup() {
28+
// Initialize serial and wait for port to open:
29+
Serial.begin(9600);
30+
while (!Serial) {
31+
; // wait for serial port to connect. Needed for native USB port only
32+
}
33+
34+
// check for the presence of the shield:
35+
if (WiFi.status() == WL_NO_SHIELD) {
36+
Serial.println("WiFi shield not present");
37+
// don't continue:
38+
while (true);
39+
}
40+
41+
// attempt to connect to Wifi network:
42+
while ( status != WL_CONNECTED) {
43+
Serial.print("Attempting to connect to WPA SSID: ");
44+
Serial.println(ssid);
45+
// Connect to WPA/WPA2 network:
46+
status = WiFi.begin(ssid, pass);
47+
48+
// wait 5 seconds for connection:
49+
delay(5000);
50+
}
51+
52+
// you're connected now, so print out the data:
53+
Serial.println("You're connected to the network");
54+
printCurrentNet();
55+
printWifiData();
56+
}
57+
58+
void loop() {
59+
Serial.print("Pinging ");
60+
Serial.print(hostName);
61+
Serial.print(": ");
62+
63+
pingResult = WiFi.ping(hostName);
64+
65+
if (pingResult >= 0) {
66+
Serial.print("SUCCESS! RTT = ");
67+
Serial.print(pingResult);
68+
Serial.println(" ms");
69+
} else {
70+
Serial.print("FAILED! Error code: ");
71+
Serial.println(pingResult);
72+
}
73+
74+
delay(5000);
75+
}
76+
77+
void printWifiData() {
78+
// print your WiFi shield's IP address:
79+
IPAddress ip = WiFi.localIP();
80+
Serial.print("IP address : ");
81+
Serial.println(ip);
82+
83+
Serial.print("Subnet mask: ");
84+
Serial.println((IPAddress)WiFi.subnetMask());
85+
86+
Serial.print("Gateway IP : ");
87+
Serial.println((IPAddress)WiFi.gatewayIP());
88+
89+
// print your MAC address:
90+
byte mac[6];
91+
WiFi.macAddress(mac);
92+
Serial.print("MAC address: ");
93+
Serial.print(mac[5], HEX);
94+
Serial.print(":");
95+
Serial.print(mac[4], HEX);
96+
Serial.print(":");
97+
Serial.print(mac[3], HEX);
98+
Serial.print(":");
99+
Serial.print(mac[2], HEX);
100+
Serial.print(":");
101+
Serial.print(mac[1], HEX);
102+
Serial.print(":");
103+
Serial.println(mac[0], HEX);
104+
Serial.println();
105+
}
106+
107+
void printCurrentNet() {
108+
// print the SSID of the network you're attached to:
109+
Serial.print("SSID: ");
110+
Serial.println(WiFi.SSID());
111+
112+
// print the MAC address of the router you're attached to:
113+
byte bssid[6];
114+
WiFi.BSSID(bssid);
115+
Serial.print("BSSID: ");
116+
Serial.print(bssid[5], HEX);
117+
Serial.print(":");
118+
Serial.print(bssid[4], HEX);
119+
Serial.print(":");
120+
Serial.print(bssid[3], HEX);
121+
Serial.print(":");
122+
Serial.print(bssid[2], HEX);
123+
Serial.print(":");
124+
Serial.print(bssid[1], HEX);
125+
Serial.print(":");
126+
Serial.println(bssid[0], HEX);
127+
128+
// print the received signal strength:
129+
long rssi = WiFi.RSSI();
130+
Serial.print("signal strength (RSSI): ");
131+
Serial.println(rssi);
132+
133+
// print the encryption type:
134+
byte encryption = WiFi.encryptionType();
135+
Serial.print("Encryption Type: ");
136+
Serial.println(encryption, HEX);
137+
Serial.println();
138+
}

0 commit comments

Comments
 (0)