For this week's assignment, I wanted to get ahead on my auto-aiming trash can final project. I need to determine whether using LiDAR or camera object detection is the better approach for sensing trash in the air. This week's networking & communications assignment required me to connect multiple wired &/or wireless nodes. My project used the ESP32-S3 with onboard camera module to, which also included addresses for local input / output devices. I started the weekly assignment by going through past class versions of ESP32 connections through the MCU's built-in WiFi package. Brian Huang's assignment from last year walks through is Wi-Fi connection with the ESP32. I refined his code for my setup and established a Wi-Fi connection with the MCU by creating an access point. Once the connection was established by connecting my computer to the public network, I entered the IP address into my browser and saw the "Hello World!" message flash on my screen.
The code below was used to generate WiFi credentials and establish a connection with a client.
#include
// Generate WiFi credentials
const char* ssid = "ESP32-Access-Point";
const char* password = "123456789";
WiFiServer server(80);
void setup() {
Serial.begin(115200);
// Wait a moment for serial to stabilize
delay(1000);
Serial.println();
Serial.print("Setting soft-AP (Access Point)...");
// Start the Access Point
// Remove the password parameter if you want the AP to be open (no password)
WiFi.softAP(ssid, password);
IPAddress IP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(IP);
server.begin();
}
void loop() {
WiFiClient client = server.available(); // Listen for incoming clients
if (client) { // If a new client connects,
Serial.println("New Client.");
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println("Connection: close");
client.println();
// Display the HTML web page
client.println("");
client.println("");
client.println("Hello World
");
client.println("Connected to ESP32-S3!
");
// The HTTP response ends with another blank line
client.println();
// Break out of the while loop
break;
} else { // if you got a newline, then clear currentLine
currentLine = "";
}
} else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
}
}
// Close the connection
client.stop();
Serial.println("Client disconnected.");
Serial.println("");
}
}
Once the connection was established, the next step was streaming the camera feed to the same browser. Thankfully, the ESP32 library came with pre-installed camera web server examples that I used to generate the livestream. I uncommented my board (XIAO ESP32-S3) in the board.config module and added my WiFi credentials to the script. When I re-initiated the network connection and entered the IP address in the browser, I saw the ESP32 livestream module begin. Then I pressed the Start Stream button and saw the livestream successfully begin. Despite the high latency and low resolution, the camera still broadcasted its feed to my computer browser via the WiFi connection.