Skip to content

Instantly share code, notes, and snippets.

@loosak
Created June 27, 2015 17:35
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save loosak/76019faaefd5409fca67 to your computer and use it in GitHub Desktop.
Save loosak/76019faaefd5409fca67 to your computer and use it in GitHub Desktop.
WiFi.localIP() to string
char buf[16];
sprintf(buf, "IP:%d.%d.%d.%d", WiFi.localIP()[0], WiFi.localIP()[1], WiFi.localIP()[2], WiFi.localIP()[3] );
@loosak
Copy link
Author

loosak commented Jul 11, 2015

IPAddress ip = WiFi.localIP();
sprintf(lcdBuffer, "%d.%d.%d.%d:%d", ip[0], ip[1], ip[2], ip[3], udpPort);

@Vijayenthiran
Copy link

Thanks. You can also use inbulilt .toString() funciton. Example usage:
server.send(200, "text/plain", "Please go to : " + WiFi.localIP().toString() + "/test");

@zzxjl1
Copy link

zzxjl1 commented Nov 26, 2018

Then how to reverse that?

@fitorec
Copy link

fitorec commented May 14, 2019

a simple snippet in some function:

String ip2Str(IPAddress ip){
  String s="";
  for (int i=0; i<4; i++) {
    s += i  ? "." + String(ip[i]) : String(ip[i]);
  }
  return s;
}

good luck!

@gns5280
Copy link

gns5280 commented Apr 18, 2024

But, then how to pass/assign "s" to be used as a String in other parts of the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment