A working example of a BLE Keyboard Peripheral (Server) ran on my Raspberry PI4-b with Buster Raspbian-Lite for all to use. My desire is to hopefully save at least one other person the literal weeks I've spent trying to get this working for my little home automation project.
Verified working connected to my Blade Android, Windows 10 laptop, and Amazon FireTV stick devices
Once running and connectted properly to a client device, it will update the battery status with a lower percentage every 60 seconds, use the Keyboard Input Report to send a capital 'M' every 10 secomds, and use the Consumer Input Report to send a 'volumeUp' every 15 seconds.
Ensure you use Bluez Version 5.56 or better. This example uses Bluez features that were only experimental in prior versions.
The PI4 ships with a dual bluetooth chip. You must ensure you pair devices in BLE mode. To help, change this option in the /etc/bluetooth/main.conf file:
#Restricts all controllers to the specified transport. Default value
#is "dual", i.e. both BR/EDR and LE enabled (when supported by the HW).
#Possible values: "dual", "bredr", "le"
#ControllerMode = dual
#ControllerMode = bredr
ControllerMode = le
Once you have this example running, use the Bluetoothctl command to make sure your bluetooth controller's 'power' option is on and that the 'advertise' option is on. This will advertise your bluetooth controller to other bluetooth client devices in order to discover and pair with your server. You can write your own GAD service to programically advertise your device, but it's not required if you properly use the BluetoothCtl or BtMgmt tools that ship with Bluez.
I have not tested this yet.... But to eliminate the questions during pairing, try setting the Bluez default-agent option to 'noInputnoOutput'. Also use the Bluetoothctl command to 'trust' the client device your connecting with.
Hi All,
I wrote this for my own personal use for my little home automation project. As such, no support for this example is available, but I'll be happy to answer any questions I can.
Regards