跳转到主要内容

低功耗蓝牙平台无关客户端

项目描述

Bleak Logo
Build and Test https://img.shields.io/pypi/v/bleak.svg PyPI - Downloads Documentation Status https://img.shields.io/badge/code%20style-black-000000.svg

Bleak代表低功耗蓝牙平台无关客户端。

  • 免费软件:MIT许可证

  • 文档:[https://bleak.readthedocs.io](https://bleak.readthedocs.io).

Bleak是一个GATT客户端软件,能够连接到作为GATT服务器的BLE设备。它旨在提供一个异步、跨平台的Python API,用于连接和与传感器等进行通信。

安装

$ pip install bleak

功能

  • 支持Windows 10,版本16299(秋季创造者更新)或更高版本

  • 支持具有BlueZ >= 5.43的Linux发行版

  • 通过Core Bluetooth API支持OS X/macOS,至少为OS X版本10.11

  • Android后端与python-for-android兼容

Bleak支持从GATT服务器读取、写入和获取通知,以及发现BLE设备的函数。

用法

发现可以连接的蓝牙设备

import asyncio
from bleak import BleakScanner

async def main():
    devices = await BleakScanner.discover()
    for d in devices:
        print(d)

asyncio.run(main())

连接到蓝牙设备并读取其型号编号

import asyncio
from bleak import BleakClient

address = "24:71:89:cc:09:05"
MODEL_NBR_UUID = "2A24"

async def main(address):
    async with BleakClient(address) as client:
        model_number = await client.read_gatt_char(MODEL_NBR_UUID)
        print("Model Number: {0}".format("".join(map(chr, model_number))))

asyncio.run(main(address))

请不要将您的脚本命名为 bleak.py!这会导致循环导入错误。

请参阅示例文件夹以获取更多代码,例如连接到TI SensorTag CC2650的示例代码。

项目详情


下载文件

下载适合您平台的文件。如果您不确定该选择哪一个,请了解更多关于安装包的信息。

源代码分布

bleak-0.22.2.tar.gz (122.2 kB 查看哈希值)

上传时间 源代码

构建分布

bleak-0.22.2-py3-none-any.whl (142.6 kB 查看哈希值)

上传时间 Python 3

由以下支持