Wednesday, February 19, 2014

Adding Bluetooth as console connection on Raspberry Pi

Hacking Raspberry Pi is fun. But as with all hacking activities it sometimes goes wrong — lost IP address, wireless LAN do not connect anymore, disks that are offline, etc. When it goes wrong it is always good to have access to the Linux console. Diagnose and to restore the system to a known state is much simpler with such access. But hacking and building Pi's sometimes leads to Pi's located in hard to reach places such as the roof of the garage, the attic, or deep in the basement. Places where attaching a serial console is hard or even sometimes impossible. For those scenarios it would be perfect if the Linux console always is accessible and preferably so wirelessly. A wireless cable replacement technology that replaces a serial cable, and is supported by standard computer hardware, would be perfect for this task.

Enter Bluetooth SPP

There is one technology that fulfill all of the requirements above and more and that is Bluetooth Classic and the Bluetooth Serial Port Profile. Bluetooth Classic and the serial port profile is supported by most modern PC and hardware making it easy to operate. Besides being widely supported, it also has the stability and range needed for a reliable console connection. A Bluetooth Classic module of today has an operational range of up to 300 meters and with a speed of ~1Mbps. Very useful when the system is located on the roof top!

Adding a wireless connection

To make the console wireless a ready-to-use Bluetooth Classic device with the serial port profile is needed. In this guide the connectBlue cB-OBS419i serial port adapter is used. It is a ready-to-use Classic Bluetooth serial port module with a simple configuration interface.
The cB-OBS419i can be found on e.g. DigiKey.

Note; Serial console connectivity can be done using a Bluetooth USB dongle and some Bluez configuration. However, by using a serial port module you separate Linux config/setup/hacking from the default console and thus minimizing the risk of not reaching the console when all is lost.

Initial configuration

The default serial configuration of connectBlue's cB-OBS419i is 57600 baud and hardware flow control on. This config do not match the Raspberry Pi's console settings at all so some reconfiguration is needed. To change settings the Bluetooth module needs to be made accessible to a computer. This is easiest by using the connectBlue USB module adapter cB-ACC-34. An alternative is to use the FTDI TTL-232R-3V3 cable.

Once attached to a PC, Mac, or other hardware, connect to the module using a terminal application such as minicom or TeraTerm and issue the escape sequence '///' to enter command mode. 

First the serial baud rate needs to be increased to 115200 baud and flow control needs to be shut off. Both are changed using one single command called AT*AMRS. (All of the configuration commands are documented in the connectBlue Bluetooth Serial Port Adapter AT Commands.) 

Before changing the serial setting it is wise to reset all settings to factory defaults. Use the AT&F command to reset all settings to factory defaults.

AT&F
OK

Now, change serial baud rate and turn off flow control.

AT*AMRS=9,1,1,1,2,0,1
OK

Finally, set a more descriptive name so the console port is easier to find.

AT*AGLN="Raspberry Pi Console",1

All settings are stored in non-volatile memory so this configuration is not needed to be done again.

Connect to Raspberry Pi console pins

The Raspberry Pi console interface is located on the GPIO pin header P1, pin 8 (Tx) and 10 (Rx). These two pins needs to be wired to the Rx and Tx pins of the Bluetooth module in a crossed manner. That is, Rx on the Pi connects to Tx on OBS419i and vice versa. Besides Rx and Tx, power (VCC) and GND are needed for operating the Bluetooth module. The connectBlue module is capable of handling VCC input up to 6VDC meaning that the module can be powered directly from the +5VDC pin. 

cB-OBS419i has several host interface alternatives. For this guide host interface J6 is used. 4 cables are directly soldered on OBS419i J6 connector. Pins used are J6-3 (GND), J6-4 (VCC), J6-11 (Tx), and J6-13 (Rx).

Connection list:

P1-4 (+5VDC) ->  J6-4  (VCC)
P1-6 (GND)   ->  J6-3  (GND)
P-8  (Tx)    ->  J6-13 (Rx)
P-10 (Rx)    ->  J6-11 (Tx)

See the cB-OBS419 Electrical Mechanical Data Sheet for details about pin out etc.


The Raspberry Pi Bluetooth Linux console adapter is now ready for use.

Test

Connect the 4x1 header to the Raspberry Pi GPIO pin list. Power on and the Bluetooth console connection will be ready for a connection. Scan for the device and use your Bluetooth connection manager to create a virtual serial port. Below shows how it look like on a Mac.



The Bluetooth Manager on Mac will automatically create a TTY in /dev/ that can be used to initiate a connection. The name is derived from Bluetooth service name. Simply call e.g. minicom with the TTY as an argument like this:


Now the console is connected and ready to use. Login using your ordinary credentials. 


Finally

Do not forget to change the default Raspberry Pi password. Adding a wireless connectivity will make it easy for others to connect too. Best is to enable Bluetooth link security but this is out of scope for this short guide. The Bluetooth Serial Port Adapter Security document is a good read on Bluetooth security and how to enable it.

1 comment:

Matthew Siebenhuhner said...

I am trying to do this as well, but I run into the issue where I cannot simply access the terminal using the 'screen' command in Mac. I get a blank screen that only begins to show information when I run 'sudo reboot', which is not very helpful.

Thoughts?