Created
June 27, 2015 17:35
-
-
Save loosak/76019faaefd5409fca67 to your computer and use it in GitHub Desktop.
WiFi.localIP() to string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char buf[16]; | |
sprintf(buf, "IP:%d.%d.%d.%d", WiFi.localIP()[0], WiFi.localIP()[1], WiFi.localIP()[2], WiFi.localIP()[3] ); |
Thanks. You can also use inbulilt .toString()
funciton. Example usage:
server.send(200, "text/plain", "Please go to : " + WiFi.localIP().toString() + "/test");
Then how to reverse that?
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!
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
IPAddress ip = WiFi.localIP();
sprintf(lcdBuffer, "%d.%d.%d.%d:%d", ip[0], ip[1], ip[2], ip[3], udpPort);