7.3. Phone-to-Phone Communication

Now that we have seen how to find a target for Bluetooth communication, we can start to do something useful. This section requires that you invite a friend with a Bluetooth-capable phone to hack with you. Bluetooth really enables social interaction.

7.3.1. Using OBEX

We build an application that lets you take photos and share them with people around you. Example 56 is a combination of the camera application of Example 35 and the OBEX discovery Example 54. The only

Figure 7-2. Bluetooth from phone to phone

new feature, sending a photo to a chosen recipient, can be performed with a single function, socket.bt_obex_send_file().

Example 7.3. Send photos to another phone using Bluetooth
import camera, e32, socket, appuifw PHOTO = u"e: \\Images\\bt_photo_send.jpg" def send_photo(): try: address, services = socket.bt_obex_discover() except: appuifw.note(u"OBEX Push not available", "error") return if u'OBEX Object Push' in services: channel = services[u'OBEX Object Push'] socket.bt_obex_send_file(address, channel, PHOTO) appuifw.note(u"photo sent", "info") else: appuifw.note(u"OBEX Push not available", "error") def take_photo(): photo = camera.take_photo() canvas.blit(photo, scale = 1) photo.save(PHOTO) def quit(): app_lock.signal() canvas = appuifw.Canvas() appuifw.app.body = canvas appuifw.app.exit_key_handler = quit appuifw.app.title = u"BT photo ...

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.