bluetooth-proximity
bluetooth-proximity copied to clipboard
Getting AttributeError in bluetooth-scanner example
When running the bluetooth-scanner example on a raspberry pi with python3 (https://github.com/Adversitx/bluetooth-proximity actually, but in this case there should be no difference I think) I get the following error:
Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 865, in run self._target(*self._args, **self._kwargs) File "bluetooth_scanner.py", line 47, in bluetooth_listen rssi = b.request_rssi() File "/usr/local/lib/python3.7/dist-packages/bt_proximity-0.2-py3.7.egg/bt_proximity/bt_rssi.py", line 60, in request_rssi rssi = struct.unpack('b', rssi[3].to_bytes(1, 'big')) AttributeError: 'str' object has no attribute 'to_bytes'
Why is this? I have not changed a thing in the code… Also, if I bypass this just to see that the rest works by encoding it with latin1 instead of using to_bytes I get a runtime error after a few seconds:
line 63, in request_rssi rssi = bt.hci_send_req(self.hci_sock, bt.OGF_STATUS_PARAM, bt.OCF_READ_RSSI, bt.EVT_CMD_COMPLETE, 4, self.cmd_pkt) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfe in position 3: invalid start byte
In the code, change rssi[3]
with int(rssi[3])
. This should be done because int has a to_bytes method whereas str doesn't.