Assignment to be done:
1.Group Assignment:
Compare as many tool options as possible
To be found here
A web server is a place where web pages are stored, processed, and served to web clients. A web client is just a web browser that we use on our computers and phones. A web client and a web server communicate using a special protocol known as Hypertext Transfer Protocol (HTTP).In this protocol, a client starts a conversation by sending an HTTP request for a specific web page. The server then sends back the content of that web page or an error message if it can’t find it (like the famous 404 Error).(Reference)
#include< WiFi.h>
#include< WebServer.h>
#include< Wire.h>
#include< Adafruit_GFX.h>
#include< Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
const char* ssid = "TECNO SPARK Go 2020";
const char* password = "$felicalon";
WebServer server(80);
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
String message = "Initial message";
void handleRoot() {
String html = "< html>";
html += "< h1>ESP32 Web Server";
html += "< p>Message: " + message + "< /p>";
html += "< form method='POST' action='/update'>";
html += "< input type='text' name='newMessage'>";
html += "< input type='submit' value='Update Message'>";
html += "< /form>";
html += "< /body>";
server.send(200, "text/html", html);
}
void handleUpdate() {
if (server.hasArg("newMessage")) {
message = server.arg("newMessage");
updateDisplay();
}
server.send(200, "text/plain", "Message updated");
}
void updateDisplay() {
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(0, 0);
display.println("ESP32 Web Server");
display.setCursor(0, 20);
display.println("Message: " + message);
display.display();
}
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
Serial.print("ESP32 IP address: ");
Serial.println(WiFi.localIP());
server.on("/", handleRoot);
server.on("/update", handleUpdate);
server.begin();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x64
updateDisplay();
}
void loop() {
server.handleClient();
}
These codes help me to create the interface where I will write the message and the button that when click on it, the message on OLED will be updated.
I have added an updateDisplay() function that updates the OLED display with the current message. This function is called when the message is updated in the handleUpdate() function.
The updateDisplay() function clears the OLED display, sets the text color, size, and cursor position, and then prints the updated message on the display.
And the function server.send(200, "text/plain", "Message updated"); helps me to get the feedback message on web page from server confirming me that the message has been updated
Then lets tappe any message and click on update to see what will happen:
The following is the video showing how it works
The used board has been designed in the previous assignments and its design files can downloaded from here
2023 All Rights Reserved. Designed by Felix NYIRIGIRA