Pybluez
Python extension module allowing access to system Bluetooth resources.
Installation
BLE 추가 설치:
sudo apt install -y pkg-config libboost-python-dev libboost-thread-dev libglib2.0-dev python3-dev
python3 -m pip install pybluez[ble]
Device Reader
RFCOMM 연결
from bluetooth import BluetoothSocket, RFCOMM
from time import sleep
socket = BluetoothSocket(RFCOMM)
result = socket.connect(("98:DA:60:05:EC:2F", 1))
print(f"Connect result: {result}")
while True:
data = socket.recv(1024)
print(f"receive data: {data}")
sleep(1)
if data == "q":
print(quit)
break
socket.close()
Troubleshooting
use_2to3 is invalid
- Problems installing Pybluez (bluetooth) : learnpython
- python - Error while downloading the requirements using pip install (setup command: use_2to3 is invalid.) - Stack Overflow
- python - Error in anyjson setup command: use_2to3 is invalid - Stack Overflow
- Removed 2to3 command to resolve issue# 413 by woudie · Pull Request #414 · pybluez/pybluez
Collecting PyBluez==0.23
Using cached PyBluez-0.23.tar.gz (97 kB)
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [1 lines of output]
error in PyBluez setup command: use_2to3 is invalid.
It looks like setuptools>=58
breaks support for use_2to3:
So you should update setuptools to setuptools<58
or avoid using packages with use_2to3 in the setup parameters.
I was having the same problem, pip==19.3.1
또는 다음과 같이 setuptools 버전은 낮춘다.