×

Discussion Board

Results 1 to 5 of 5

Hybrid View

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    24

    Connecting from PC to phone via RFCOMM, OBEX

    Hi,

    Could anyone clarify on how to connect to the phone over RFCOMM using python? I'm sure this is meant to be easy but for some reason my python code on the phone does not receive the connection from the PC. My phone code looks like this: (borrowed from the other thread talking about the socket._sock bug)


    from socket import *
    s = socket(AF_BT, SOCK_STREAM)
    p = bt_rfcomm_get_available_server_channel(s._sock)
    s.bind(("", p))
    bt_advertise_service( u"asdf", s._sock, True, RFCOMM)
    set_security(s._sock, AUTHOR)

    print 'Listening...'
    s.listen(1)
    print 'After Listening'
    conn, addr = s.accept()
    print "connected to", addr
    data = conn.recv(1)


    Then I connect to the phone from my PC using PySerial, connecting to COM4. The code on the phone never receives the connection: it gets as far as to print the 'After Listening' message but it never receives a connection to print the "connected to" message. But, and I found this weird: I don't think I'm connecting to the wrong COM port, because the phone still comes up with the "do you want to accept the connection from <me>?" prompt.

    So it seems the connection is getting to my phone, but not my python code? This seems confirmed by the fact my code is using AUTHOR so it should authorize incoming connections but when I connect, it still prompts for authentication.

    My PySerial code is very simple, just:


    import serial
    ser = serial.Serial(3)
    # after the above line, the phone pops up the authentication message
    ser.write("hello")
    # now the code will just hang, I guess it has nothing at the other end to write to?


    Thanks very much if anyone can help, it would be greatly appreciated.


    (On another note, can OBEX files be sent from the PC to the phone using python? Can a file object be somehow wrapped into an OBEX object?)

  2. #2
    Registered User
    Join Date
    Oct 2004
    Posts
    48
    Hallo,
    i just have the samr problrm like you . I guess it must be something to do with security settings. I tried btpointtopoint example - no response from socket accept bt server. So you solved this problem?

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    24
    No - didn't get it working, but I don't think it's actually supposed to work.

    There are no problems with getting the phone to connect to the PC running pyserial, but I can't get the PC with pyserial to connect to the phone running an RFCOMM server. I think this is because the PC is talking serial, but the phone is talking RFCOMM, and since serial is at a higher level, the PC won't find the RFCOMM phone stuff at a lower level.

    So, I think with the code I posted, the PC is connecting to the phone, but it's not connecting to the RFCOMM service I advertised; it's actually connecting to the general serial port service on the phone (I'm not sure how I can reach that service through python).

    Because the PC is talking serial and not the lower-level RFCOMM, I don't think it'll be able to connect to the phone's RFCOMM socket.

    So to get the PC to connect to the phone, I think you'll need use lower-level RFCOMM libraries. I shifted to Mac OSX and I successfully used the IOBluetooth framework to connect to a bound python RFCOMM socket on the phone. (i.e. I swapped the pyserial code above for IOBluetooth code and it worked)

    Good luck!

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    8

    Re: Connecting from PC to phone via RFCOMM, OBEX

    Did you manage to make the phone announce the serial service??
    How can you pass throught it? You didn't care to the anounce and simple inserted the address?
    Thanks,

    Filipe aguiar - portugal

  5. #5
    Registered User
    Join Date
    Mar 2005
    Posts
    24

    Re: Connecting from PC to phone via RFCOMM, OBEX

    I'm not sure exactly what you mean, so maybe you could explain your problem in a bit more detail. When you say "announce", do you mean the bit about advertising the service? If you need to advertise a service on the phone you just have to call bt_advertise_service() (as in the code example further up on this page).

    My last post isn't that clear, so I'll try to explain it a bit more here.

    The PC can't connect to the phone because the code simply opens up a Bluetooth Serial Port, connects to the phone and then starts sending data. The key thing is that it just "connects" -- it doesn't specify exactly which port to connect to on the phone. So the phone is probably just letting it connect to its generic Serial Port service, or something, which is why you still get the "Do you want to accept the connection from ...?" message. Your code is successfully connecting to a service on the phone, but it's not connecting to the service that you actually want.

    I'm not sure if you can specify the service to connect to the from the PC if you're just using pyserial and not an actual Bluetooth library. A Bluetooth library that supports RFCOMM sockets will allow you to connect to your service on the phone, because you'll be able to actually specify the channel/service that you want to connect to on the phone.

Posting Permissions

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