Hi All,
I am trying to convert a byte array back to a string.
Basically I have an ethernet shield and I set the IP address, I would like to output the IP address to webpage when the page is accessed.
I have it all working except the fact that I do not know how to output the byte array as a string.
Here is the bit of code.
byte byIP[]={192.168.2.10};
strIP=byIP;
server.print("IP Address = ");
server.println(strIP);
Thanks
Steve
byte byIP[]={192,168,2,10};
void PrintIP( byte PrintThis[] )
{
server.print("IP Address = ");
server.print(PrintThis[0],DEC);
server.print(".");
server.print(PrintThis[1],DEC);
server.print(".");
server.print(PrintThis[2],DEC);
server.print(".");
server.print(PrintThis[3],DEC);
}
Doesn't look like you your byte array initialized correctly. There should be commas between the values, not periods.
You can't print that array as a string. You could print each byte (each element of the array), which would convert it to an array of characters.
Or, you could use the sprintf() function to do the same thing.
Thanks for your replies.
Sorry typing error, I have use comma's in my sketch.
I will look into the sprintf() function.
Thanks again.