1
1
/*
2
2
TLS WiFi Web client
3
3
4
- Remember to update the CA certificates using CertificateUploader sketch
5
- before using this sketch.
4
+ Board CA Root certificate bundle is embedded inside WiFi firmware:
5
+ https://github.com/arduino/uno-r4-wifi-usb-bridge/blob/main/certificates/cacrt_all.pem
6
6
7
7
Find the full UNO R4 WiFi Network documentation here:
8
8
https://docs.arduino.cc/tutorials/uno-r4-wifi/wifi-examples#wi-fi-web-client-ssl
12
12
#include " WiFiSSLClient.h"
13
13
#include " IPAddress.h"
14
14
15
- #include " arduino_secrets.h"
15
+ #include " arduino_secrets.h"
16
16
17
17
// /////please enter your sensitive data in the Secret tab/arduino_secrets.h
18
18
char ssid[] = SECRET_SSID; // your network SSID (name)
@@ -31,41 +31,41 @@ WiFiSSLClient client;
31
31
32
32
/* -------------------------------------------------------------------------- */
33
33
void setup () {
34
- /* -------------------------------------------------------------------------- */
34
+ /* -------------------------------------------------------------------------- */
35
35
// Initialize serial and wait for port to open:
36
36
Serial.begin (115200 );
37
37
while (!Serial) {
38
38
; // wait for serial port to connect. Needed for native USB port only
39
39
}
40
-
40
+
41
41
// check for the WiFi module:
42
42
if (WiFi.status () == WL_NO_MODULE) {
43
43
Serial.println (" Communication with WiFi module failed!" );
44
44
// don't continue
45
45
while (true );
46
46
}
47
-
47
+
48
48
String fv = WiFi.firmwareVersion ();
49
49
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
50
50
Serial.println (" Please upgrade the firmware" );
51
51
}
52
-
52
+
53
53
// attempt to connect to WiFi network:
54
54
while (status != WL_CONNECTED) {
55
55
Serial.print (" Attempting to connect to SSID: " );
56
56
Serial.println (ssid);
57
57
// Connect to WPA/WPA2 network.
58
58
status = WiFi.begin (ssid, pass);
59
-
59
+
60
60
// wait 10 seconds for connection:
61
61
delay (10000 );
62
62
}
63
-
63
+
64
64
printWifiStatus ();
65
-
65
+
66
66
Serial.println (" \n Starting connection to server..." );
67
67
// if you get a connection, report back via serial:
68
-
68
+
69
69
if (client.connect (server, 443 )) {
70
70
Serial.println (" connected to server" );
71
71
// Make a HTTP request:
@@ -79,7 +79,7 @@ void setup() {
79
79
/* just wrap the received data up to 80 columns in the serial print*/
80
80
/* -------------------------------------------------------------------------- */
81
81
void read_response () {
82
- /* -------------------------------------------------------------------------- */
82
+ /* -------------------------------------------------------------------------- */
83
83
uint32_t received_data_num = 0 ;
84
84
while (client.available ()) {
85
85
/* actual data reception */
@@ -88,15 +88,15 @@ void read_response() {
88
88
Serial.print (c);
89
89
/* wrap data to 80 columns*/
90
90
received_data_num++;
91
- if (received_data_num % 80 == 0 ) {
91
+ if (received_data_num % 80 == 0 ) {
92
92
Serial.println ();
93
93
}
94
- }
94
+ }
95
95
}
96
96
97
97
/* -------------------------------------------------------------------------- */
98
98
void loop () {
99
- /* -------------------------------------------------------------------------- */
99
+ /* -------------------------------------------------------------------------- */
100
100
read_response ();
101
101
102
102
// if the server's disconnected, stop the client:
@@ -112,7 +112,7 @@ void loop() {
112
112
113
113
/* -------------------------------------------------------------------------- */
114
114
void printWifiStatus () {
115
- /* -------------------------------------------------------------------------- */
115
+ /* -------------------------------------------------------------------------- */
116
116
// print the SSID of the network you're attached to:
117
117
Serial.print (" SSID: " );
118
118
Serial.println (WiFi.SSID ());
0 commit comments