×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Regular Contributor
    Join Date
    Jan 2009
    Posts
    71

    I can not understand why bluetooth in python is so difficult??

    Nothing want to be implemented if only the discover works I will be happy
    Actually am facing many problems during coding with python because it is the first time that I deal with python and I am trying to focus on the things that has relating with bluetooth but the problem is that I found many functions about discovering devices with bluetooth each with different syntax and no one of them is applying even those codes which are already implemented by some people
    also about obex I have found two codes one use
    look at these codes please
    this code written on one book and I have tried to execute it and it does not work

    import socket, appuifw
    File= u"e:\\a.txt"
    def send_file():
    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,File)
    appuifw.note(u"File sent", "info")
    else:
    appuifw.note(u"OBEX Push not available", "error")

    it gives IndentationError: unexpected indent
    this code do the same thing but in diffrent manner also it has not been excecuted
    s=socket(AF_BT,SOCK_STREAM)

    # scan for other phones offering OBEX service
    addr,services=bt_obex_discover()
    print "Discovered: %s, %s"%(addr,services)
    if len(services)>0:
    choices=services.keys()
    choices.sort()
    choice=appuifw.popup_menu([unicode(services[x])+": "+x
    for x in choices],u'Choose port:')
    port=services[choices[choice]]
    else:
    port=services[services.keys()[0]]
    address=(addr,port)

    # create file to be sent
    send_path = u"c:\\test.txt"
    f=open(send_path, 'w')
    f.write("hello")
    f.close() # NOTE: parens were missing here before!

    # send file via OBEX
    print "Sending file %s to host %s port %s"%(send_path, address[0], address[1])
    bt_obex_send_file(address[0], address[1], send_path)
    print "File sent."

    The most important thing that I could not understand why we open socket at the second and we did not on the first actually I fell that the second one is the correct one but the first is written on the book !!!!
    the second one can not recognize the s=socket(AF_BT,SOCK_STREAM)
    Can any one help????!!!
    Thank you

  2. #2
    Registered User
    Join Date
    Nov 2008
    Location
    Portugal
    Posts
    7

    Re: I can not understand why bluetooth in python is so difficult??

    Quote Originally Posted by programer_asal View Post
    Nothing want to be implemented if only the discover works I will be happy
    Actually am facing many problems during coding with python because it is the first time that I deal with python and I am trying to focus on the things that has relating with bluetooth but the problem is that I found many functions about discovering devices with bluetooth each with different syntax and no one of them is applying even those codes which are already implemented by some people
    also about obex I have found two codes one use
    look at these codes please
    this code written on one book and I have tried to execute it and it does not work

    import socket, appuifw
    File= u"e:\\a.txt"
    def send_file():
    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,File)
    appuifw.note(u"File sent", "info")
    else:
    appuifw.note(u"OBEX Push not available", "error")

    it gives IndentationError: unexpected indent
    Well, you should first take some python tutorials, before start coding in python, as you probably already seen python don't use semicolons or braces to delimit blocks of code like a if-else, instead python use indentation, the problem here is that you don't have your code properly indented.


    Best regards.
    Valério Valério

    http://www.valeriovalerio.org/

  3. #3
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    87

    Re: I can not understand why bluetooth in python is so difficult??

    Well I am good at python and I know bluetooth on pys60 is difficult. Much of the base funcationality is hidden by wrappers and the ones available are limited. e.g. though there is code in S60 C++ for Bluetooth PMP, I couldn't do that in PyS60.

  4. #4
    Regular Contributor
    Join Date
    Jan 2009
    Posts
    71

    Re: I can not understand why bluetooth in python is so difficult??

    Hello Mr.VDVsx
    The problem is that this is not my code I found it on this book and it didn't work and I tried the other to but it also didn't work

  5. #5
    Regular Contributor
    Join Date
    Jan 2009
    Posts
    71

    Re: I can not understand why bluetooth in python is so difficult??

    hello Mr.ra.ravi.rav
    did the discovering work with you??
    because I am fried that it won't be implemented and my graduation project is depends on it

  6. #6
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    87

    Re: I can not understand why bluetooth in python is so difficult??

    Ditto! even my final year project is based on it. And I was fairly disappointed. Better close the project with only 2 node network.

  7. #7
    Regular Contributor
    Join Date
    Oct 2007
    Posts
    114

    Re: I can not understand why bluetooth in python is so difficult??

    The error "IndentationError: unexpected indent" is a general Python error and is in no way related to any bluetooth bug. Look at the traceback for the exact line where it complains about this. Also, don't mix tabs and spaces when indenting.

    I guess the second error is because you are using the module socket in 1.9.x to get bluetooth functionality . In 1.9.x it has been moved to btsocket module. I guess the import at the top is something like this - "from socket import *" , change it to "from btsocket import *"
    import antigravity

  8. #8
    Registered User
    Join Date
    Apr 2009
    Posts
    10

    Re: I can not understand why bluetooth in python is so difficult??

    I am also basing my final graduate project on this python code, and being able to use the BT Discover function without the Python Interpreter crashing every time would be really useful!

    ashwinurao you mentioned that you can use 'import btsocket' instead of socket, does this solve any problems with bluetooth discovery?

    many thanks,
    ben

  9. #9
    Nokia Developer Moderator
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,777

    Re: I can not understand why bluetooth in python is so difficult??

    Quote Originally Posted by benjeee View Post
    I am also basing my final graduate project on this python code, and being able to use the BT Discover function without the Python Interpreter crashing every time would be really useful!

    ashwinurao you mentioned that you can use 'import btsocket' instead of socket, does this solve any problems with bluetooth discovery?

    many thanks,
    ben
    It is just the name of the module has changes in 1.9.x release.
    Pankaj Nathani
    www.croozeus.com

Similar Threads

  1. Python for S60 1.9.2 released
    By tvijayan in forum Symbian
    Replies: 26
    Last Post: 2009-03-11, 09:28
  2. Python for S60 1.9.1 released
    By tvijayan in forum Symbian
    Replies: 30
    Last Post: 2009-02-26, 06:16
  3. Replies: 10
    Last Post: 2008-07-26, 08:10
  4. Bluelet - Rapid Bluetooth App Development (Free source)
    By huiben in forum Mobile Java General
    Replies: 4
    Last Post: 2008-07-25, 15:52
  5. Canyon Bluetooth adapter not working with PC Suite?
    By sNNooPY in forum Bluetooth Technology
    Replies: 6
    Last Post: 2006-08-10, 08:43

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •