# basend on a script from Jurgen Scheible
import appuifw
import socket
import e32
import sys
# function that handles the bluetooth connection:
def bt_connect():
global sock
# create a bluetooth socket
sock=socket.socket(socket.AF_BT,socket.SOCK_STREAM)
target=''# here you can give the bt address of the other mobile if you know it
if not target:
# scan for bluetooth devices
address,services=socket.bt_discover()
if len(services)>1:
choices=services.keys()
choices.sort()
# bring up a popup menu and show the available bt devices for selection
choice=appuifw.popup_menu([unicode(services[x])+": "+x
for x in choices],u'Choose port:')
target=(address,services[choices[choice]])
else:
target=(address,services.values()[0])
sock.connect(target)
t.color=(0,150,0)
t.add(u"Connected\n")
t.color=(0,0,255)
# define the textinput function
def bt_send():
global sock
test = appuifw.query(u"String:", "text", u"")
sock.send(test)
t.color=(255,0,0)
t.add(unicode(test))
t.add(u"\n")
t.color=(0,0,255)
def bt_rec():
global sock
#sys.stdout.write(sock.recv(1024))
try:
t.add(unicode(sock.recv(1024)))
except:
t.add(u"???")
def exit_key_handler():
global running
running=0
appuifw.app.exit_key_handler = exit_key_handler
# call the function that handles the bluetooth connection
appuifw.app.menu = [(u"send line", bt_send)]
appuifw.app.screen='large'
t=appuifw.Text()
appuifw.app.body=t
t.color=(0,0,255)
bt_connect()
running=1
while running:
bt_rec()
e32.ao_yield()