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 :
Be sure that the bluetooth device is started :
# power on
We now start the agent that will "remember the pin" for
# 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
[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
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
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 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) + :quit"
Second option : connect using
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...