I am currently work in a project that I am using Raspberry-pi to record data from Bluetooth signal. I chosen the PyBluez to program bluetooth. My object is to write the data into csv file, each data point corresponding to the time it was recorded.
I connect the Bluetooth by following code:
port = 1
target_addr = '20:17:08:15:12:41'
sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
sock.connect((target_addr, port)
The first way I used to print the signal is sock.recv(1024)
and It returned a huge string '-10245\r\n,Red:-10285\r\n,Red:-2918\r\n...'
I cannot match each data point into the corresponding time I received it. So I tried the second way which I tried to use readline() function, I convert socket into file and use readline() to read each data value: f = sock.makefile("r+")
then f.readline()
, the result is not consistence : ed:3124\r\n
, Red:-4480\r\n
, 1\r\n
, :-4480\r\n
. Can anyone suggest the way I can read the bluetooth which I can receive a proper string value ex: Red:34612\r\n
.