Replies: 1 comment 1 reply
|
Hi @Crimi01 I really can't tell from your code snippet here. You definitely shouldn't be using I'd suggest having a close read of https://github.com/capacitor-community/bluetooth-le#heart-rate-monitor, as this walks through all the important points. |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Problem
Hello,
I'm Crimi01. I'm searching for a solution to my problem. I don't know if this topic already exists, but I'm trying to connect via OBD2 on iOS using Capacitor 5.7.8 and the Capacitor Bluetooth LE 3.1.4 module, and I really need some help. Thanks in advance.
I'm connecting to an OBDLink CX BLE adapter (ELM327 protocol) installed on a 2025 BMW M3.
What works
What doesn't work
always times out
Xcode logs show data arriving correctly:
TO JS {"value":"37 45 38 20 30 34 20 34 31 20 30 43 20 31 36 20 36 41 20 0d"}
TO JS {"value":"0d 3e "}
My current onBLENotify implementation:
BC.addListener(notifKey, (data) => {
if (data && data.value) onBLENotify(data.value);
});
function onBLENotify(value) {
if (value && typeof value === 'object' && value.value)
value = value.value;
if (typeof value === 'string') {
const bytes = value.trim().split(' ')
.filter(h => h.length > 0)
.map(h => parseInt(h, 16))
.filter(b => !isNaN(b));
value = new TextDecoder().decode(new Uint8Array(bytes));
} else if (value && value.buffer) {
value = new TextDecoder().decode(new Uint8Array(value.buffer));
}
_scanBuf += value;
if (_scanBuf.includes('>')) {
const r = _scanBuf.replace(/>/g, '').trim();
_scanBuf = '';
if (cmdResolve) { cmdResolve(r); cmdResolve = null; }
}
}
Question
What is the exact format of the data object received in the
addListener callback?
Is it:
How should I correctly decode the incoming BLE notification data
from OBDLink CX to get the ASCII response string?
Environment
All reactions