Chat freely about anything...

User avatar
By Trey
#42707 I don't know if this is the right place to ask. But what is the most elegant way to get an IpAddress from a string. My google attempts tell me how to turn one into a string but I don't need that. I know I can get the 4 ints and convert them to a byte array, My question is whats the best, easiest, way with as few lines as possible. To turn string"255,255,255,255" into an IPAdress object.

Thanks
User avatar
By Trey
#42753 Thanks I'll look into that, I had just about decided to move on and do it this way temporarily.
Thanks again for the response.

int commaIndex = settings[setting_index].indexOf(',');
int secondCommaIndex = settings[setting_index].indexOf(',', commaIndex+1);
int thirdCommaIndex = settings[setting_index].indexOf(',', secondCommaIndex+1);
String firstValue = settings[setting_index].substring(0, commaIndex);
String secondValue = settings[setting_index].substring(commaIndex+1, secondCommaIndex);
String thirdValue = settings[setting_index].substring(secondCommaIndex+1,thirdCommaIndex);
String fourthValue = settings[setting_index].substring(thirdCommaIndex+1);
IPAddress ip = (firstValue.toInt(),secondValue.toInt(),thirdValue.toInt(),fourthValue.toInt());
User avatar
By Trey
#42754 Do you have a usage example?

String str = "192.168.0.1";
IPAddress ip = IPAddress.fromString(str); ????

I get 'class IPAddress' has no member named 'fromString'

using:
http://arduino.esp8266.com/stable/packa ... index.json & IDE 1.6.6


Found this thread broken links. Is this still only in the staging release.

From GitHub :
https://github.com/esp8266/Arduino/blob ... ddress.cpp
https://github.com/esp8266/Arduino/blob ... PAddress.h
No other files are needed for the IPAddress.toString() method. - See more at: viewtopic.php?p=30487#sthash.VtrCaoba.dpuf