Introduction to ESP32

From Makerpedia
Jump to navigation Jump to search


This is Carleton's repository for all things related to Espressif's System-on-a-chip ESP32.

Installation

The easiest way to work with ESP32 microcontrollers is by using the Arduino IDE. After installing the Arduino IDE, open the application, and go to File -> Preferences, and add the following to the 'Additional Boards Managers URLs' field:

https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

After adding the URL, close the preference panel, and go to "Tools -> Board -> Boards Manager...", and search for ESP32 in the dialog window that appears. Click the "Install" button to download the latest version of the tools required to work with the ESP32.

Networking

Using ESP32 controllers on Carleton's Networks

There are two methodologies for using an ESP32 on Carleton's networks; either using eduroam (which may cause headaches, but is possible) or using CarletonGuests, which is the preferred method.

Wifi via eduroam (not recommended):

In order to use an ESP32 via eduroam, you will need to obtain a copy of the Carleton eduroam CA root certificate, or use the code copied below.

#include <WiFi.h> //Wifi library
#include "esp_wpa2.h" //wpa2 library for connections to Enterprise networks

#define EAP_ANONYMOUS_IDENTITY "anonymous@carleton.edu"
#define EAP_IDENTITY "username@carleton.edu"
#define EAP_PASSWORD "password" //password for eduroam account

const char* root_ca= \ "-----BEGIN CERTIFICATE-----\n" \ 
"MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/\n" \ 
"MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT\n" \ 
"DkRTVCBSb290IENBIFgzMB4XDTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVow\n" \ 
"PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD\n" \ 
"Ew5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB\n" \ 
"AN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmTrE4O\n" \ 
"rz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEq\n" \ 
"OLl5CjH9UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9b\n" \ 
"xiqKqy69cK3FCxolkHRyxXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw\n" \ 
"7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD\n" \ 
"aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV\n" \ 
"HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQMA0GCSqG\n" \ 
"SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69\n" \ 
"ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr\n" \ 
"AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz\n" \ 
"R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5\n" \ 
"JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo\n" \ 
"Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ\n" \ 
"-----END CERTIFICATE-----";


void setup() {
  Serial.begin(115200);
  delay(10);
  Serial.print(F("Connecting to network: "));
  Serial.println(ssid);
  WiFi.disconnect(true);  //disconnect from WiFi to set new WiFi connection
  WiFi.begin(ssid, WPA2_AUTH_PEAP, EAP_ANONYMOUS_IDENTITY, EAP_IDENTITY, EAP_PASSWORD, test_root_ca); //with CERTIFICATE
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(F("."));
  }
  Serial.println("Connected.");
}

Wifi via CarletonGuests:

This is the preferred method, as it does not require your password, and won't lock you out of your account if you change your password. First, run a sketch to get the MAC address of the ESP32:

#include <esp_wifi.h>

void setup() { 
  Serial.begin(115200); 
  Serial.print("ESP Board MAC Address:  "); 
  Serial.println(WiFi.macAddress());
}

Then, once you have the MAC address for your ESP32, log into the Carleton Network Registration system with your credentials, click "create", and add an entry with the number you found using the above sketch. Once you have done this, connecting to the wifi network should be as easy as:

#include <esp_wifi.h>

setup(){

  WiFi.begin("CarletonGuests");
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println(" CONNECTED");
}

IO