7.2. OBEX and RFCOMM
There are two main ways to communicate over Bluetooth with PyS60. OBject EXchange (OBEX) is suitable for transferring files, such as photos or sounds, over Bluetooth. Radio Frequency COMMunication (RFCOMM) is useful for sending and receiving streams of text and raw data, including protocols of your own.
To send anything over Bluetooth, you have to know the recipient's Bluetooth address, which is represented in a string, such as 00:12:d2:41:35:e4. You can find Bluetooth devices and their addresses with Bluetooth scanning. Typically, you have to worry about the raw addresses only if you want to connect to the same device again without scanning.
The Bluetooth address identifies a device. A single device may provide several services. For example, your phone can simultaneously receive files and communicate with a headset and a wireless keyboard over Bluetooth. Each of the services operates on a different channel so they do not interfere with each other. If you want to send a file to another phone, first you have to find out its address and then the channel that is used by the file transfer service.
This might sound a bit complicated and, in the background, it is. However, PyS60 wraps this functionality behind two simple functions: socket.bt_obex_discover() performs service discovery for the OBEX protocol and socket.bt_discover() performs service discovery for RFCOMM. Note that all Bluetooth-related functionality can be found in the socket module, which is described ...
Get Mobile Python: Rapid Prototyping of Applications on the Mobile Platform now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.