me-no-dev / ESPAsyncUDP

Async UDP library for ESP8266

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Help Request] Send UDP packets to range of IP's

DraconInteractive opened this issue · comments

Hi!
I am working on an arduino sending sensor data to multiple devices. I did not set up the original board/code, the company hired an engineer from it and I received it from there.

I have a working prototype with a single connection. The engineer made it so the board could be configured values easily, including network details, target IP and in/out port. Setting these, with a client on the other end, data is transferring nicely.

I am trying to convert this so it can be sent to multiple devices, without manually entering the IP of each device. All devices (including the arduino), are on a local network with static IP's.

The current code consists of these parts:
The relevant part of Main.cp:
IPAddress ip; if (ip.fromString(config._targetIP)){ InitiateUDP(ip, atoi(config._portSend), atoi(config._portListen)); TickerUDPStream.attach_ms(streamRate,UDPStream); }

InitiateUDP:
`if(udp.connect(_targetIP, _portSend)) {
Serial.print("UDP1 connected on port: ");
Serial.println(_portSend);
Serial.println(_targetIP.toString());

  udp.onPacket([](AsyncUDPPacket packet) {
        Serial.print("UDP1 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());
   });`

UDPStream:
void UDPStream(){ transmitSensorData(ReceivedCommand); }

transmitSensorData simply calculates the output, and uses udp.print (data) to send it.

I highly appreciate any help provided :)

commented

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

commented

[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.