Trucrux Inc

Testing Bluetooth

Check Bluetooth node #

root@imx8mq-trux-q01:~# hciconfig -a

output

hci0: Type: Primary Bus: UART
BD Address: 20:50:E7:4B:F3:AD ACL MTU: 1021:8 SCO MTU: 64:1
DOWN 
RX bytes:738 acl:0 sco:0 events:41 errors:0
TX bytes:458 acl:0 sco:0 commands:41 errors:0
Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
Link policy: RSWITCH SNIFF 
Link mode: SLAVE ACCEPT

Note: #

If you don’t get Bluetooth node then, restart the bluetooth service using below command.

root@imx8mq-trux-q01:~# systemctl restart trucrux-bt

Enable Bluetooth node #

 

root@imx8mq-trux-q01:~# hciconfig hci0 up

Check for current Bluetooth devices #

root@imx8mq-trux-q01:~# hcitool dev

output

Devices:
hci0 20:50:E7:4B:F3:AD

Configure & Connect Bluetooth #

To use Bluetooth utility open bluetooth command line using:

root@imx8mq-trux-q01:~# bluetoothctl

Power On Bluetooth node

[bluetooth]# power on
Changing power on succeeded

Reset Agent

[bluetooth]# agent off
Agent unregistered
Controller 20:50:E7:4B:F3:AD Pairable: no
[bluetooth]# agent on
Agent registered
Controller 20:50:E7:4B:F3:AD Pairable: yes
[bluetooth]# default-agent
Default agent request successful

Set host Bluetooth as Parable

[bluetooth]# pairable on
Changing pairable on succeeded

Set host Bluetooth as Discoverable

[bluetooth]# discoverable on
Controller 20:50:E7:4B:F3:AD Class: 0x003c0100
Changing discoverable on succeeded
Controller 20:50:E7:4B:F3:AD Discoverable: yes

Scan for available Bluetooth devices

[bluetooth]# scan on
Discovery started
Controller 20:50:E7:4B:F3:AD Discovering: yes
Device FC:D4:36:06:BF:EF Trunexa
Device FC:D4:36:06:BF:EF RSSI: -84

Turn off Sacn

[bluetooth]# scan off
Discovery stopped

Pair with device

[bluetooth]# pair <Device_MAC>

Confirm all the pass key and Authorise service

Disconnect from paired device

[Trunexa]# disconnect
Attempting to disconnect from FC:D4:36:06:BF:EF
Device FC:D4:36:06:BF:EF ServicesResolved: no
Successful disconnected
Device FC:D4:36:06:BF:EF Connected: no

Terminate Bluetooth session

[bluetooth]# exit

Send File via Bluetooth to paired device #

Open obex command line for data transfer from host device to paired device

root@imx8mq-trux-q01:~# DBUS_SESSION_BUS_ADDRESS=unix:path=/var/run/dbus/system_bus_socket obexctl

Connect to paired Device

[obex]# connect <Device_MAC>
Attempting to connect to <Device_MAC>
Session /org/bluez/obex/client/session1 [default]
ObjectPush /org/bluez/obex/client/session1 
Connection successful

Send File to Paired Device

[Device_MAC]# send /home/root/test_file.txt 
Attempting to send /home/root/test_file.txt to /org/bluez/obex/client/session1
Transfer /org/bluez/obex/client/session1/transfer0 
Transfer /org/bluez/obex/client/session1/transfer0
Status: queued
Name: test_file.txt
Size: 15
Filename: /home/root/test_file.txt
Session: /org/bluez/obex/client/session1
Transfer /org/bluez/obex/client/session1/transfer0 Status: complete
Transfer /org/bluez/obex/client/session1/transfer0

Note: Enter the full path of the file, Here the file test_file.txt is stored in /home/root/

Terminate obex session

[Device_MAC]# quit

Receive File via Bluetooth from paired device #

  1. Connect your host device and the device you want to get the file from.
  2. Sent the file from paired deice.
  3. After successful transfer of file, the file will be stored in /tmp/bluetooth-inbox/