Maybe this changed.....but I have to send a String over an XBEE connection. The way it is send means I have to convert the String to uint8_t[]. I played around with the getBytes and arrays a bit, as I seemed to loose my last character.
String length = 43 characters (as in, counted on screen on println, so probably excluding the trailing zero)
Code:
uint8_t payload[message.length()];
message.getBytes(payload, message.length());
Result: last character lost
As suggested above:
uint8_t payload[message.length()+1];
message.getBytes(payload, message.length()+1);
Result: A blank space after my message, so no good
Used code:
uint8_t payload[message.length()];
message.getBytes(payload, message.length()+1);
Result: String is send, no errors/missing chars/blanks etc
So it seems length() does give the right size array, but somehow replaces the last char with the trailing zero in the getBytes() method???