LoginSignup
27
32

More than 3 years have passed since last update.

[メモ] らずぱいで、Bluetoothキーボードのエミュレーション

Last updated at Posted at 2017-04-02

概要

環境

  • Raspberry Pi: Zero W と 3 Model B で確認
    • Raspbian: 2017-03-02-raspbian-jessie-lite.img
    • USBキーボード - らずぱいに接続
  • Windows 7 64ビット: sshにて、らずぱいにログインして、設定した。あと、BTの接続テスト

手順

  1. Raspbian起動させる

    • microSDに、Raspbianイメージ焼く
    • 必要あれば、
      • ssh(空ファイル) と wpa_supplicant.conf(あれば)をFATパーティションに
      • sudo apt-get update && sudo apt-get upgrade
  2. 必要なパッケージ類のインストール

    • とりあえず、

      とりあえず
      sudo apt-get install -y htop byobu git-core python-dbus python-gtk2
      
    • Bluetooth関連

      Bluetooth関連
      sudo apt-get install -y python-gobject bluez bluez-tools bluez-firmware python-bluez python-dev python-pip
      sudo pip install evdev
      
  3. byobu起動

    • byobu [Enter] で起動
    • Ctrl+aする => 1 [Enter] (初回時のみ)
  4. 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
    
  5. Ctrl+a (離して) c

  6. 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
    

    ここで表示された、BD Addressを控えておく。
    => 例)BD Address: B8:27:EB:31:41:59 ACL MTU: 1021:8 SCO MTU: 64:1

    btk_server.pyを編集
    #Edit the Emulator Server Code
    cd ${HOME}
    cd BlogCode/btkeyboard/server
    #
    vi btk_server.py
    

    => MY_ADDRESSに先ほどのBD ADDRESS、MY_DEV_NAMEに適当な名前を入れる。
    MY_ADDRESS="B8:27:EB:31:41:59"
    MY_DEV_NAME="RPiZeroW_BTKb"

    EmulatorServer起動
    # Run Emulator Server
    cd ${HOME}
    cd BlogCode/btkeyboard/server
    sudo python btk_server.py
    
    (実行例)
    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
    
  7. Ctrl+a (離して) c

  8. Pairing

    • sudo /usr/bin/bluetoothctl を実行して、↓をこぴぺ。
    こぴぺ
    agent on
    default-agent
    scan on
    discoverable on
    
    • WindowsのBluetoothのアイコンを右クリック、デバイス追加。
      image.png image.png image.png
    • 数字見たいのが出てきたら、らずぱい側に、[agent] Confirm passkey 117747 (yes/no):のが表示される。そしたら、yes[Enter]して、Windowsのダイアログでも、[Next]を押す。=> ドライバ類がインストールされるので、待つ。
  9. Ctrl+a (離して) c

  10. Local Keyboard Mirroring

    • USBキーボードをらずぱいに挿して、以下、こぴぺ。
    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
    

    => らずぱいに刺さったUSBキーボードで、操作が行えるハズ。

その他

  • 電源を入れなおしたときは、こんな感じ??

    # byobu起動
    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
    
27
32
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27
32