Categories
python

香橙派ble蓝牙 python

安装依赖包

sudo apt-get update
sudo apt-get install bluetooth bluez libbluetooth-dev libusb-dev libdbus-1-dev

确保蓝牙开启

sudo systemctl enable bluetooth
sudo systemctl start bluetooth

bluetoothctl 是一个点对点蓝牙控制工具

gatttool 是一个ble蓝牙控制工具

sudo apt-get install bluez-tools
gatttool -b <设备地址> --interactive

python 代码:

sudo apt-get install python3-pip
pip3 install bluepy
from bluepy.btle import Scanner, DefaultDelegate
import time

class ScanDelegate(DefaultDelegate):
    def handleDiscovery(self, dev, isNewDev, isNewData):
        if isNewDev:
            print("Discovered device")
            print("  Device %s (%s), RSSI=%d dB" % (dev.addr, dev.addrType, dev.rssi))
        elif isNewData:
            print("  Updated data: %s" % dev.scanData)
            print("  Manufacturer data: %s" % dev.manufacturerData)        # Optional: manufacturer data if available. 0x0000FFFF is the default for BLE devices. 0xFFFF is the default for Beacons. 0x004C is the default for iBeacons. 0x0215 is the default for AltBeacons. 0x0242 is the default for Estimote beacons. 0x0015 is the default for Eddystone beacons. 0x02AA is the default for Apple beacons. 0x0118 is the default for Samsung beacons. 0x02AA is the default for Apple beacons. 0x0118 is the default for Samsung beacons. 0x02AA is the default for Apple beacons. 0x0118 is the default for Samsung beacons. 0x02AA is the default for Apple beacons. 0x0118 is the default for Samsung beacons. 0x02AA is the default for Apple beacons. 0x0118 is the default for Samsung beacons. 0x02AA is the default for Apple beacons. 0x0118 is the default for Samsung

相关链接

https://blog.csdn.net/weixin_30598047/article/details/156319564

Categories
linux

Bluetoothctl

linux下一个蓝牙工具 可控制设备信任 配对 连接 等生命周期

sudo bluetoothctl 进入控制台

devices 列出设备

scan on 搜索

scan off 关闭搜索

trust 信任设备 untrust 不信任设备

pair 配对设备 unpair 不配对设备