Dear all,
I am working on a module where I am using Simcom A7672S GSM module.
When I am running command to get the ip address of the GSM module, I am getting correct ip address inform of string.
But when I am trying to convert that string to IP address I am getting not proper output. Not getting last octate.
Here is the code which I have written.
if (ipstat) {
Serial.println(str);
i = str.indexOf(",");
str = str.substring(i + 1);
Serial.println(str);
ip.fromString(str);
}
Here what is I am getting in output.
19:51:05.652 -> +CGPADDR: 1,10.3.85.36
19:51:05.652 -> 10.3.85.36
19:51:05.652 -> OK
19:51:05.652 -> OK
19:51:05.652 -> 10.3.85.0
When I am printing ip using
Serial.println(ip);
I am getting 10.3.85.0
Where in output I should get 10.3.85.36
Thank you for your quick response.
It's my mistake that I posted it in IDE 2.X questions, I am sorry for that.
I got the solution.
String was new line terminated, where it should be null character terminated.
I have changed the code and now it's working.
I posted the question because I was working on this part for more than 2 hours, tried all possible ways to solve it.
I am adding corrected code.
Serial.println(str);
i = str.length();
str[i-1]= '\0';
i = str.indexOf(",");
str = str.substring(i + 1);
Serial.println(str);
ip.fromString(str);
That doesn't sound right. You don't need to null-terminate String type, or use any other terminator. String type maintains a separate length attribute so that no termination is required.
I have decided I will move your topic to the Programming section, since you no longer care.