UDP Without Static IP Addresses Arduino
Posted: Mon Jul 11, 2016 4:26 pm
I'm using the ESP8266WiFi library for arduino for Udp communications. It has been working well so far, but right now I have to hardcode in the IP address of the client/computer I'm sending UDP packets to.
I'm wondering if anyone knows of a way (preferably using ESP8266WiFi.h library) to eliminate the need for me to hardcode in the IP address of the client and on the client code side hardcode the IP address of the ESP.
I'm aware that you if you have a client send a packet to the ESP then you can get the IP address of whatever sent you the packet. For instance:
This is a partial solution because it requires that I know the IP address of the ESP8266 to send it an initial packet from the client. In my particular usage the client is a pc running come UDP matlab code.
I've read a little bit about UDP multicasting and am wondering maybe this would be the right route to a solution. Perhaps I can multicast send messages from the ESP and receive them with the matlab code and then send a response to the ESP? Unfortunately I'm fairly unfamiliar with multicasting in general.
In another situation I would just use a static IP (so I wouldn't worry about the IP address of the ESP and Client changing), but I'm using the wifi at my school.
Thanks everyone, any suggestions/advice would be appreciated I'll post my solution once I figure this out
EDIT: I ended up using Dynamic DNS to use hostnames instead of static IPs. Here is my updated code. It implements a UDP serial bridge with dynamic dns.
I'm wondering if anyone knows of a way (preferably using ESP8266WiFi.h library) to eliminate the need for me to hardcode in the IP address of the client and on the client code side hardcode the IP address of the ESP.
I'm aware that you if you have a client send a packet to the ESP then you can get the IP address of whatever sent you the packet. For instance:
Code: Select all
// send a reply, to the IP address and port that sent us the packet we received
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write("UDP packet received");
Udp.endPacket();
This is a partial solution because it requires that I know the IP address of the ESP8266 to send it an initial packet from the client. In my particular usage the client is a pc running come UDP matlab code.
I've read a little bit about UDP multicasting and am wondering maybe this would be the right route to a solution. Perhaps I can multicast send messages from the ESP and receive them with the matlab code and then send a response to the ESP? Unfortunately I'm fairly unfamiliar with multicasting in general.
In another situation I would just use a static IP (so I wouldn't worry about the IP address of the ESP and Client changing), but I'm using the wifi at my school.
Thanks everyone, any suggestions/advice would be appreciated I'll post my solution once I figure this out
EDIT: I ended up using Dynamic DNS to use hostnames instead of static IPs. Here is my updated code. It implements a UDP serial bridge with dynamic dns.