[Note] Bluetooth keyboard emulation

Overview

――A memo that tried the article of typing
from a USB keyboard that was garbled (emulated) on a BT keyboard and inserted into a Raspberry Pi using Bluetooth. らずぱいでBluetoothキーボードのエミュレーション

-** Original article ** - Emulating a Bluetooth Keyboard with a Raspberry Pi and Python (Raspbian Jessie/Bluez 5 version)
↑ seems to correspond to the recent environment by referring to ↓. - Emulate a Bluetooth keyboard with the Raspberry Pi - Learn how to relay the input from a USB keyboard to a Bluetooth-capable device using the Raspberry Pi

-Isn't it BLE? (I couldn't detect it from my smartphone) --I haven't seen the implemented code at all. .. Only step by step. -(Related) USB keyboard with Bluetooth support on BL Nano and Raspberry Pi ... Road to

environment

--Confirmed with Raspberry Pi: Zero W and 3 Model B - Raspbian: 2017-03-02-raspbian-jessie-lite.img --USB keyboard --Connect to Zupai --Windows 7 64-bit: I logged in to Zupai with ssh and set it. Also, BT connection test

procedure

  1. Start Raspbian --Burn Raspbian image to microSD --If necessary --Make ssh (empty file) and wpa_supplicant.conf (if any) into FAT partition - sudo apt-get update && sudo apt-get upgrade

  2. Installation of required packages --For the time being

    ```bash:For the time being
    

sudo apt-get install -y htop byobu git-core python-dbus python-gtk2

 --Bluetooth related

        ```bash:Bluetooth related
sudo apt-get install -y python-gobject bluez bluez-tools bluez-firmware python-bluez python-dev python-pip
sudo pip install evdev
  1. Start byobu --Start with byobu [Enter] --Ctrl + a => 1 \ [Enter ](first time only)

  2. Bluetooth Daemon Configuration

    # Stop the background process
    sudo /etc/init.d/bluetooth stop
    
    # Open a dedicated terminal and tun the bluetooth daemon in the foreground
    sudo /usr/sbin/bluetoothd --nodetach --debug -p time
    
  3. Ctrl + a (release) c

  4. Emulator Sever

    # Download the code
    cd ${HOME}
    git clone https://github.com/yaptb/BlogCode.git
    
    # Configure DBUS
    cd BlogCode/btkeyboard/dbus
    sudo cp org.yaptb.btkbservice.conf /etc/dbus-1/system.d/
    
    #hciconfig
    sudo hciconfig hci0
    sudo hciconfig hci0 up
    sudo hciconfig hci0
    

Make a note of the BD Address displayed here. => Example) BD Address: B8: 27: EB: 31: 41: 59 ACL MTU: 1021: 8 SCO MTU: 64: 1

```bash:btk_server.Edit py
#Edit the Emulator Server Code
cd ${HOME}
cd BlogCode/btkeyboard/server
#
vi btk_server.py
```

=> Enter the appropriate name in BD ADDRESS and MY_DEV_NAME in MY_ADDRESS. MY_ADDRESS="B8:27:EB:31:41:59" MY_DEV_NAME="RPiZeroW_BTKb"

```bash:Start Emulator Server
# Run Emulator Server
cd ${HOME}
cd BlogCode/btkeyboard/server
sudo python btk_server.py
```
```shell-session:(Execution example)
pi@raspberrypi:~/BlogCode/btkeyboard/server$ sudo python btk_server.py
/usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:57: GtkWarning: could not open display
  warnings.warn(str(e), _gtk.Warning)
Setting up service
Setting up BT device
Configuring for name RPiZeroW_BTKb
Configuring Bluez Profile
Reading service record
Profile registered
Waiting for connections
```
  1. Ctrl + a (release) c

  2. Pairing --Execute sudo / usr / bin / bluetoothctl and copy ↓.

    agent on
    default-agent
    scan on
    discoverable on
    

--Right-click the Windows Bluetooth icon to add a device.
image.pngimage.pngimage.png --When you see the number, you will see [agent] Confirm passkey 117747 (yes / no): on the side of the page. Then press yes [Enter] and press [Next] in the Windows dialog as well. => Drivers will be installed, so wait.

  1. Ctrl + a (release) c

  2. Local Keyboard Mirroring --Insert the USB keyboard and copy and paste below.

    cd
    cd BlogCode/btkeyboard/keyboard
    sudo python kb_client.py
    
    pi@raspberrypi:~/BlogCode/btkeyboard/keyboard$ sudo python kb_client.py
    Setting up keyboard
    setting up DBus Client
    waiting for keyboard
    found a keyboard
    starting event loop
    

=> You can operate it with a USB keyboard that is stuck in the bag.

Other

――When you turn the power off and then on again, it looks like this ??

```bash
#byobu launch
byobu


# Stop the background process
sudo /etc/init.d/bluetooth stop

# Open a dedicated terminal and tun the bluetooth daemon in the foreground
sudo /usr/sbin/bluetoothd --nodetach --debug -p time


######## Ctrl+a  c ########

sudo hciconfig hcio up
sudo hciconfig hcio


cd ${HOME}
cd BlogCode/btkeyboard/server
sudo python btk_server.py

######## Ctrl+a  c ########

sudo /usr/bin/bluetoothctl

agent on
default-agent
scan on
discoverable on


######## Ctrl+a  c ########

cd 
cd BlogCode/btkeyboard/keyboard
sudo python kb_client.py
```

Recommended Posts

[Note] Bluetooth keyboard emulation
Note
Note
Note