1
-
2
1
/*
3
2
Web client
4
3
5
- This sketch connects to a website (http://www.google.com)
6
- using the WiFi module.
7
-
8
- This example is written for a network using WPA encryption. For
9
- WEP or WPA, change the Wifi.begin() call accordingly.
4
+ This sketch connects to a website (http://example.com) using the WiFi module.
10
5
11
6
This example is written for a network using WPA encryption. For
12
7
WEP or WPA, change the Wifi.begin() call accordingly.
13
8
14
9
Circuit:
15
- * Board with NINA module ( Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2)
10
+ * Arduino Portenta H7
16
11
17
12
created 13 July 2010
18
13
by dlf (Metodo2 srl)
19
14
modified 31 May 2012
20
15
by Tom Igoe
21
16
*/
22
17
23
-
24
- #include < SPI.h>
25
- #include < WiFiNINA.h>
18
+ #include < WiFi.h>
26
19
27
20
#include " arduino_secrets.h"
28
21
// /////please enter your sensitive data in the Secret tab/arduino_secrets.h
29
22
char ssid[] = SECRET_SSID; // your network SSID (name)
30
- char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
31
- int keyIndex = 0 ; // your network key Index number (needed only for WEP)
23
+ char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
24
+ int keyIndex = 0 ; // your network key Index number (needed only for WEP)
32
25
33
26
int status = WL_IDLE_STATUS;
34
27
// if you don't want to use DNS (and reduce your sketch size)
35
28
// use the numeric IP instead of the name for the server:
36
- // IPAddress server(74,125,232,128 ); // numeric IP for Google (no DNS)
37
- char server[] = " www.google. com" ; // name address for Google (using DNS)
29
+ // IPAddress server(93,184,216,34 ); // IP address for example.com (no DNS)
30
+ char server[] = " example. com" ; // host name for example.com (using DNS)
38
31
39
- // Initialize the Ethernet client library
40
- // with the IP address and port of the server
41
- // that you want to connect to (port 80 is default for HTTP):
42
32
WiFiClient client;
43
33
44
34
void setup () {
@@ -49,26 +39,21 @@ void setup() {
49
39
}
50
40
51
41
// check for the WiFi module:
52
- if (WiFi.status () == WL_NO_MODULE ) {
42
+ if (WiFi.status () == WL_NO_SHIELD ) {
53
43
Serial.println (" Communication with WiFi module failed!" );
54
44
// don't continue
55
45
while (true );
56
46
}
57
47
58
- String fv = WiFi.firmwareVersion ();
59
- if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
60
- Serial.println (" Please upgrade the firmware" );
61
- }
62
-
63
48
// attempt to connect to Wifi network:
64
49
while (status != WL_CONNECTED) {
65
50
Serial.print (" Attempting to connect to SSID: " );
66
51
Serial.println (ssid);
67
52
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
68
53
status = WiFi.begin (ssid, pass);
69
54
70
- // wait 10 seconds for connection:
71
- delay (10000 );
55
+ // wait 3 seconds for connection:
56
+ delay (3000 );
72
57
}
73
58
Serial.println (" Connected to wifi" );
74
59
printWifiStatus ();
@@ -78,8 +63,9 @@ void setup() {
78
63
if (client.connect (server, 80 )) {
79
64
Serial.println (" connected to server" );
80
65
// Make a HTTP request:
81
- client.println (" GET /search?q=arduino HTTP/1.1" );
82
- client.println (" Host: www.google.com" );
66
+ client.println (" GET /index.html HTTP/1.1" );
67
+ client.print (" Host: " );
68
+ client.println (server);
83
69
client.println (" Connection: close" );
84
70
client.println ();
85
71
}
@@ -104,7 +90,6 @@ void loop() {
104
90
}
105
91
}
106
92
107
-
108
93
void printWifiStatus () {
109
94
// print the SSID of the network you're attached to:
110
95
Serial.print (" SSID: " );
0 commit comments