Linux Bluetooth Obex: Difference between revisions

From Variscite Wiki
No edit summary
 
(10 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{PageHeader|Bluetooth File Transfer}} {{DocImage|category1=Yocto|category2=VAR-SOM-MX6}}[[Category: DART-6UL]][[Category: VAR-SOM-MX7]] __toc__
{{PageHeader|Bluetooth File Transfer}}  
{{DocImage|category1=Yocto|category2=Debian}}[[Category:VAR-SOM-MX6]][[Category: DART-6UL]][[Category: VAR-SOM-MX7]][[Category:DART-MX8M]][[Category:DART-MX8M-MINI]][[Category:DART-MX8M-PLUS]] __toc__


= Pairing with Bluetooth device =
= Pairing with Bluetooth device =
Before sending files bluetooth devices should be paired.
To send files to each other two bluetooth devices should be paired first. Use '''bluetoothctl''' tool to manage the pairing
You can manage bluetooth with '''bluetoothctl''', type 'bluetoothctl' and enter the CLI. Type help to show commands.</br>
 
For pairing a device do the following:</br>
<pre>
<pre>
$ bluetoothctl
# bluetoothctl
[bluetooth]# power on
[bluetooth]# power on
[bluetooth]# agent on
[bluetooth]# default-agent
[bluetooth]# pairable on
[bluetooth]# pairable on
[bluetooth]# scan on
[bluetooth]# scan on
Line 22: Line 20:
[bluetooth]# trust <mac address>
[bluetooth]# trust <mac address>
[bluetooth]# quit
[bluetooth]# quit
</pre>
For example when pairing with a PC the following is done:
<pre>
# bluetoothctl
[NEW] Controller 96:93:E0:47:39:89 Variscite [default]
[bluetooth]# power on
[CHG] Controller 96:93:E0:47:39:89 Class: 0x300100
Changing power on succeeded
[CHG] Controller 96:93:E0:47:39:89 Powered: yes
[bluetooth]# pairable on
Changing pairable on succeeded
[bluetooth]# scan on
Discovery started
[CHG] Controller 96:93:E0:47:39:89 Discovering: yes
[bluetooth]# random: nonblocking pool is initialized
[NEW] Device B8:6C:E8:60:C0:8F Galaxy S5
[NEW] Device 00:1A:7D:DA:71:0B Ubuntu-PC
[bluetooth]# scan off
[CHG] Device 38:BC:1A:20:14:5D RSSI is nil
[CHG] Device 00:1A:7D:DA:71:0B RSSI is nil
[CHG] Device B8:6C:E8:60:C0:8F RSSI is nil
[CHG] Controller 96:93:E0:47:39:89 Discovering: no
Discovery stopped
[bluetooth]# pair 00:1A:7D:DA:71:0B
Attempting to pair with 00:1A:7D:DA:71:0B
[CHG] Device 00:1A:7D:DA:71:0B Connected: yes
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 00001104-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 00001105-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 00001106-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 00001112-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 0000112f-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 00001132-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 00001133-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 00005005-0000-1000-8000-0002ee000001
[CHG] Device 00:1A:7D:DA:71:0B Paired: yes
Pairing successful
[CHG] Device 00:1A:7D:DA:71:0B Connected: no
[bluetooth]# trust 00:1A:7D:DA:71:0B
[CHG] Device 00:1A:7D:DA:71:0B Trusted: yes
Changing 00:1A:7D:DA:71:0B trust succeeded
[bluetooth]# quit
[DEL] Controller 96:93:E0:47:39:89 Variscite [default]
#
</pre>
</pre>


Line 27: Line 76:


To send a file to a paired device use '''obexctl''' tool.
To send a file to a paired device use '''obexctl''' tool.
<pre>
# DBUS_SESSION_BUS_ADDRESS=unix:path=/var/run/dbus/system_bus_socket obexctl
[obex]# connect <mac address>
[obex]# send <file>
[obex]# quit
</pre>
{{note|Please when running send command remember to provide absolute path}}
For example, to send /etc/fstab file to a paired PC from the example above:
<pre>
<pre>
root@imx6ul-var-dart:~# obexctl  
# DBUS_SESSION_BUS_ADDRESS=unix:path=/var/run/dbus/system_bus_socket obexctl  
[NEW] Client /org/bluez/obex  
[NEW] Client /org/bluez/obex  
[obex]# connect 00:1A:7D:DA:71:0B
[obex]# connect 00:1A:7D:DA:71:0B

Latest revision as of 16:42, 15 March 2023

Bluetooth File Transfer

Pairing with Bluetooth device

To send files to each other two bluetooth devices should be paired first. Use bluetoothctl tool to manage the pairing

# bluetoothctl
[bluetooth]# power on
[bluetooth]# pairable on
[bluetooth]# scan on

Copy mac address

[bluetooth]# scan off
[bluetooth]# pair <mac address>

Approve pairing on Device if required

[bluetooth]# trust <mac address>
[bluetooth]# quit

For example when pairing with a PC the following is done:

# bluetoothctl
[NEW] Controller 96:93:E0:47:39:89 Variscite [default]
[bluetooth]# power on
[CHG] Controller 96:93:E0:47:39:89 Class: 0x300100
Changing power on succeeded
[CHG] Controller 96:93:E0:47:39:89 Powered: yes
[bluetooth]# pairable on
Changing pairable on succeeded
[bluetooth]# scan on
Discovery started
[CHG] Controller 96:93:E0:47:39:89 Discovering: yes
[bluetooth]# random: nonblocking pool is initialized
[NEW] Device B8:6C:E8:60:C0:8F Galaxy S5
[NEW] Device 00:1A:7D:DA:71:0B Ubuntu-PC
[bluetooth]# scan off
[CHG] Device 38:BC:1A:20:14:5D RSSI is nil
[CHG] Device 00:1A:7D:DA:71:0B RSSI is nil
[CHG] Device B8:6C:E8:60:C0:8F RSSI is nil
[CHG] Controller 96:93:E0:47:39:89 Discovering: no
Discovery stopped
[bluetooth]# pair 00:1A:7D:DA:71:0B
Attempting to pair with 00:1A:7D:DA:71:0B
[CHG] Device 00:1A:7D:DA:71:0B Connected: yes
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 00001104-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 00001105-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 00001106-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 00001112-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 0000112f-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 00001132-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 00001133-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1A:7D:DA:71:0B UUIDs: 00005005-0000-1000-8000-0002ee000001
[CHG] Device 00:1A:7D:DA:71:0B Paired: yes
Pairing successful
[CHG] Device 00:1A:7D:DA:71:0B Connected: no
[bluetooth]# trust 00:1A:7D:DA:71:0B
[CHG] Device 00:1A:7D:DA:71:0B Trusted: yes
Changing 00:1A:7D:DA:71:0B trust succeeded
[bluetooth]# quit
[DEL] Controller 96:93:E0:47:39:89 Variscite [default]
# 

Sending files using OBEX Protocol

To send a file to a paired device use obexctl tool.

# DBUS_SESSION_BUS_ADDRESS=unix:path=/var/run/dbus/system_bus_socket obexctl
[obex]# connect <mac address>
[obex]# send <file>
[obex]# quit
Please when running send command remember to provide absolute path

For example, to send /etc/fstab file to a paired PC from the example above:

# DBUS_SESSION_BUS_ADDRESS=unix:path=/var/run/dbus/system_bus_socket obexctl 
[NEW] Client /org/bluez/obex 
[obex]# connect 00:1A:7D:DA:71:0B
Attempting to connect to 00:1A:7D:DA:71:0B
[NEW] Session /org/bluez/obex/client/session0 [default]
[NEW] ObjectPush /org/bluez/obex/client/session0 
Connection successful
[00:1A:7D:DA:71:0B]# send /etc/fstab
Attempting to send /etc/fstab to /org/bluez/obex/client/session0
[NEW] Transfer /org/bluez/obex/client/session0/transfer0 
Transfer /org/bluez/obex/client/session0/transfer0
        Status: queued
        Name: fstab
        Size: 637
        Filename: /etc/fstab
        Session: /org/bluez/obex/client/session0
[CHG] Transfer /org/bluez/obex/client/session0/transfer0 Status: complete
[DEL] Transfer /org/bluez/obex/client/session0/transfer0 

Receiving files using OBEX Protocol

No special action is required to receive a file that was sent from a paired device. The file will be stored under /tmp/bluetooth-inbox.