Closed milesfrain closed 6 years ago
Sounds like BlueZ is not exposing the battery service. That usually happens when a BlueZ plugin claims the service. Maybe try disabling plugins?
Yep. Disabling the battery plugin worked. I couldn't figure out how to do that when you replied, but have since found the details in this SO answer.
The solution is to edit /lib/systemd/system/bluetooth.service
and add -P battery
to end of bluetoothd
:
ExecStart=/usr/lib/bluetooth/bluetoothd -P battery
FWIW, sudo systemctl edit bluetooth.service
with the following contents will probably work better for most people.
[Service]
ExecStart=
ExecStart=-/usr/lib/bluetooth/bluetoothd -P battery
If changes are made directly to /lib/systemd/system/bluetooth.service
, they will be overwritten whenever the bluez
package is updated.
What is the reason for the empty assignment and the leading hyphen in the next line? Would this not work?
[Service] ExecStart=/usr/lib/bluetooth/bluetoothd -P battery
Services allow more than one ExecStart
, ExecStart=
is a special case to say "don't run any previous ExecStart
, only the new ones after this". So without it, the service will try to start bluetoothd
twice.
https://www.freedesktop.org/software/systemd/man/systemd.service.html
Thanks for the link.
I'm still a bit confused about whether an "empty string" is considered "zero commands". I guess not, since that's disallowed with Type=dbus
for bluez.
Here are the relevant nuggets from that manual:
Unless
Type=
isoneshot
, exactly one command must be given. WhenType=oneshot
is used, zero or more commands may be specified. Commands may be specified by providing multiple command lines in the same directive, or alternatively, this directive may be specified more than once with the same effect. If the empty string is assigned to this option, the list of commands to start is reset, prior assignments of this option will have no effect.If the executable path is prefixed with "-", an exit code of the command normally considered a failure (i.e. non-zero exit status or abnormal exit due to signal) is recorded, but has no further effect and is considered equivalent to success.
It is not an "empty" command, it means delete all previous commands. Since the dbus
type can only have one command, we have to delete the old one before we can add a new one. In the end there is still exactly one command.
Not sure if this is a Linux/Chrome bug or related to #94. I'm running on Ubuntu 18.04 with Chrome. Heartrate test seems to work fine, so I'm confused why there are issues with Battery simulation.
I'm testing through this page: https://googlechrome.github.io/samples/web-bluetooth/battery-level.html Seeing the following "Live Output":
I found that exact
0000180f-...
battery_service UUID in the android code here: https://github.com/WebBluetoothCG/ble-test-peripheral-android/blob/277fbf7c586d579a9d270d71f7891144dea5e4d5/app/src/main/java/io/github/webbluetoothcg/bletestperipheral/BatteryServiceFragment.java#L45The reset energy app works: https://googlechrome.github.io/samples/web-bluetooth/reset-energy.html
Live output of:
Which successfully resets the
energy expended
value to zero in the android app.Trying to troubleshoot with
bluetoothctl
(Linux CLI utility). Seeing reasonable GATT listing "Heart Rate Control Point" (2A39) when opening the heartrate tab in the android app:But when switching over to the Battery tab, I don't see the battery service listed.
Upon a fresh connection, I do see the
180F
battery status UUID logged with the [CHG] tag, but it does not persist withlist-attributes
.