10

I'm trying to connect to a Totalstation that doesn't offer bluetooth drivers. As I am doing this for purely diagnostic reasons, I'd like to see the raw output from the established serial connection.

What do I have to do to pipe all output from a bluetooth connection to a terminal?

  • Are you doing Bluetooth->Serial, Serial->Bluetooth, or two-way? – ζ-- Jan 29 '13 at 0:14
  • Totalstation Bluetooth<->Ubuntu Bluetooth. Given that the totalstation has the standard serial configuration over USB, I suspect it is establishing a serial connection over Bluetooth. Of course, I could be completely wrong, at which point the answer that I'm wrong and the bluetooth uses XYZ is completely permissible. – Brian Ballsun-Stanton Jan 29 '13 at 0:18
  • In terms of the two-way proof, I have managed to establish a blank serial connection via "screen" that causes an error beep on the device when I hit a key on the keyboard. So I suspect that I'm half-way there, I just don't know which half. – Brian Ballsun-Stanton Jan 29 '13 at 0:19
  • Can you draw up a quick diagram? I can't understand whether it's serial over or bluetooth over serial, as well as who's passing on the data to where. Just do it in GIMP or something and upload it here – ζ-- Jan 29 '13 at 0:20
  • Works very well but I run into some glitches with RFCOMM. When I connecting with SCREEN, some AT-Sequences is typed automatically "ATE1 E0"<RETURN> three times. Because of that, some "Login failed" appears at the Raspi side. After then, I can successfully login and use the terminal session w/o any further glitches. – Cody May 30 at 15:31
5
+100

As an addition to Brian's answer. Screen didnt work for me, immediately displaying [screen is terminating]

So I found this miniterm python script. Usage is similar:

sudo miniterm.py /dev/rfcomm0
12

1) Use hcitool scan to find the Mac address of the device.

The device should be set to slave mode with a known pin. If you don't use a known pin, ubuntu makes one up and you generally won't have time to enter it in the clunky menus of your measuring tool.

2) I'm not entirely sure this is necessary, but in the bluetooth gui menu, pair the device.

3) in /etc/bluetooth/rfcomm.conf

rfcomm0 {
        bind no;
        device 00:07:80:44:4F:37;
        channel 1;
        comment "Serial Port";
        }

The "bind no" is important, otherwise it will try to autmatically bind, which presents all sorts of problems for actually accessing the device (as it's quite picky about when its associated)

4) sudo rfcomm connect 0

If you have errors, restart the bluetooth service.

5) screen /dev/rfcomm0

For actual serial commands transmitted this way, contact your vendor and beg.

  • 3
    I get "Missing dev parameter" when I try to run "rfcomm connect 0" – someonewithpc Mar 27 '16 at 16:43
  • Did you edit your conf file correctly? – Brian Ballsun-Stanton Mar 28 '16 at 0:58
  • 5
    Try sudo rfcomm connect rfcomm0 00:07:80:44:4F:37 – elopio Jul 4 '16 at 5:52
  • @elopia's oneliner very simple. It worked for me – ptetteh227 Mar 31 '18 at 2:27
10

Here is my way to proceed to connect to a HC-05 bluetooth device plugged on my arduino. It does not need to write a file like in Brian's answer, but the idea is similar. I've tested it with a baud 9600 rate setup on the HC-05 device.

First step : pair the device and provide the PIN

I tried to setup from GUI the pairing, but it wasn't working. Here is the command line way to proceed that worked for me. First, let us pair the device from command line. Run :

sudo bluetoothctl

Be sure that the bluetooth device is started :

# power on

We now start the agent that will "remember the pin" for rfcomm :

# agent on

Now we enable the scan mode to find our device and be able to pair it :

# scan on

After a few seconds the MAC of your device should appear. We will denote it as after. Then, you just need to pair the device like this :

# pair <MAC>

You will be asked to type a PIN, by default it's 1234 on my HC-05 device. You can note that it's possible that you device connect then disconnect with a message like that :

[CHG] Device 20:16:10:24:29:77 UUIDs: 00001101-0000-1000-8000-00805f9b34fb
[CHG] Device 20:16:10:24:29:77 ServicesResolved: yes
[CHG] Device 20:16:10:24:29:77 Paired: yes
Pairing successful
[CHG] Device 20:16:10:24:29:77 ServicesResolved: no
[CHG] Device 20:16:10:24:29:77 Connected: no

but it's not a problem. You do not need to connect, so you can now quit bluetoothctl by typing Ctrl + D.

Provide a usable file /dev/rfcomm0

Firstly, be sure that you didn't run any rfcomm command before. Indeed, even if you close with Ctrl+C the program, it still run in background.

sudo killall rfcomm

Now, you can run

sudo rfcomm connect /dev/rfcomm0 20:16:10:24:29:77 1 &

Note that if you try to write on the input of rfcom, nothing happened. You need to use another program.

Third and last step : write into the /dev/rfcomm0

There are several ways to write on the file, but note that all ways to proceed involve root. I describe here several programs that can do that (so that you can choose depending on your need or on what is installed on your system for example). If you forget to run the program as root, you may have an error :

stty: /dev/rfcomm0: Device or resource busy

First option : connect using screen

Screen is a very powerfull tool. You can install it (it's always usefull anymore) by using :

sudo apt-get install screen

and then run

sudo screen /dev/rfcomm0

If you forget to run it as root, you will get an error like Aleksander got :

[screen is terminating]

To quit it, type "Ctrl A + :exit"

Second option : connect using minicom

Install it

sudo apt-get install minicom

and then run

sudo minicom -D /dev/rfcomm0

If you forget to run it as root, you will have an error like

minicom: cannot open /dev/rfcomm0: Device or resource busy

To quit it, type "Ctrl + A X".

Third option : python script miniterm

Download this script, and run :

chmod +x miniterm.py
sudo ./miniterm.py /dev/rfcomm0

Write directly into the file

Firstly run the following command (9600 is the baud rate) :

sudo stty -F /dev/rfcomm0 cs8 9600 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts 

Now you can write in this file like in a classic file :

sudo su -c "echo 'message' > /dev/rfcomm0"

and in theory read from it using

sudo tail -f /dev/rfcomm0

But I don't know read does not work, if any of you have an idea...

  • /def/rfcomm0 should be /dev/rfcomm0 – stewSquared Feb 21 at 6:10

protected by Community May 30 at 16:43

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.