#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
// Replace with your network credentials
const char* ssid = "Wokwi-GUEST";
const char* password = " ";
ESP8266WebServer server(80);
// Status
String status = "Loading...";
void setup() {
Serial.begin(115200);
// Initialize pins
pinMode(buttonAvailablePin, INPUT_PULLUP);
pinMode(buttonBusyPin, INPUT_PULLUP);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("Connected to WiFi");
// Handle HTTP GET requests
server.on("/", HTTP_GET, []() {
server.send(200, "text/html", "<html><body><h1>NodeMCU Status System</h1></body></html>");
});
server.on("/updateStatus", HTTP_GET, []() {
if (server.arg("status") == "available") {
status = "Available";
} else if (server.arg("status") == "busy") {
status = "Busy";
}
server.send(200, "text/plain", "Status updated to: " + status);
});
server.on("/status", HTTP_GET, []() {
server.send(200, "text/plain", status);
});
server.begin();
}
void loop() {
server.handleClient();
// Check button status
if (digitalRead(buttonAvailablePin) == LOW) {
status = "Available";
delay(500); // Debounce delay
}
if (digitalRead(buttonBusyPin) == LOW) {
status = "Busy";
delay(500); //Debounce delay
}
}