bleak 라이브러리[python]
https://bleak.readthedocs.io/en/latest/index.html
장치 관리자 -> bluetooth -> 컴퓨터 bluetooth device ->오른쪽 클릭 후 속성 -> 고급 -> 펌웨어 버전 확인
장치 관리자 ->bluetooth -> 컴퓨터 bluetooth device
페어링된 장비도 뜨는 듯
lmp확인
https://bleak.readthedocs.io/en/latest/scanning.html
scann 예제
import asyncio
from bleak import BleakScanner
async def main():
devices = await BleakScanner.discover()
for d in devices:
print(d)
asyncio.run(main())
설정 -> 장치 -> bluetooth -> bluetooth 또는 기타 장비 추가
를 통해서 디바이스 페어링
페어링 이후에는 밑에 장치 표시됨
https://bleak.readthedocs.io/en/latest/usage.html
connect 예제
import asyncio
from bleak import BleakClient
# 장비 address 작성
address = "--:--:--:--:--:--"
async def main(address):
client = BleakClient(address)
try:
await client.connect()
print("connect to " + client.address)
except Exception as e:
print(e)
finally:
await client.disconnect()
asyncio.run(main(address))
노트북/컴퓨터 기본 내장 bluetooth칩일시 끊기는 현상
->블루투스 동굴 이용해서 해보세요 잘 됩니다
notify enable 설정을 해야지 전송 데이터가 쭉 들어옴
import asyncio
from bleak import BleakClient
address = "--:--:--:--:--:--"
#charateristic uuid
C_uuid = "00001524-1212-efde-1523-785feabcd123"
def callback(sender:int , data:bytearray):
pass
async def main(address):
client = BleakClient(address)
try:
#connect
await client.connect()
print("connect to " + client.address)
#notify
await client.start_notify(C_uuid,callback)
#read
while(True):
data = await client.read_gatt_char(C_uuid)
print(bytes(data))
except Exception as e:
print(e)
pass
finally:
await client.disconnect()
asyncio.run(main(address))