What you want to do is possible, but how you're approaching it isn't correct
In order to talk serial over a bluetooth link, you need to use rfcomm to setup a serial connection. With that in place, you then open the rfcomm /dev/ entry, and a connection is initiated over bluetooth (or an error returned). Finally, you then read and write from the rfcomm device to send and receive your serial data.
If you are only ever going to be talking to a single static Bluetooth device, your best bet is to define the link in /etc/bluetooth/rfcomm.conf
so that the rfcomm device is always created. If you're going to be talking to lots of different devices, you'll need to do something (perhaps using hcitool scan
or sdptool browse
) to identify the bluetooth address + channel, then use rfcomm bind ....
to setup the rfcomm object, and finally connect to that from python.
If you're new to all this, I'd suggest you follow tutorials like this one or this one to get started.
If you wanted to connect to the Dial Up Networking rfcomm serial service, and there was only one device offering that in range, you'd do something like:
$ hcitool dev
Devices:
hci0 74:AA:BB:CC:80:FF
$ hcitool scan
Scanning ...
AA:BB:CC:AA:BB:CC Gagravarr's Phone
$ sdptool browse | grep -A 10 'Dial-Up Networking'
Service Name: Dial-Up Networking
Service RecHandle: 0x10005
Service Class ID List:
"Dialup Networking" (0x1103)
"Generic Networking" (0x1201)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 1
Profile Descriptor List:
"Dialup Networking" (0x1103)
$ rfcomm bind /dev/rfcomm1 AA:BB:CC:AA:BB:CC 1
# Open /dev/rfcomm1 in python and read/write to it
With that, we scan to find the address of the remote device (must be visible!), we sdp browse to find the rfcomm channel of the remote service, then rfcomm bind to create a /dev/ entry that'll connect us to that channel on that host. Open /dev/rfcomm1
and you're away! (Well, assuming you have set the permissions up properly that is!)