Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forward Bluetooth socket to serial port

I've been trying to figure out how to turn my Raspberry Pi into a USB to Bluetooth serial adapter. I want to be able to send data over Bluetooth to the Pi which has a USB thermal printer registered at /dev/usb/lp0.

Using only standard command line apps such as hciconfig, hcitool, rfcomm, and sdptool I have been able to see the Pi as visible, and pair to it from an Android tablet using a Bluetooth SPP app on the Store. However, the tablet disconnects immediately, and no data is sent. rfcomm listen /dev/rfcomm0 1 also waits for a connection forever.

I think I'm able to achieve what I need without custom code, using solely standard command line apps, but I'm not entirely sure. socat will likely be of use to finally connect the sockets.

like image 733
joe Avatar asked Dec 31 '25 04:12

joe


1 Answers

Figures that I'd get it right after posting. To anyone else looking to do something similar:

  1. Pair with bluez-simple-agent
  2. Create your serial port channel with sdptool add --channel=x sp
  3. Listen for a connection on that channel with sudo rfcomm listen /dev/rfcomm0 x
  4. Cross the streams with socat /dev/rfcomm0 /dev/usb/lp0

Beautiful. It's all so simple now.

like image 80
joe Avatar answered Jan 02 '26 02:01

joe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!