Bluetooth dongle and Raspberry Pi
I found one old bluetooth dongle in my drawer from time when it was the only way to get files from or to my Siemens mobile :) So I decided to try to plug it into RPi. It works, even it is bought from dx.com for 1$ many years ago.
My intention was to make RPi accept files that I send from my mobile or any bluetooth capable device. At first install required packages...
apt-get install bluetooth bluez
After successful installation, connect your bluetooth dongle and list USB devices.
You should see dongle in statement like this:
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 005: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
Now, when you are sure your device is recognized, list bluetooth devices.
You will get output with adapter name and its MAC address:
If you want detailed information about hci device, use this command:
I use this command because in output I can see how many bytes was transmitter and received.
hci0: Type: BR/EDR Bus: USB
BD Address: 00:15:83:xx:xx:xx ACL MTU: 672:3 SCO MTU: 128:2
UP RUNNING PSCAN
RX bytes:914 acl:0 sco:0 events:30 errors:0
TX bytes:360 acl:0 sco:0 commands:23 errors:0
Features: 0xff 0x3e 0x85 0x30 0x18 0x18 0x00 0x00
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: RSWITCH HOLD SNIFF
Link mode: SLAVE ACCEPT
Service Classes: Unspecified
Device Class: Phone, Cordless
HCI Version: 2.0 (0x3) Revision: 0xc5c
LMP Version: 2.0 (0x3) Subversion: 0xc5c
Manufacturer: Cambridge Silicon Radio (10)
Now you can try to scan for devices in the area.
And it finds my phone...
Of course your device have to be discoverable. But how to make RPi discoverable when some user is scanning for it?
hciconfig hci0 piscan
If you reissue "hciconfig -a" you will see added flag ISCAN - which means device is discoverable. I tried to discover new devices in my mobile phone and...
Next step will be pairing. When 2 devices want to communicate via bluetooth, have to be "introduced" at first (enter same PIN on both devices). First, set PIN on RPi with:
Bluetooth agent will not stop. Now you can initiate pairing from mobile...
During pairing attemp, bluetooth-agent will print notification...
Pincode request for device /org/bluez/2061/hci0/dev_64_99_5D_xx_xx_xx
Enter PIN and "OK", Now devices should be paired and able to communicate with each other.
After successful pairing, you can stop bluetooth-agent with Ctrl+C. Now when devices are paired, you can try to ping them.
l2ping -i hci0 64:99:5D:xx:xx:xx
Change address in black bold to your device`s MAC address. It can be found in output of "hcitool scan"
Ping: 64:99:5D:xx:xx:xx from 00:15:83:xx:xx:xx (data size 44) ...
44 bytes from 64:99:5D:xx:xx:xx id 0 time 18.01ms
44 bytes from 64:99:5D:xx:xx:xx id 1 time 34.66ms
44 bytes from 64:99:5D:xx:xx:xx id 2 time 17.65ms
44 bytes from 64:99:5D:xx:xx:xx id 3 time 31.80ms
44 bytes from 64:99:5D:xx:xx:xx id 4 time 14.95ms
5 sent, 5 received, 0% loss
Now when we are sure devices can talk to each other, you can make RPi to automaticaly accept files transmitted.
obexpushd -B -o /root/bluetooth
Tried to transmit a file, and success...
Address in black bold is destination, where files will be stored. My RPi bluetooth dongle is always visible, but if you want to hide it, after successful pairing, you can make RPi invisible again by issuing:
hciconfig hci0 noscan
Of course, all of this can be available from start. Edit crontab...
And add following lines.
@reboot sudo -u root hciconfig hci0 piscan #make RPi discoverable
@reboot sudo -u root obexpushd -B -o /root/bluetooth #accept files from paired devices and save to /root/bluetooth
@reboot sudo -u root bluetooth-agent 4554 & #set PIN for pairing
Edit statements in black bold. Now close file (CTRL+X...) and save changes (...press "y" and Enter). Reboot and try if all is working from start.