I am currently facing an issue where I am trying to read raw data from a device using Ionic Bluetooth Serial. The device sends 506 bytes per transmission to the app and waits for a response of "OK" before sending the next 506 bytes.
However, there are instances where the app does not receive the full 506 bytes in one transmission, even though the device is confirmed to be sending all 506 bytes. It seems that the app only receives a portion of the data initially, with the remainder being sent afterwards. Additionally, each set of 506 bytes contains CRC, which sometimes fails (which is expected). But when requesting a resend of the last 506 bytes, the CRC failure occurs again, even though the device itself is functioning correctly.
My suspicion is that something may be going wrong when the data reaches the Bluetooth buffer in Ionic/Cordova.
So my questions are: Am I making a mistake in how I am reading the data? Has anyone else encountered similar issues?
Here are the steps I've already taken: - Attempted to add time delays before requesting data. - Tried asking the device to restart sending data from the beginning.
async getBTRawData(): Promise<any> {
let result = new Array();
const res = this.bluetoothSerial.subscribeRawData().subscribe((data) => {
let buffer = new Uint8Array(data);
console.log("buffer items: ", buffer);
buffer.forEach((item) => {
result.push(item);
});
// this.bluetoothSerial.clear().then(data => {
// console.log("Is buffer clear before reciving new messages?:", data);
// });
}, err => {
console.log("err: ", err);
});
return result;
}
I anticipate receiving all 506 bytes without any loss since the cellphone and the device are in close proximity. While I understand occasional CRC failures, the ability to request a resend should resolve that issue. Ideally, the 506 bytes would not break into chunks upon reception by the app.
Edit: Data format can be viewed here.
Edit2: This is how the data is being processed by the Bluetooth serial: https://i.sstatic.net/ap9TV.png
Edit3: Raw Data retrieved from subscribe: https://i.sstatic.net/YJXEA.png