#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <ArduinoWiFiServer.h>
const char *ssid = "yourSSID";
const char *password = "yourPassword";
StaticJsonDocument<2000> myjson;
WiFiUDP udp;
IPAddress broadcast_ip(255, 255, 255, 255);
unsigned long timerC = 0;
const int intervalC = 2000;
String DeviceName = "MyDevice";
char packet[255];
void setup() {
WiFi.mode(WIFI_AP_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println("Connecting to WiFi..");
}
Serial.println(WiFi.localIP());
udp.begin(8192);
}
void loop() {
counter = millis();
if (counter - timerC >= intervalC) {
timerC = counter;
myjson.clear();
myjson["AP"] = WiFi.softAPSSID();
myjson["STA"] = WiFi.SSID();
myjson["STAIP"] = WiFi.localIP().toString();
myjson["DeviceName"] = DeviceName;
String output;
serializeJson(myjson, output);
udp.beginPacket(broadcast_ip, 8084);
udp.print(output);
udp.endPacket();
}
}