I am using the HC-05 bluetooth module to connect to my Arduino mega. I am sending messages of 35 bytes using the library pySerialTransfer / SerialTransfer.h.
These are the bytes my python module logs as sending:
ARDUINO: b'\x01\x88\x13\xc8\xaf\x00\x00\x00\x00\x9f\x05\x1e\x00UAL2380\x00\x00SFO-HNL\x00\x00\x00\x00\x00\x00'
These are the bytes the Arduino records as receiving:
Recd 35 new bytes: 1|FFFFFF88|13|FFFFFFC8|FFFFFFAF|0|0|0|0|FFFFFF9F|5|1E|0|55|41|4C|32|33|38|30|0|0|53|46|4F|2D|48|4E|4C|0|0|0|0|0|0|
Everything matches exactly.... except the extra data in bytes 2, 4, 5 and 10 - what might be causing that?
Here's the python code:
def Write(link, values, format_string):
"""Sends the encapsulated string command on an open pySerialTransfer."""
packed_bytes = struct.pack(format_string, *values)
Log(packed_bytes)
for n, b in enumerate(packed_bytes):
link.txBuff[n] = b
link.send(len(packed_bytes))
The format_string is '=?hlhhh9s9shh'.
Here's the Arduino code that receives the data / prints the bytes-received message:
void PrintRecdBytes(int bytes_read, char* rx_buff) {
Serial.print("Recd ");
Serial.print(bytes_read);
Serial.print(" new bytes: ");
for(byte i = 0; i < bytes_read; i++) {
Serial.print(rx_buff[i], HEX);
Serial.print("|");
}
Serial.println("");
}
void Read() {
long now = millis();
bool bt_available = bluetooth.available();
if (now - last_read_time >= READ_DELAY_SECONDS * 1000 && bt_available) {
bluetooth.rxObj(inbound, sizeof(inbound));
last_read_time = now;
if (VERBOSE) {
PrintRecdBytes(bluetooth.bytesRead, bluetooth.rxBuff);
}
}
}
Thanks for any guidance!