Examples for Arduino WiFi-enabled boards: MKR1000, MKR1010, Nano 33 IoT, Nano ESP, Uno Rev 4 WiFi, and others
Library Include line
Credentials Header file
WiFi Connection
Arduino HTTP Clients
HTTP Servers
TCP and UDP Examples
OSC Examples
ESP32 Examples
This project is maintained by tigoe
The examples listed below were written originally for the Nano ESP32 board, which has an ESP32-S3 processor, but they have also been tested on the Seeed Xiao ESP3C3 board and Seeed Xiao ESP3S3 boards. They all use the ESP32 WiFi library, which is installed in the Arduino IDE when you install the Espressif ESP32-Arduino boards definition. Installing the Nano ESP32 board also installs this library.
The Uno R4 WiFi board also has an ESP32-S3 on board for WiFi connectivity, and uses a variant on the ESP32 WiFi library, called
WiFiS3.h.
A good place to start with these examples is the WiFiScanNetworksESP example. This example will scan for nearby networks. It will also print out your board’s MAC address, which you may need to connect to a University network.
One of the key differences between the ESP32 WiFi library and the WiFiNINA and WiFi101 libraries for other Arduino boards is that the ESP32 library includes support for enterprise WPA2 networks, using the esp_wpa2.h library. You can see this in action in these examples:
These examples which show you how to connect to Eduroam, a common WPA2 enterprise in many univerities. If you’re a student or university employee, the big advantage of Eduroam is that you can use your school login credentials at other universities. This means that the same microcontroller device can run on your school’s network via eduroam, or another school’s.
NOTE: Be very careful NEVER to upload your university ID or password in the arduino_secrets.h file. Best practice is to .gitignore this file before ever committing it to a git repository.
Another difference between the WiFiNINA and WiFi101 libraries and the ESP32 WiFi libraries is how they support secure socket layer (SSL) connections for HTTP requests. For background on what this means, see this explainer article on how SSL works.
The ESP32 WiFi libraries are slightly different than the WiFiNINA and WiFi101 libraries, which are used by the Nano 33 IoT and MKR1000 and MKR1010. Those libraries rely on the WiFiSSLClient class to create SSL clients. That client doesn’t require you to obtain a website’s root CA certificate in advance.
By contrast, the ESP32 WiFi library uses the WiFiClientSecure class, part of the ESP32 NetworkClientSecure library, to handle SSL clients, and it requires you to supply the root certificate for the site to which you want to connect.
Here are three HTTPClient examples for ESP32:
In the latter two examples, a root certificate for www.example.com is used to make an HTTPS connection to that same site. You can replace it with the root certificate for another site by going to ssl.org, and entering the URL for the site to which you want to connect. From the resulting certificates, choose the root CA. Click “View/Copy PEM” and copy the text revealed there. Then open the arduino_secrets.h file and find the rootCACertificate variable. Replace the text of that variable (everything between the R"( and )"; parts) with the text of your desired Root Certificate. Then you’re ready to compile and upload.