By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,621 Members | 1,074 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,621 IT Pros & Developers. It's quick & easy.

bluetooth discover

P: 1
Im doing project which connect a bluetooth module to development board. unfortunely, my python code couldn't discover bluetooth devices. Can anyone help me to check my code ? thx you


Expand|Select|Wrap|Line Numbers
  1. import socket,appuifw,e32
  2.  
  3.  
  4. def bt_socket_connect(target=''):
  5. address, services= socket.bt_discover()
  6.  
  7. if len(services) > 1:
  8. choices = services.keys()
  9. choices.port()
  10. choice = appuifw.popup_menu([unicode(services[x])+": "+x for x in choices], u'Choose port:')
  11. target = (address, services[choices[choice]])
  12. else:
  13. target = (address, services.values()[0])
  14. sock = socket.socket(socket.AF_BT,socket.SOCK_STREAM)
  15. sock.connect(target)
  16. return sock
  17.  
  18. def recieve():
  19.     global sock
  20.     data=sock.recv(1)
  21.     if data=="1":
  22.         appuifw.note(u"LED on","info")
  23.     elif data=="0":
  24.     appuifw.note(u"LED off","info")
  25.  
  26. def recieve():
  27.     global sock
  28.     data=sock.recv(2)
  29.     if data=="1":
  30.         appuifw.note(u"Light on","info")
  31.     elif data=="0":
  32.     appuifw.note(u"Light off","info")
  33.  
  34.  
  35. def bt_send_data1():
  36.     global sock
  37.     sock.send("1")
  38.     receive()
  39.  
  40. def bt_send_data2():
  41.     global sock
  42.     sock.send("0")
  43.     receive()
  44.  
  45. def bt_send_data3():
  46.     global sock
  47.     sock.send("1")
  48.     receive()
  49.  
  50. def bt_send_data4():
  51.     global sock
  52.     sock.send("0")
  53.     receive()
  54.  
  55.  
  56. def exit_key_handler():
  57.     print"socket closed"
  58.     sock.close()
  59.     app_lock.signal()
  60.  
  61. app_lock=e32.Ao_lock()
  62.  
  63.  
  64. devices = [u"LED", u"Light"]  
  65. index = appuifw.selection_list(devices, 0)
  66.  
  67.  
  68. appuifw.app.exit_key_handler=exit_key_handler
  69. app_lock.wait()
Nov 24 '08 #1
Share this Question
Share on Google+
1 Reply


Curtis Rutland
Expert 2.5K+
P: 3,256
Please enclose your posted code in [CODE] [/CODE] tags (See How to Ask a Question). Code tags preserve indention and uses a monospaced font.

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [CODE] [/CODE] tags in future.

MODERATOR
Nov 25 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.