I'm attempting to send 8-bit byteArrays to an rfduino.
In the sketch, I got
void RFduinoBLE_onReceive(char *data, int len) {
int firstbyte = data[0];
Serial.println(firstbyte)
}
This works fine if the firstbyte is over 32. But if I'm sending a byteArray of [13, ...], firstbyte is parsed as 0.
I think I understand why (?): RFduinoBLE parses incoming data as characters before sending it to this function, and bytes up to 32 are empty string.
So my question is: how can I use the RFduinoBLE-onReceive to read bytearrays with values below 32?
The following seems to work just fine:
void RFduinoBLE_onReceive(char *data, int length) {
uint8_t firstbyte = data[0];
}
or for arrays
uint8_t getData[20];
void RFduinoBLE_onReceive(char *data, int length) {
for (i = 0; i < length; i++) {
getData[i] = data[i];
}
}
Not quite sure what went right/wrong where, but I suspect either using int firstbyte
instead of uint8_t firstbyte
or casting uint8_t firstbyte = (uint8_t) data[0]
did something I didn't expect.