ESP Code
ESP Code
h>
#include <WebSocketsServer.h>
#include <ESP8266HTTPClient.h> // Include the HTTP client for sending requests
void setup() {
Serial.begin(9600); // This is for communication with Arduino Mega (TX/RX)
WiFi.begin(ssid, password);
Serial.println("Connecting to WiFi...");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nWiFi connected.");
Serial.print("IP: ");
Serial.println(WiFi.localIP());
webSocket.begin();
webSocket.onEvent(webSocketEvent);
}
void loop() {
webSocket.loop();
if (client.connect(host, port)) {
// Update status based on message from NodeMCU
String status = (message == "1") ? "occupied" : "available"; // 1 -> occupied,
0 -> available
String postData = "slot_number=" + String(slot) + "&status=" + message;
// Send slot and status