const batteryReadCommand = [0x22, 0x01]; // Command to request battery status
try {
// Start notification on the battery characteristic
try {
await BleManager.startNotification(deviceId, SERVICEUUID, CHARACTERISTICUUID);
console.log('
} catch (error) {
console.error('
}
// Listen for updates on the battery characteristic
const subscription = bleManagerEmitter.addListener(
'BleManagerDidUpdateValueForCharacteristic',
({ value, peripheral, characteristic }) => {
console.log('
if (peripheral !== deviceId || characteristic !== CHARACTERISTICUUID) return;
const buffer = Buffer.from(value);
console.log('
if (buffer.length < 2) {
console.warn('
return;
}
// Assuming battery voltage is in the first byte
const batteryVoltage = buffer[0] / 10.0;
// Assuming car battery voltage is in the second byte
const carBatteryVoltage = buffer[1] / 10.0;
// Pass battery info to the callback
onBatteryUpdate({
battery: batteryVoltage.toFixed(1),
carBattery: carBatteryVoltage.toFixed(1),
});
}
);
// Send command to the device to trigger battery reading
await BleManager.write(deviceId, SERVICEUUID, CHARACTERISTICUUID, batteryReadCommand);
console.log('
return () => {
// Clean up the listener when done
subscription.remove();
console.log('
};
} catch (error) {
console.error('
return () => {};
}
};< /code>
< /div>
< /div>
< /p>
Ich habe Protokolle im Hörer hinzugefügt, aber sie werden nicht gedruckt. Ich habe auch einen Screenshot der Dienste und Eigenschaften des Geräts angehängt. 0.77.0
Ble Manager Version: 11.5.7 < /p>
Ich bin seit über einer Woche in dieser Ausgabe festgefahren, und jede Hilfe wäre sehr geschätzt. < /P>