I have a ESP32.
Its working fine with example code developed on Arduino IDE.
Now I have a requirement for this module using its Analog Input module.
I am acquiring 4 analog channels. I want to beam them as a comma separated data via WiFi to any PC client which is linked to it.
I guess I must use TCP or for faster data transfer use UDP.
So there are two parts to this :
A. I must beam up the data via UDP to any client who is interested to read my data.
B. On the client side I must have a WiFi Client configured to read the incoming data , parse it and store it / display it.
For the first point ( A ) i think I can use the example below and in the loop() code replace the " Anyone Here " with my data.
But for the client side (B) what options are there as I have no clue how to go about creating a WiFi client... maybe a web browser can be tweaked to do what I want ?
SERVER SIDE CODE SAMPLE :
#include "WiFi.h"
#include "AsyncUDP.h"
const char * ssid = "***********";
const char * password = "***********";
AsyncUDP udp;
void setup()
{
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("WiFi Failed");
while(1) {
delay(1000);
}
}
if(udp.listen(1234)) {
Serial.print("UDP Listening on IP: ");
Serial.println(WiFi.localIP());
udp.onPacket([](AsyncUDPPacket packet) {
Serial.print("UDP Packet Type: ");
Serial.print(packet.isBroadcast()?"Broadcast":packet.isMulticast()?"Multicast":"Unicast");
Serial.print(", From: ");
Serial.print(packet.remoteIP());
Serial.print(":");
Serial.print(packet.remotePort());
Serial.print(", To: ");
Serial.print(packet.localIP());
Serial.print(":");
Serial.print(packet.localPort());
Serial.print(", Length: ");
Serial.print(packet.length());
Serial.print(", Data: ");
Serial.write(packet.data(), packet.length());
Serial.println();
//reply to the client
packet.printf("Got %u bytes of data", packet.length());
});
}
}
void loop()
{
delay(1000);
//Send broadcast
udp.broadcast("Anyone here?");
}