跳转到主要内容

设置和获取各种低功耗蓝牙时钟的时间

项目描述

Continuous Integration Python package version Supported Python versions Documentation Status Codecov coverage License

蓝牙时钟

设置和获取各种低功耗蓝牙时钟的时间

本项目提供了一种轻松识别蓝牙低功耗(BLE)时钟的方法,并提供了设置和获取它们时间的设备无关API。

Synchronize all your Bluetooth Low Energy clocks

支持的设备

蓝牙时钟支持以下设备

设备

设置时间

设置12/24小时格式

读取时间

当前时间服务(例如,带有InfiniTime固件的PineTime)

PVVX固件(LYWSD03MMC、MHO-C401、CGG1、CGDK2、MJWSD05MMC、MHO-C122)

Qingping BT Clock Lite

ThermoPro TP358/TP393

小米 LYWSD02

安装

您可以使用pip从PyPI将bluetooth-clocks安装为包

pip install bluetooth-clocks

命令行程序的使用

如果您使用

pip

安装了此软件包,则可以以

bluetooth-clocks

运行程序

$ bluetooth-clocks -h
usage: bluetooth-clocks [-h] [--version] [-v] [-vv] {discover,get,set} ...

Bluetooth Clocks

options:
  -h, --help           show this help message and exit
  --version            show program's version number and exit
  -v, --verbose        set loglevel to INFO
  -vv, --very-verbose  set loglevel to DEBUG

Subcommands:
  {discover,get,set}
    discover           discover supported Bluetooth clocks
    get                get the time from a Bluetooth clock
    set                set the time of a Bluetooth clock

发现蓝牙时钟

您可以使用

bluetooth-clocks discover

发现支持的蓝牙时钟

$ bluetooth-clocks discover
Scanning for supported clocks...
Found a ThermoPro TP358: address BC:C7:DA:6A:52:C6, name TP358 (52C6)
Found a Xiaomi LYWSD02: address E7:2E:00:B1:38:96, name LYWSD02
Found a ThermoPro TP393: address 10:76:36:14:2A:3D, name TP393 (2A3D)
Found a Qingping BT Clock Lite: address 58:2D:34:54:2D:2C, name Qingping BT Clock Lite
Found a Current Time Service: address EB:76:55:B9:56:18, name F15

这些是

discover

子命令识别的选项

$ bluetooth-clocks discover -h
usage: bluetooth-clocks discover [-h] [-s SCAN_DURATION]

options:
  -h, --help            show this help message and exit
  -s SCAN_DURATION, --scan-duration SCAN_DURATION
                        scan duration (default: 5 seconds)

设置时间

使用指定的蓝牙地址设置时钟的时间

$ bluetooth-clocks set -a E7:2E:00:B1:38:96
Scanning for device E7:2E:00:B1:38:96...
Writing time to device...
Synchronized time

如果您想定期同步设备上的时间,您可以将此命令作为服务运行,例如在Linux中使用systemd服务或cron作业。

这些是

set

子命令识别的选项

$ bluetooth-clocks set -h
usage: bluetooth-clocks set [-h] -a ADDRESS [-s SCAN_DURATION] [-t TIME] [-p]

options:
  -h, --help            show this help message and exit
  -a ADDRESS, --address ADDRESS
                        Bluetooth address (e.g. 12:34:56:78:9A:BC)
  -s SCAN_DURATION, --scan-duration SCAN_DURATION
                        scan duration (default: 5 seconds)
  -t TIME, --time TIME  the time to set, in ISO 8601 format (e.g. 2023-01-10T16:20,
                        default: current time)
  -p, --am-pm           use AM/PM format (default: 24-hour format)

获取时间

从具有指定蓝牙地址的时钟获取时间

$ bluetooth-clocks get -a E7:2E:00:B1:38:96
Scanning for device E7:2E:00:B1:38:96...
Reading time from device...
2023-01-14T17:54:17

这些是

get

子命令识别的选项

$ bluetooth-clocks get -h
usage: bluetooth-clocks get [-h] -a ADDRESS [-s SCAN_DURATION]

options:
  -h, --help            show this help message and exit
  -a ADDRESS, --address ADDRESS
                        Bluetooth address (e.g. 12:34:56:78:9A:BC)
  -s SCAN_DURATION, --scan-duration SCAN_DURATION
                        scan duration (default: 5 seconds)

库的使用

您也可以通过使用此项目作为库来在您的Python程序中使用命令行程序的功能。

请参阅模块参考以获取完整的API文档。

文档

阅读蓝牙时钟的在线文档

了解更多关于蓝牙低功耗开发的信息

如果您想了解更多关于蓝牙低功耗开发的信息,请阅读书籍Develop your own Bluetooth Low Energy Applications for Raspberry Pi, ESP32 and nRF52 with Python, Arduino and Zephyr及其配套的GitHub存储库koenvervloesem/bluetooth-low-energy-applications

许可证

本项目由Koen Vervloesem提供,开源软件,MIT许可证。有关更多信息,请参阅LICENSE文件。

项目详情


下载文件

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

源代码发行版

bluetooth-clocks-0.2.0.tar.gz (532.7 kB 查看哈希值)

上传时间 源代码

构建发行版

bluetooth_clocks-0.2.0-py3-none-any.whl (20.5 kB 查看哈希值)

上传时间 Python 3

支持