#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
const IPAddress ip(192, 168, 1, 100); // Replace with the desired static IP
const IPAddress gateway(192, 168, 1, 1);
const IPAddress subnet(255, 255, 255, 0);
const unsigned int localPort = 12345; // Choose a UDP port
WiFiUDP udp;
void setup() {
Serial.begin(115200);
WiFi.config(ip, gateway, subnet);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
udp.begin(localPort);
}
void loop() {
int packetSize = udp.parsePacket();
if (packetSize) {
char packetBuffer[255];
int len = udp.read(packetBuffer, 255);
if (len > 0) {
packetBuffer[len] = 0;
Serial.print("Received packet: ");
Serial.println(packetBuffer);
}
}
}