跳转到主要内容

通过BLE进行简单的基于字节和字符串的设备间通信。

项目描述

介绍

Documentation Status Discord Build Status Code Style: Black

此库提供通过BLE进行简单的基于字节和字符串的设备间通信。

它的工作方式类似于对讲机:配置您的设备使用特定的频道(编号为0-255,默认为42),它将在该频道上广播并接收使用该频道从其他设备收到的任何消息。

依赖关系

此库依赖于

请确保所有依赖项都可在CircuitPython文件系统中使用。这可以通过下载 Adafruit库和驱动程序捆绑包 来轻松实现。

用法示例

所有功能都通过非常简单的 Radio 类公开

from adafruit_ble_radio import Radio


# A radio instance listens/broadcasts on a numbered channel.
r = Radio(channel=7)

# Update radio instance settings.
r.configure(channel=9)

# Broadcast a simple string message.
r.send("Hello")

# Broadcast raw bytes.
r.send_bytes(b"Hello")

# A loop to listen for incoming string based messages...
while True:
    msg = r.receive()
    if msg:
        print(msg)

# Alternatively, to get the raw bytes and other details...
while True:
    msg = r.receive_full()
    if msg:
        msg_bytes = msg[0]
        msg_strength = msg[1]
        msg_time = msg[2]
        print("Recieved {} (strength {}, at time {})".format(
              msg_bytes,
              msg_strength,
              msg_time))

单元测试

要运行测试套件,您应该安装 pytestpytest-coverage (pip install pytest pytest-coverage)。

使用以下命令运行单元测试

$ pytest --cov-report term-missing --cov=adafruit_ble_radio tests/

文档

此库的API文档可在 Read the Docs 上找到。

有关构建库文档的信息,请参阅 本指南

贡献

欢迎贡献!在为该项目做出贡献之前,请阅读我们的行为准则,以帮助该项目保持开放友好。

项目详情


下载文件

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

源分布

adafruit-circuitpython-ble-radio-0.5.10.tar.gz (30.2 kB 查看散列)

上传时间

构建分布

adafruit_circuitpython_ble_radio-0.5.10-py3-none-any.whl (6.6 kB 查看散列)

上传时间 Python 3

由以下支持