I'm trying to parse the following output taken from a GSM module in Arduino, to get the Voltage (3.900V
) part only. However, I can't get it to work.
"
+CBC: 0,66,3.900V
OK
"
I have tried the following code, but it fails and even crashes.
float getVoltage() {
if (atCmd("AT+CBC\r") == 1) {
char *p = strchr(buffer, ',');
if (p) {
p += 3; // get voltage
int vo = atof(p) ;
p = strchr(p, '.');
if (p) vo += *(p + 1) - '0'; // ??
return vo;
}
}
return 0;
}
How can this be done in a better or more transparent way?