Fix Bosch BLE protocol: correct UUIDs, 2-byte data IDs, new dashboard fields
This commit is contained in:
parent
906fde8ad1
commit
b5dd24544c
@ -1,11 +1,16 @@
|
||||
/**
|
||||
* BLE Service — Web Bluetooth connection to Bosch Smart System
|
||||
*
|
||||
* Connects via the correct Bosch eaa2 service UUID,
|
||||
* subscribes to notifications on char 0011,
|
||||
* and passes decoded data to the app.
|
||||
*/
|
||||
|
||||
const BLEService = (() => {
|
||||
let device = null;
|
||||
let server = null;
|
||||
let characteristic = null;
|
||||
let writeCharacteristic = null;
|
||||
let onDataCallback = null;
|
||||
let onStatusCallback = null;
|
||||
|
||||
@ -27,9 +32,10 @@ const BLEService = (() => {
|
||||
updateStatus('scanning');
|
||||
|
||||
try {
|
||||
// Request device — use namePrefix filters + optionalServices
|
||||
// (some Bosch bikes don't advertise the service UUID directly)
|
||||
device = await navigator.bluetooth.requestDevice({
|
||||
filters: [
|
||||
{ services: [BoschProtocol.SERVICE_UUID] },
|
||||
{ namePrefix: 'smart system' },
|
||||
{ namePrefix: 'Bosch' },
|
||||
{ namePrefix: 'BRC' }
|
||||
@ -44,9 +50,19 @@ const BLEService = (() => {
|
||||
|
||||
updateStatus('discovering');
|
||||
const service = await server.getPrimaryService(BoschProtocol.SERVICE_UUID);
|
||||
|
||||
// Get notify characteristic (0011)
|
||||
characteristic = await service.getCharacteristic(BoschProtocol.CHAR_UUID);
|
||||
|
||||
// Subscribe to notifications
|
||||
// Try to get write characteristic (0012) for potential init commands
|
||||
try {
|
||||
writeCharacteristic = await service.getCharacteristic(BoschProtocol.WRITE_UUID);
|
||||
console.log('Write characteristic (0012) available');
|
||||
} catch (e) {
|
||||
console.log('Write characteristic not available:', e.message);
|
||||
}
|
||||
|
||||
// Subscribe to notifications IMMEDIATELY
|
||||
await characteristic.startNotifications();
|
||||
characteristic.addEventListener('characteristicvaluechanged', onCharacteristicChanged);
|
||||
|
||||
@ -71,6 +87,7 @@ const BLEService = (() => {
|
||||
characteristic.removeEventListener('characteristicvaluechanged', onCharacteristicChanged);
|
||||
characteristic = null;
|
||||
}
|
||||
writeCharacteristic = null;
|
||||
if (device && device.gatt.connected) {
|
||||
device.gatt.disconnect();
|
||||
}
|
||||
@ -84,6 +101,14 @@ const BLEService = (() => {
|
||||
*/
|
||||
function onCharacteristicChanged(event) {
|
||||
const dataView = event.target.value;
|
||||
|
||||
// Log raw bytes for debugging
|
||||
const raw = [];
|
||||
for (let i = 0; i < dataView.byteLength; i++) {
|
||||
raw.push(dataView.getUint8(i).toString(16).toUpperCase().padStart(2, '0'));
|
||||
}
|
||||
console.log('BLE notification:', raw.join('-'), `(${dataView.byteLength}B)`);
|
||||
|
||||
const parsed = BoschProtocol.parseNotification(dataView);
|
||||
if (onDataCallback) {
|
||||
onDataCallback(parsed);
|
||||
@ -96,6 +121,7 @@ const BLEService = (() => {
|
||||
function onDisconnected() {
|
||||
console.warn('BLE device disconnected');
|
||||
characteristic = null;
|
||||
writeCharacteristic = null;
|
||||
server = null;
|
||||
updateStatus('disconnected');
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user