×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    3

    Bluetooth RFCOMM crashes when receiving data

    I'm building an application which communicates with a cardiac belt via bluetooth. I'm using PyS60 2.0.0, so I use the btsocket module to create the RFCOMM pipe.
    The problem is the application only seems to work sometimes, most of the time it crashes the first time it tries to receive data. What's strange is that, everytime I use the SPARK Environment to test commands or so, it works (which uses an older version of PyS60, before the upgrade from socket to btsocket)! I'm using an E52, but also testing this on an N81.

    import btsocket as socket
    belt = socket.socket(socket.AF_BT, socket.SOCK_STREAM)
    belt = 'xx:xx:xx:xx:xx:xx'
    target = (belt, 1)
    belt.connect(target)
    request = '\x02\x08\x00\x00\x03'
    belt.send(request)
    response = bh_belt.recv(12)
    belt.close()

    I'm sure this is the right message to send to the belt and the type of response to expect, as it has already worked a few times. The program crashes because there is no data to receive, in the line 'recv(12)', with "socket.error: (0:'Error')". What do you think might be going wrong?

    Thank you for your attention.

    [EDIT] I've tried to write this code, line by line, by interactive input, and it works, so the problem only happens when this is on a .py file.
    Last edited by kitCate; 2010-09-13 at 01:53. Reason: further explaining

  2. #2
    Regular Contributor
    Join Date
    Mar 2008
    Posts
    151

    Re: Bluetooth RFCOMM crashes when receiving data

    I think u need to put your recv command in a main loop otherwise your program is expecting the answer to come immediately.

  3. #3
    Nokia Developer Champion
    Join Date
    Sep 2007
    Location
    Bhavnagar
    Posts
    928

    Re: Bluetooth RFCOMM crashes when receiving data

    Or try to add some delay before reading for the response.
    Jajal Mehul

  4. #4
    Registered User
    Join Date
    Apr 2010
    Posts
    3

    Re: Bluetooth RFCOMM crashes when receiving data

    Thank you for both your answers!

    jtullis, I tried that (http://discussion.forum.nokia.com/fo...a-continuously), the program doesn't crash anymore, but it runs forever so... there is no answer from the device. Do you think it could be related to the format of the string I send? It is well interpreted in the interactive console, as I said, but I do not know if there are any differences in executing a .py file. What shoud I change? And while we're at it, one more question: what does the setblocking(0) do?

    james1980, I also simulated a delay with a time.sleep, but it didn't help either. Any other suggestions?

  5. #5
    Registered User
    Join Date
    Jul 2008
    Posts
    90

    Re: Bluetooth RFCOMM crashes when receiving data

    I really don't understand how this could work, because
    # now the socket is created....
    belt = socket.socket(socket.AF_BT, socket.SOCK_STREAM)
    # ...but the variable is reused as a string
    belt = 'xx:xx:xx:xx:xx:xx'
    # ...and there is no variable name bh_belt defined anywhere. This should crash every time...
    response = bh_belt.recv(12)

    ...I have a hunch that you really haven't posted the latest, real code

  6. #6
    Registered User
    Join Date
    Apr 2010
    Posts
    3

    Re: Bluetooth RFCOMM crashes when receiving data

    Well there was obviously a mistake when I copied the code here and changed the name of the variables, while the real address of the device was not relevant.

    More importantly, I was able to get it to work combining the two solutions presented. Actually, I used a loop in which I send the request intended, added a delay and then read the response, inside a try/except structure.

Similar Threads

  1. Replies: 4
    Last Post: 2010-09-01, 15:34
  2. Sending data to Nokia via bluetooth RFCOMM
    By scipio123 in forum Mobile Java General
    Replies: 10
    Last Post: 2009-09-30, 04:02
  3. Unable to receive data from Bluetooth Device Via RFComm
    By kctan in forum Bluetooth Technology
    Replies: 0
    Last Post: 2008-06-15, 15:23
  4. Receiving RFCOMM binary data.
    By pisaacson in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2006-08-18, 03:38
  5. Receiving Bluetooth Data with Emulator?
    By btuman in forum Bluetooth Technology
    Replies: 1
    Last Post: 2002-11-12, 07:06

Posting Permissions

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