logo elektroda
logo elektroda
X
logo elektroda

WiFiUdp.h: How to Assign a Static IP Address to ESP32?

madiz08 990 5
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18276990
    madiz08
    Level 14  
    Hello
    Uploading the following code:
    Code: C / C++
    Log in, to see the code
    .
    then attaching the serial monitor, the IP is assigned randomly (practically different every day). Is it possible to assign a specific IP address by modifying the libraries accordingly?

    Added after 3 [hours] 9 [minutes]: .

    Code: C / C++
    Log in, to see the code


    In wifiudp.h instead of remoteIP() can I assign my address e.g. 192.168.0.214? If so, how do I write it down?

    Added after 1 [hour] 1 [minute]: .

    In WifiUdp.cpp I have this function:
    Code: C / C++
    Log in, to see the code
    .

    Now I have no way to check it, but if I replace this function with:
    Code: C / C++
    Log in, to see the code
    .

    solve the problem?
  • ADVERTISEMENT
  • Helpful post
    #2 18277925
    mpier
    Level 29  
    Hello, write again what you mean, because the attempted solution you presented has little to do with the question you asked. You can either set a fixed IP address for the client on a DHCP server (e.g. oi MAC number) or instead of DHCP configure it statically. I'm not familiar with the arduino, maybe Wifi.config()?
  • ADVERTISEMENT
  • ADVERTISEMENT
  • #4 18278670
    madiz08
    Level 14  
    What I mean is that my ESP32 should have a fixed IP address, as I connect to it via different applications. For data exchange to be possible the ESP32 needs to know the IP address of the application and the application needs to know the ESP32 address.
    The example shown is for communication over TCP/IP and there is no problem with that, but the UDP protocol allows for much faster data exchange and the point is that with UDP I can't set a static IP in any way

    WiFiUdp.h: How to Assign a Static IP Address to ESP32?

    If I use the UDP library I always have a different IP than I would like. What I wrote earlier also does not work
  • ADVERTISEMENT
  • Helpful post
    #5 18278708
    khoam
    Level 42  
    madiz08 wrote:
    What I want is for my ESP32 to have a fixed IP address, as I connect to it via various applications. In order for data exchange to be possible the ESP32 needs to know the IP address of the application and the application needs to know the address of the ESP32.
    .
    Is this ESP supposed to operate in STA or AP mode?

    madiz08 wrote:
    The example shown here is for communication over TCP/IP and there is no problem with that, but the UDP protocol allows for much faster data exchange and the thing is that with UDP I cannot set a static IP in any way
    .
    The IP address is set for the IP layer, not for the higher layers, TCP or UDP.

    This code, what you have shown in the image does not match what I wrote in post #3 - no WiFi.config() before WiFi.begin().
  • #6 18286000
    madiz08
    Level 14  
    It wasn't until today that I was able to sit down to this quietly and indeed the solution was WiFi.config(local_IP, gateway, subnet);
    Code: C / C++
    Log in, to see the code
    .

    Thanks to
ADVERTISEMENT