How to get the public ip from esp8266?

Posted on
  • I am trying to get the public ip in my esp8266 so I can send it to my remote server( so I can access my espruino server later remotely. Is there an api to get the public ip? I tried to use wifi.getIP() but it returns the local ip (192.168.x.x) only which is not what I needed.
    I also tried the Ethernet.getIP() but it keep saying Ethernet is not defined. Not sure why. am I doing something wrong on using it?

    Please help thanks.

  • Get your esp8266 to do a http.get to your remote server. The IP of the request on your remote server will be your current public IP address.

    Anternatively, you can use a Dynamic DNS service, like . They offer a free service - although you have to update every month. This means that you can use a DNS name and this name will get updated to you current IP.

    You will also need to port forward on your router so that a request on your router gets forwarded to the esp8266. As @Ollie suggested on another thread - it's best to give your esp8266 a static IP based on the MAC address so you know what address to forward too.

  • thanks for your help. Yeah I can get the that IP via the get request on the server end. but this is more like a passive way of getting the ip. I want to be able to get the ip right in the esp8266 as soon as the public ip is changed and send it right away to the cloud.

    so back to my original question is it impossible to get the external ip from the esp8266?

  • You would need to involve an external server that sees what IP is sending the request and echos it back - the devices behind a router do not know what their external IP address is (be they computers, embedded devices, or whatever).

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

How to get the public ip from esp8266?

Posted by Avatar for coyu1314 @coyu1314