设置和获取各种低功耗蓝牙时钟的时间
项目描述
蓝牙时钟
设置和获取各种低功耗蓝牙时钟的时间
本项目提供了一种轻松识别蓝牙低功耗(BLE)时钟的方法,并提供了设置和获取它们时间的设备无关API。
支持的设备
蓝牙时钟支持以下设备
设备 |
设置时间 |
设置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的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 42bf2cec2cdafa0d435050c12f0cc192a42d59148badf96b18bfce7dcc06abbe |
|
MD5 | 79faa05070962e161ba6caf4e60fff28 |
|
BLAKE2b-256 | 77cf6d677e33e696173a88263b234043b7ae057f7107ff82f8eeb8015d53a82a |
bluetooth_clocks-0.2.0-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 099c7cd989323fbefce3ed998859e7a52c432c8fd9f26d75de29939d1e04fef3 |
|
MD5 | f56b278a500ec886ba9f85d0871655a6 |
|
BLAKE2b-256 | b6d99088d67c58c0158a15bbb5502f88e4de538efa1de96653d12bef43f175e0 |