Hi there everyone,
I have a Python problem with the socket recv function not working properly for my N91 S60 phone when receiving data from the BlueSmirf
The phone is connecting via Bluetooth to the BlueSmirf(let’s call this device X ), and I can do that fine with the connect command. I can also connect to the serial port provided by X.
Now, X is constantly sending out data packets out continuously(each 8 bytes) through the Bluetooth port
However, when I do the recv command on my N91 phone, it can only read 4 bytes for some reason and no more. Any further calls to recv will just block indefinitely for no reason.
I tried the same code running on the phone on my PC(with Bluetooth) except written in PyBluez, and it works. I can stream data continuously from device X to the PC but not to the N91, which is perplexing.
So, this is the code that runs on the N91 phone(no pyBluez) :
import socket
import os , sys
global sock
micazAddress = “00:a0:96:11:a2:9f”
class BTReader:
def connect(self):
self.sock=socket.socket(socket.AF_BT,socket.SOCK_STREAM,socket.BTPROTO_RFCOMM)
address=(micazAddress , 1)
print "Connecting to "+str(address)+ “…”,
self.sock.connect(address)
print “OK.”
def readline(self):
line=
print “Let’s get data…\n”
count = 0
line = self.sock.recv(3)
return line
def close(self):
self.sock.close()
bt = BTReader()
bt.connect()
while 1:
line = bt.readline()
print "Read the line " + line + “\n”
bt.close()
and this is the similar code running on my PC(using pyBluez)
from bluetooth import *
import string, time
import os , sys
micazAddress = “00:a0:96:11:a2:9f”
sock = BluetoothSocket( RFCOMM )
sock.connect((micazAddress , 1 ))
print “connected \n”
while 1:
line = sock.recv(3)
print " line : " + line + “\n”
I have tried to do non-blocking sockets and use the select function for N91, and the Python script would seem to hang.
Please help, thanks in advance : |