Howto: Getting Bluetooth (serial console) working on Debian
#1
Information 
Tested on a Pine64+ 1GB running Debian 8 “jessie” (3.10.102-3) using the official WIFI 802.11BGN/BLUETOOTH 4.0 Module.

What's it all about? These were the steps I followed to be able to view the text output of a bluetooth-enabled USB power meter, and most of these steps apply to getting bluetooth working at all if it isn't already configured in your chosen image. If it is already enabled, you can probably jump straight to step 5. Regardless, steps 1-5 should get your bluetooth working and a device paired with your pine64, but what you do after that if you don't want the text output (ie. you instead want a bluetooth mouse, audio) like I did I wouldn't know! ;)


Step 1: Make sure you have the bluetooth stack and utilities installed! If you want to all make sure you have  all of the stuff this guide uses in one hit, you can add "rfkill git screen minicom" to the list of stuff to install.
sudo apt-get install bluez


Step 2:
Get the firmware binaries for the BT from https://github.com/lwfinger/rtl8723bs_bt

This repo contains the programs and firmware to operate the Bluetooth section of the RTL8723BS. This basically loads the firmware into the module, which makes it a bluetooth module! if you don't have git, install it by running "sudo apt-get install git".


Quote:git clone https://github.com/lwfinger/rtl8723bs_bt.git


Step 3:
Compile and load the firmware.
Change into the newly cloned repo, and run "make", which will compile the main program needed, rtk_hciattach. Then run "sudo make install" to install the firmware.

You’ll then want the following command to run at bootup, so perhaps put it in /etc/rc.local. For the moment though, you can run it as shown below.

Quote:sudo ./start_bt.sh


This is the command that does real magic… it configures the BT module and makes it available for use. 


Step 4: Remove soft block, scan for devices
For some reason or another, the device is "soft blocked" (meaning it is blocked by software),  which is easy to fix when you know how. Run

Quote:sudo rfkill list

and you should see something like this (if you don’t, something has gone horribly, horribly wrong already). If you get a message saying rfkill can’t be found, thats ok… just run "sudo apt-get install rfkill" to install it, and try again.

Quote:0: sunxi-bt: Bluetooth
Soft blocked: no
Hard blocked: no
1: phy0: Wireless LAN
Soft blocked: no
Hard blocked: no
2: phy1: Wireless LAN
Soft blocked: no
Hard blocked: no
3: hci0: Bluetooth
Soft blocked: yes
Hard blocked: no


The entry of interest is the last one (the one for hci0: Bluetooth). That is the bluetooth adapter we’re trying to use, and as you can see, it is currently soft blocked. To fix that, just run (if yours is listed as 3 also)

Quote:sudo rfkill unblock 3

and it will be unblocked. You sould then see if you run "sudo rfkill list" again that this is the case, and if you run hcitool dev, you should also have something like this as the ouput, listing the MAC address of the pine64’s BT adapter.

Quote:Devices:
hci0 34:C3:D2:71:BE:ED


Step 5: Power on bluetooth module and pair your device
You can then run bluetoothctl (as sudo) in order tha manage the bluetooth connection. Install via ‘sudo apt-get install bluez-utils’ if it is missing. You should get an immediate message about a new bluetooth controller… this is a good sign… everything is working so far if you get that message. If you get a  message about no default controller, something is wrong. Assuming you don’t have any issues, run the following commands, which power on the BT module and sets it as the default BT agent.

Quote:power on
agent on
default-agent

If all has gone well, you should be seeing something like this.

Quote:[NEW] Controller 34:C3:D2:71:BE:ED pine64 [default]
[NEW] Device 00:BA:55:56:D8:7E SPP-CA
[bluetooth]# power on
Changing power on succeeded
[bluetooth]# agent on
Agent registered
[bluetooth]# default-agent
Default agent request successful


You can then then enter "scan on" to start discovery of BT devices, and if you have any devices available for pairing, you should see messages about them appear (prefixed by [NEW]). If they’re not ready for pairing, this is the time to make them ready.

Once your device appears, you can run "scan off" to make the system a bit more responsive again, as it seems pretty laggy at times whilst the scan process is running.

To pair the device you’re trying to pair the pine64 with, enter  the command "pair <your-bluetooth-deviceaddress>" . For example, my USB power meter with BT serial had an address of  “00:BA:55:56:D8:7E”, so I entered “pair 00:BA:55:56:D8:7E” and entered the device pin when prompted. Once you see a message about the pair being successful (I had to do it a couple of times, it didn’t seem to take the first time) you can exit the bluetoothctl program with the quit command.


Step 6: Bind  bluetooth device for usage
This step is what makes the bluetooth device available for you to access. It’s really simple.. just run "sudo rfcomm bind hci0 <your-bluetooth-device-address>"

For example,

Quote:sudo rfcomm bind hci0 00:BA:55:56:D8:7E


This binds hci0 (which you might remember from the rfkill list output from earlier) to the bluetooth device you specificied (usb power meter in my case).


Step 7: Do something with it!
Since I simply wanted to view the serial output from the meter, and I prefer using screen I ran

Quote:sudo screen /dev/rfcomm0 9600

in order to connect to the bluetooth device (made available at /dev/rfcomm0) at 9600 baud. (run "sudo apt-get install screen" to use screen as it’s not installed by default). For those of you who prefer minicom, you could do the same thing by running

Quote:sudo minicom -D /dev/rfcomm0 -b 9600

And then try figuring out how to exit it – hint: it’s Ctrl+a, z, q, enter).I then get a line like this every 5 seconds (the  update rate I have the meter set to) telling me the voltage and amperage being measured by the meter. Success!

Quote:052496,005516
052496,005420

All it needs then is some simple decoding to change the interger values sent to their decimal equivalents (ie. the second line is 5.2496v and 0.5420A).

Assuming you were working with a device that didn’t work one way (the meter only ouputs the data, it doesn’t have any configuration or anything over the BT link), you sould then have proper two-way communication via your device and the pine64 over bluetooth!



Acknowledgements:
This information/guide would not be possible without the following sources:

Errata:

2016-09-25 - removed redundant part of step 3
2016-10-10 - removed reference to bluez-utils as isn't needed (or available!) for jessie
  Reply


Messages In This Thread
Howto: Getting Bluetooth (serial console) working on Debian - by pfeerick - 09-20-2016, 03:18 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Wifi / Bluetooth Board Update S265 2 4,155 07-30-2020, 04:53 PM
Last Post: S265
  Create a WiFi hotspot on Debian 8 JulianM 6 27,047 03-10-2019, 01:02 AM
Last Post: waqasnasir
  RTL8723bs Bluetooth xalius 21 33,230 03-22-2017, 04:53 PM
Last Post: JulianM
  WIFI & Bluetooth? 7777777 14 28,102 12-24-2016, 05:01 AM
Last Post: Toriless
  Using Bluetooth for Sending serial data Arjun 9 14,707 10-19-2016, 10:19 PM
Last Post: Arjun
  How can you get the WIFI/Bluetooth module separate? GoZone 8 11,328 07-06-2016, 05:23 PM
Last Post: JasperBrown
  WiFi/BT module, no bluetooth riviera89 5 7,209 06-24-2016, 04:32 PM
Last Post: srinivas.s34@gmail.com
  Board doesn't boot when wifi/Bluetooth connected with Lcd screen Krinilssen 4 6,802 06-16-2016, 07:22 AM
Last Post: Krinilssen
  WIFI/Bluetooth Chipset monmoonmooonmoooon 2 5,120 01-20-2016, 06:02 AM
Last Post: monmoonmooonmoooon

Forum Jump:


Users browsing this thread: 1 Guest(s)