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)
request = '\x02\x08\x00\x00\x03'
response = bh_belt.recv(12)
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.