I am using PySerial on a Raspberry Pi 3b to recieve data from an external bluetooth device (FireFly. I am able to get a connection to the device, and receive data. But when I close the connection via close(), the device doesn't seem to disconnect properly from the Raspberry (this is partly indicated by the green light at the Firefly not changing led colors after turning off the connection. Below is the code I'm trying to get to work. I have tried using both PySerial 2.7 and PySerial 3.3.0 aswell as python 2.7.9/10 and python 3.4. None of these changes seems to matter.
import serial import sys from timeit import default_timer as timer port = serial.Serial( baudrate=115200, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=1 ) port.port = '/dev/rfcomm1' port.open() sys.stdout.flush() time = timer() while timer()-time < 10: print(port.read()) port.flush() port.flushInput() port.flushOutput() port.close()
If I try using minicom to recieve data it works flawlessly unless I've previously used the python script, in which case it doesn't recieve any data except in some cases where it will recieve data after about 5 minutes.
Below is a screenshot of after the script has been executed and finished. The FireFly is still connected, which causes the program not to be able to run again until the device is restarted.
Any help would be greatly appreciated :)