UDP Packet to Every IP

I currently have an IOS app that sends and receives UDP data to the Arduino. The Arduino sets itself up on the network using DHCP. Now most of the time it gets the same IP address, however there could be a time that it could get a different one. What I would like is for the Arduino to broadcast its IP over UDP on a specific port but not necessarily to a particular IP, that way if the IP changes the IOS app will just look at the UDP traffic on the specified port and will now know the IP address of the Arduino. This will also allow multiple IOS devices to see what the IP address is on the Arduino.

Any ideas?

Interesting question. As I see it, you have two choice. First, you might be able to get you iOS device to use UDP broadcast / multicast. That way, the Arduino will get every packet as long as they are on the same subnet. I have used this approach very successfully. I am receiving UDP datagrams on my Arduino that were sent via various Art-Net enabled programs.

Second, you might have the Arduino code broadcast its IP address via UDP broadcast / multicast.

The first approach is easier (assuming that iOS will let you use UDP broadcast / multicast). The second approach is more efficient.

Got any sample code....

SFP,

Sure. Just go to Dropbox - Error - Simplify your life

Ignore the LED related code (you can delete it). The UDP code successfully reads UDP datagrams broadcast (probably multicast to be more accurate) from various Art-Net components.

SFP,

Note that the code works with a standard Arduino Ethernet shield. Check out http://www.ebay.com/itm/300851543921?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649 for an example.

Also note that the Ethernet shield uses several pins including pin 4. That's why the LED code uses pin 5.