[태그:] bluetooth

  • raspberry pi4 bluetooth pairing with cli

    살다 보면 터미널로 블루투스 페이링을 할 필요가 있다. bluetoothctl가 제공하는 scan on, pair, trust, connect로 가능하다.

    [bluetooth]# pair 34:88:5D:5C:C2:65
    Device 34:88:5D:5C:C2:65 not available
    [bluetooth]# scan on
    Discovery started
    [CHG] Controller AA:AA:AA:AA:AA:AA Discovering: yes
    [CHG] Device 74:31:32:C6:8F:67 RSSI: -72
    [CHG] Device 74:31:32:C6:8F:67 TxPower: 12
    [CHG] Device 00:17:55:B0:CF:2E RSSI: -84
    [CHG] Device 5F:B7:26:83:54:58 RSSI: -73
    [CHG] Device 5F:B7:26:83:54:58 TxPower: 26
    [CHG] Device 75:CB:B4:32:0F:29 RSSI: -85
    [CHG] Device 5F:5C:FD:38:FC:36 RSSI: -84
    [CHG] Device 5F:5C:FD:38:FC:36 TxPower: 6
    [CHG] Device 68:47:92:B1:39:9C RSSI: -73
    [CHG] Device 68:47:92:B1:39:9C TxPower: 8
    [CHG] Device 58:7B:3E:E0:3F:F5 RSSI: -72
    [CHG] Device 58:7B:3E:E0:3F:F5 TxPower: 7
    [CHG] Device 42:39:EF:80:06:A0 RSSI: -71
    [CHG] Device 42:39:EF:80:06:A0 TxPower: 12
    [CHG] Device 00:17:55:B0:CF:2C RSSI: -89
    [CHG] Device 00:17:55:B0:CC:14 RSSI: -79
    [CHG] Device 7D:72:08:EE:56:18 RSSI: -72
    [CHG] Device 7D:72:08:EE:56:18 TxPower: 24
    [CHG] Device 42:39:EF:80:06:A0 AdvertisingFlags:
      00                                               .               
    [CHG] Device 00:17:55:B0:C3:AA RSSI: -88
    [CHG] Device 43:AF:C1:01:A4:9E RSSI: -73
    [CHG] Device 43:AF:C1:01:A4:9E TxPower: 7
    [CHG] Device 00:17:55:B0:CF:27 RSSI: -89
    [CHG] Device 00:17:55:B0:CC:16 RSSI: -91
    [CHG] Device 43:AF:C1:01:A4:9E AdvertisingFlags:
      00                                               .               
    [CHG] Device 00:17:55:B0:CC:16 AdvertisingFlags:
      00                                               .               
    [CHG] Device 00:17:55:B0:CF:27 AdvertisingFlags:
      00                                               .               
    [CHG] Device 53:02:B7:C1:DA:EF RSSI: -90
    [CHG] Device 00:17:55:B0:CF:2C AdvertisingFlags:
      00                                               .               
    [CHG] Device 53:02:B7:C1:DA:EF AdvertisingFlags:
      00                                               .               
    [NEW] Device 34:88:5D:5C:C2:65 Keyboard K480
    [CHG] Device DC:B5:4F:0A:1B:C7 RSSI: -79
    [bluetooth]# pair 34:88:5D:5C:C2:65
    Attempting to pair with 34:88:5D:5C:C2:65
    Failed to pair: org.bluez.Error.ConnectionAttemptFailed
    [CHG] Device 42:39:EF:80:06:A0 AdvertisingFlags:
      1a                                               .               
    [CHG] Device 00:17:55:B0:CC:16 AdvertisingFlags:
      06                                               .               
    [CHG] Device 2E:23:6D:1E:EC:1A RSSI: -85
    [CHG] Device 43:AF:C1:01:A4:9E AdvertisingFlags:
      1a                                               .               
    [CHG] Device 00:17:55:B0:CF:27 AdvertisingFlags:
      06                                               .               
    [CHG] Device 70:4A:71:F9:0C:89 RSSI: -92
    [CHG] Device 70:4A:71:F9:0C:89 TxPower: 7
    [CHG] Device 70:4A:71:F9:0C:89 AdvertisingFlags:
      1a                                               .               
    [CHG] Device 53:02:B7:C1:DA:EF AdvertisingFlags:
      02                                               .               
    [CHG] Device 68:47:92:B1:39:9C RSSI: -86
    [CHG] Device 75:CB:B4:32:0F:29 RSSI: -97
    [NEW] Device 00:17:55:B0:CE:F5 44881938.01000222
    [CHG] Device 53:02:B7:C1:DA:EF AdvertisingFlags:
      00                                               .               
    [CHG] Device 00:17:55:B0:CF:2C AdvertisingFlags:
      06                                               .               
    [bluetooth]# pair 34:88:5D:5C:C2:65
    Attempting to pair with 34:88:5D:5C:C2:65
    [CHG] Device 34:88:5D:5C:C2:65 Connected: yes
    [agent] Passkey: 091237
    [agent] Passkey: 091237
    [agent] Passkey: 091237
    [agent] Passkey: 091237
    [agent] Passkey: 091237
    [agent] Passkey: 091237
    [agent] Passkey: 091237
    [CHG] Device 34:88:5D:5C:C2:65 Modalias: usb:v046DpB33Cd2802
    [CHG] Device 34:88:5D:5C:C2:65 UUIDs: 00001000-0000-1000-8000-00805f9b34fb
    [CHG] Device 34:88:5D:5C:C2:65 UUIDs: 00001124-0000-1000-8000-00805f9b34fb
    [CHG] Device 34:88:5D:5C:C2:65 UUIDs: 00001200-0000-1000-8000-00805f9b34fb
    [CHG] Device 34:88:5D:5C:C2:65 ServicesResolved: yes
    [CHG] Device 34:88:5D:5C:C2:65 Paired: yes
    Pairing successful
    [CHG] Device 34:88:5D:5C:C2:65 ServicesResolved: no
    [CHG] Device 34:88:5D:5C:C2:65 Connected: no
    [CHG] Device 00:17:55:B0:CC:14 RSSI: -89
    [CHG] Device 53:02:B7:C1:DA:EF AdvertisingFlags:
      02                                               .               
    [CHG] Device 68:47:92:B1:39:9C RSSI: -78
    [CHG] Device 5F:5C:FD:38:FC:36 ManufacturerData Key: 0x004c
    [CHG] Device 5F:5C:FD:38:FC:36 ManufacturerData Value:
      10 06 7e 1e 2a 4b a0 b5                          ..~.*K..        
    [CHG] Device 75:CB:B4:32:0F:29 RSSI: -88
    [CHG] Device 75:CB:B4:32:0F:29 AdvertisingFlags:
      00                                               .               
    [CHG] Device 74:31:32:C6:8F:67 RSSI: -87
    [CHG] Device 7F:70:C6:B1:18:7B RSSI: -90
    [CHG] Device 7F:70:C6:B1:18:7B TxPower: 12
    [CHG] Device 00:17:55:B0:CF:27 AdvertisingFlags:
      00                                               .               
    [bluetooth]# trust 34:88:5D:5C:C2:65
    [CHG] Device 34:88:5D:5C:C2:65 Trusted: yes
    Changing 34:88:5D:5C:C2:65 trust succeeded
    [CHG] Device 74:31:32:C6:8F:67 RSSI: -71
    [CHG] Device 00:17:55:B0:CC:14 RSSI: -80
    [CHG] Device 75:CB:B4:32:0F:29 AdvertisingFlags:
      02                                               .               
    [NEW] Device 79:2D:EA:FA:C8:07 79-2D-EA-FA-C8-07
    [CHG] Device 43:AF:C1:01:A4:9E AdvertisingFlags:
      00                                               .               
    [CHG] Device 42:39:EF:80:06:A0 AdvertisingFlags:
      00                                               .               
    [CHG] Device 68:47:92:B1:39:9C AdvertisingFlags:
      00                                               .               
    [CHG] Device 53:02:B7:C1:DA:EF AdvertisingFlags:
      00                                               .               
    [CHG] Device 00:17:55:B0:C3:D0 RSSI: -94
    [CHG] Device 00:17:55:B0:CF:27 AdvertisingFlags:
      06                                               .               
    [DEL] Device 7D:72:08:EE:56:18 7D-72-08-EE-56-18
    [DEL] Device 00:17:55:B0:CF:2E 44881995.01000222
    [DEL] Device 5F:B7:26:83:54:58 5F-B7-26-83-54-58
    [DEL] Device 72:1E:96:C2:47:34 72-1E-96-C2-47-34
    [DEL] Device 74:31:32:C6:8F:67 74-31-32-C6-8F-67
    [DEL] Device 5F:5C:FD:38:FC:36 5F-5C-FD-38-FC-36
    [DEL] Device 58:7B:3E:E0:3F:F5 58-7B-3E-E0-3F-F5
    [DEL] Device 68:47:92:B1:39:9C 68-47-92-B1-39-9C
    [DEL] Device 00:17:55:B0:CC:14 44881201.01000222
    [DEL] Device 42:39:EF:80:06:A0 42-39-EF-80-06-A0
    [DEL] Device 2E:23:6D:1E:EC:1A 2E-23-6D-1E-EC-1A
    [DEL] Device 52:16:A9:CA:B5:11 52-16-A9-CA-B5-11
    [DEL] Device 00:17:55:B0:CF:27 44881988.01000222
    [DEL] Device 7F:70:C6:B1:18:7B 7F-70-C6-B1-18-7B
    [DEL] Device 50:1E:AF:D4:17:76 50-1E-AF-D4-17-76
    [DEL] Device 00:17:55:B0:C3:AA 44879047.01000222
    [DEL] Device 6F:3D:D3:F2:4A:31 6F-3D-D3-F2-4A-31
    [DEL] Device DC:B5:4F:0A:1B:C7 Mike Bouchon
    [DEL] Device 00:17:55:B0:CC:16 44881203.01000222
    [DEL] Device 6F:44:C7:02:3B:D0 6F-44-C7-02-3B-D0
    [DEL] Device 4A:41:FE:14:FE:2A 4A-41-FE-14-FE-2A
    [DEL] Device 00:17:55:B0:CF:17 00-17-55-B0-CF-17
    [DEL] Device 40:CC:C6:57:E4:40 40-CC-C6-57-E4-40
    [DEL] Device 00:17:55:B0:CF:25 44881986.01000222
    [DEL] Device 70:4A:71:F9:0C:89 70-4A-71-F9-0C-89
    [DEL] Device 00:17:55:B0:CF:2C 44881993.01000222
    [DEL] Device 00:17:55:B0:C3:D0 00-17-55-B0-C3-D0
    [DEL] Device 76:7F:82:5E:9F:77 76-7F-82-5E-9F-77
    [DEL] Device 53:02:B7:C1:DA:EF 53-02-B7-C1-DA-EF
    [DEL] Device 57:09:04:A4:37:BD 57-09-04-A4-37-BD
    [DEL] Device 75:CB:B4:32:0F:29 75-CB-B4-32-0F-29
    [DEL] Device 43:AF:C1:01:A4:9E 43-AF-C1-01-A4-9E
    [DEL] Device 00:17:55:B0:CE:F5 44881938.01000222
    [DEL] Device 79:2D:EA:FA:C8:07 79-2D-EA-FA-C8-07
    [NEW] Device 7F:70:C6:B1:18:7B 7F-70-C6-B1-18-7B
    [bluetooth]# connect 34:88:5D:5C:C2:65
    Attempting to connect to 34:88:5D:5C:C2:65
    [CHG] Device 34:88:5D:5C:C2:65 Connected: yes
    Connection successful
    [NEW] Device DC:B5:4F:0A:1B:C7 Mike Bouchon
    [CHG] Device 34:88:5D:5C:C2:65 ServicesResolved: yes
    [NEW] Device 43:AF:C1:01:A4:9E 43-AF-C1-01-A4-9E
    [NEW] Device 5F:B7:26:83:54:58 5F-B7-26-83-54-58
    [NEW] Device 53:02:B7:C1:DA:EF 53-02-B7-C1-DA-EF
    [NEW] Device 7D:72:08:EE:56:18 7D-72-08-EE-56-18
    [NEW] Device 68:47:92:B1:39:9C 68-47-92-B1-39-9C
    [NEW] Device 10:B8:5D:5C:03:7E 10-B8-5D-5C-03-7E
    [NEW] Device 6F:1D:B5:96:AE:86 6F-1D-B5-96-AE-86
    [NEW] Device 74:31:32:C6:8F:67 74-31-32-C6-8F-67
    [NEW] Device 00:17:55:B0:CF:2E 44881995.01000222
    [NEW] Device 75:CB:B4:32:0F:29 75-CB-B4-32-0F-29
    [NEW] Device 42:39:EF:80:06:A0 42-39-EF-80-06-A0
    [NEW] Device 79:2D:EA:FA:C8:07 79-2D-EA-FA-C8-07
    [NEW] Device 00:17:55:B0:CF:27 44881988.01000222
    [NEW] Device 6F:3D:D3:F2:4A:31 6F-3D-D3-F2-4A-31
    [NEW] Device 00:17:55:B0:CC:14 44881201.01000222
    [NEW] Device 00:17:55:B0:C3:AA 44879047.01000222
    [CHG] Device 00:17:55:B0:CF:27 AdvertisingFlags:
      00                                               .               
    [NEW] Device 00:17:55:B0:CF:2C 44881993.01000222
    [NEW] Device 00:17:55:B0:CC:16 44881203.01000222
    [CHG] Device DC:B5:4F:0A:1B:C7 RSSI: -80
    

    처음 블루투스를 실행하면 잘 안되는데, 여기를 참조했다. ExecStart에 옵션을 잘 넣어주면 된다.

    pi@raspberrypi:/etc/systemd/system/bluetooth.target.wants $ pwd
    /etc/systemd/system/bluetooth.target.wants
    pi@raspberrypi:/etc/systemd/system/bluetooth.target.wants $ cat bluetooth.service bluetooth.service 
    [Unit]
    Description=Bluetooth service
    Documentation=man:bluetoothd(8)
    ConditionPathIsDirectory=/sys/class/bluetooth
    
    [Service]
    Type=dbus
    BusName=org.bluez
    #ExecStart=/usr/lib/bluetooth/bluetoothd
    ExecStart=/usr/lib/bluetooth/bluetoothd --compat --noplugin=sap -E 
    NotifyAccess=main
    #WatchdogSec=10
    #Restart=on-failure
    CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
    LimitNPROC=1
    ProtectHome=true
    ProtectSystem=full
    
    [Install]
    WantedBy=bluetooth.target
    Alias=dbus-org.bluez.service
    [Unit]
    Description=Bluetooth service
    Documentation=man:bluetoothd(8)
    ConditionPathIsDirectory=/sys/class/bluetooth
    
    [Service]
    Type=dbus
    BusName=org.bluez
    #ExecStart=/usr/lib/bluetooth/bluetoothd
    ExecStart=/usr/lib/bluetooth/bluetoothd --compat --noplugin=sap -E 
    NotifyAccess=main
    #WatchdogSec=10
    #Restart=on-failure
    CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
    LimitNPROC=1
    ProtectHome=true
    ProtectSystem=full
    
    [Install]
    WantedBy=bluetooth.target
    Alias=dbus-org.bluez.service