3030static volatile BTState bluetoothState = BT_OFF;
3131
3232#ifdef COMPILE_BT
33+
34+ #include < BleBatteryService.h>
35+
3336BTSerialInterface *bluetoothSerialSpp;
3437BTSerialInterface *bluetoothSerialBle;
3538BTSerialInterface *bluetoothSerialBleCommands; // Second BLE serial for CLI interface to mobile app
39+ BleBatteryService bluetoothBatteryService;
3640
3741#define BLE_SERVICE_UUID " 6e400001-b5a3-f393-e0a9-e50e24dcca9e"
3842#define BLE_RX_UUID " 6e400002-b5a3-f393-e0a9-e50e24dcca9e"
@@ -503,6 +507,7 @@ void bluetoothStart()
503507 deviceName, false , false , settings.sppRxQueueSize , settings.sppTxQueueSize , BLE_COMMAND_SERVICE_UUID,
504508 BLE_COMMAND_RX_UUID, BLE_COMMAND_TX_UUID); // localName, isMaster, disableBLE, rxBufferSize,
505509 // txBufferSize, serviceID, rxID, txID
510+ bluetoothBatteryService.begin ();
506511 }
507512 else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP)
508513 {
@@ -522,7 +527,9 @@ void bluetoothStart()
522527 beginSuccess &= bluetoothSerialBleCommands->begin (
523528 deviceName, false , false , settings.sppRxQueueSize , settings.sppTxQueueSize , BLE_COMMAND_SERVICE_UUID,
524529 BLE_COMMAND_RX_UUID, BLE_COMMAND_TX_UUID); // localName, isMaster, disableBLE, rxBufferSize,
525- // txBufferSize, serviceID, rxID, txID
530+ // txBufferSize, serviceID, rxID, txID
531+
532+ bluetoothBatteryService.begin ();
526533 }
527534 else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_SPP_ACCESSORY_MODE)
528535 {
@@ -750,3 +757,11 @@ void bluetoothPrintStatus()
750757
751758 systemPrintln ();
752759}
760+
761+ // Send over dedicated BLE service
762+ void bluetoothSendBatteryPercent (int batteryLevelPercent)
763+ {
764+ #ifdef COMPILE_BT
765+ bluetoothBatteryService.reportBatteryPercent (batteryLevelPercent);
766+ #endif // COMPILE_BT
767+ }
0 commit comments