First add add a zero-byte ('\0') at the end of your string (that's after the 5) to terminate it properly if this isn't already the case and then call either atoi or atol to convert the string to integer or long.
I´m trying to do it, but atoi allways give me a zero value. My code is the follow:
char message[10];
// now fill our zb rx class
xbee.getResponse().getZBRxResponse(rx);
nss.println(“Got an rx packet!”);
if (rx.getOption() == ZB_PACKET_ACKNOWLEDGED) {
// the sender got an ACK
nss.println(“packet acknowledged”);
}
else {
nss.println(“packet not acknowledged”);
}
nss.print("checksum is ");
nss.println(rx.getChecksum(), HEX);
nss.print("packet length is ");
nss.println(rx.getPacketLength()-6, DEC);
for (int i = 6; i <= rx.getDataLength(); i++) {
nss.print(“frame data [”);
nss.print(i, DEC);
nss.print("] is ");
char stringOne = char(rx.getData());
stringOne = hexNibbleToChar(stringOne);*
//If we are in the final character… we put in it ‘\0’*
With the 0021 IDE a numerical character string (readstring) can be turned into a number like below:
if (readstring.length() >0) {
Serial.println(readstring); //so you can see the captured string
char carray[readstring.length() + 1]; //determine size of the array
readstring.toCharArray(carray, sizeof(carray)); //put readstringinto an array
int n = atoi(carray); //convert the array into an Integer
myservo.writeMicroseconds(n); // for microseconds
//myservo.write(n); //for degees 0-180
readstring="";
}