hansjny / Natural-Nerd

589 stars 444 forks source link

Why not use UDP broadcast in SoundReactive2 project? #24

Closed rishabhrpg closed 4 years ago

rishabhrpg commented 4 years ago

In SoundReactive2 project, inspecting the led_master.ino file its clear that user needs to define how many clients are going to connect this is needed just because you need to loop through their IP addresses which you are guessing by adding 1 to 192.168.4.1 good enough but lot of functions can be removed just by sending the packet to a broadcast address such as

255.255.255.255

But since there is no Arduino wrapper that supports broadcast address (However EspressIf OS has API for that) we can still use 192.168.4.255 (253 clients) or more by 192.168.255.255 that should work.

  IPAddress ip(192,168,4,255);
  UDP.beginPacket(ip, 7001); 
  UDP.write((char*)&send_data,sizeof(struct led_command));
  UDP.endPacket();

this should send the packet to all connected node this way there is no need to keep track on if any node is connected hanse waitForConnections, resetHeartBeats, readHeartBeat, checkHeartBeats methods can be removed, this will not only make project more easy to DIY but also this way there will be no need to modify any code on a master node if more clients are connected later on.

hansjny commented 4 years ago

Absolutely. I tinkered with the UDP broadcast when I first made the thing, but I couldn't get it to broadcast as fast asI wanted (for some reason it was a lot slower). But I was on a deadline for the video, so I stopped working on improving it, and opted for the other way. If you have gotten this to work consistently I am sure very many people would be happy if you made a pull request with the necessary changes to make it work.

gulliver103 commented 3 years ago

Hi guys and thanks for SoundReactive2 project. I would like to use the UDP broadcast in SoundReactive2. Can you help me how to implement it? Thanks /Gulliver