471,594 Members | 1,319 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 software developers and data experts.

bluetooth discover

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
1 2472
Curtis Rutland
3,256 Expert 2GB
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.

Similar topics

reply views Thread by Thomas_Germany | last post: by
3 posts views Thread by Tor Erik Sønvisen | last post: by
6 posts views Thread by jabslim | last post: by
1 post views Thread by Z.K. | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.