Skip to main content

云知 · yunzhi

让 Python 项目通过局域网向安卓手机发送消息、紧急报警和二进制附件。传输使用扫码时验证的 HTTPS。支持 Android 8.0 及以上。

下载安装与绑定

本地发布包可用 pip install ./yunzhi-0.2.0-py3-none-any.whl 安装。

yunzhi-agent apk-qr

手机与电脑连上同一 Wi-Fi,用手机系统相机扫描这个二维码直接下载 APK。也可以运行 yunzhi-agent apk,或调用 yunzhi.get_apk(),把导出的 APK 传到手机安装。下载二维码默认 10 分钟后失效。

在每台要绑定的电脑上启动后台投递服务。macOS 可选择登录后自动运行。

# 手动启动,Windows、Linux 和 macOS 均可运行
yunzhi-agent serve --name "家里电脑"

# macOS 登录后自动启动,在未运行 serve 时执行
yunzhi-agent enable --name "家里电脑"

再打开一个终端,为每台手机分别运行一次 yunzhi-agent bind。手机打开云知,选择「扫描项目二维码」。一台电脑最多绑定 32 台手机,一台手机最多绑定 16 台电脑。用 yunzhi-agent phones 查看设备 ID,用 yunzhi-agent revoke 手机ID 撤销设备。macOS 可运行 yunzhi-agent disable 停用登录后启动。

电脑有多个网络接口时,使用 serve --host 192.168.1.20 指定电脑的局域网 IPv4。防火墙需允许手机访问打印的 TCP 端口,默认 8789。建议在路由器为电脑保留固定 IP,服务地址或端口变化后需要重新配对。

消息与报警

from pathlib import Path
import yunzhi

# 向这台电脑已绑定的全部手机发送
yunzhi.send("语音监测检测到愤怒", source="Sound")

# 紧急报警,可附带二进制内容,也可用 to="手机ID" 指定接收者
yunzhi.send_warning("检测到疑似摔倒,请查看老人情况。", source="YOLO")
yunzhi.send("检测事件附件", Path("event.bin").read_bytes(), source="YOLO")

已完成配对后,应用和命令行都能投递。后台服务在监测窗口关闭时可继续投递已入队的消息。即使后台服务暂时停止,发送方也可以将新消息写入同一账号的本地队列,等服务恢复后投递。生成实时检测报警仍需要摄像头或麦克风及识别进程继续运行。

yunzhi-agent warn "测试紧急报警" --source "桌面测试"

老人监测仓库的 YOLO 摔倒流程可用 YUNZHI_FALL_ALERTS=1 开启报警桥接。先把云知 wheel 安装到 YOLO 的 Python 环境,并在同一桌面账号启动投递服务、配对手机。确认摔倒时,YOLO 会自动发出紧急消息。

手机权限

启用云知首页的「紧急报警」,允许系统通知。Android 14 及以上需要时点击「允许锁屏全屏报警」,在系统设置里授予权限。收到紧急消息后,Android 可在锁屏时显示亮屏报警,手机正在使用时可能显示横幅。报警用系统闹钟铃声,最多响 45 秒,可点「停止响铃」。

可在云知里确认将系统闹钟音量设为最大。该操作也会影响其他闹钟。要在「仅允许优先打扰」模式下接收报警,先授予勿扰访问权限,再启用云知的勿扰例外。最终的响铃、振动和全屏行为取决于系统及厂商设置。手机端保持后台接收开启,系统通知栏会显示常驻状态。

Python 接口

接口 行为
bind_scan(timeout=120, *, host=None, port=0, name=None, qr_path=None) 生成一个一次性配对二维码,等待扫描后返回手机 ID。用 qr_path="pairing.svg" 导出二维码。
send(message, file=None, *, source=None, to=None) 将普通消息放入持久化队列并返回消息 ID。默认发送给已绑定的全部手机,to 支持单个 ID 或 ID 列表。
send_warning(message, file=None, *, source=None, to=None) 将紧急报警放入优先队列。5 分钟内未收到的报警会过期,避免手机恢复连接后响起过时的警报。
get_apk(destination=None) 导出内置 APK 并返回绝对路径。可传入现有目录或目标文件路径。

正文最多 8 KiB,附件最多 16 MiB。各手机保存消息和附件后分别确认接收。普通消息待投递时间为 7 天。

构建

安卓端需要 JDK 17、Android SDK Platform 36、Build Tools 36.0.0 和 ZXing Core 3.5.4。先配置 ANDROID_SDK_ROOT、JAVA_HOME、ZXING_JAR、YUNZHI_KEYSTORE 和 YUNZHI_KEY_PASSWORD_FILE,再运行 bash android/build.sh。签名密钥使用 yunzhi 别名。升级安装时使用原签名密钥。

APK 构建完成后,用 python -m build 生成 Python wheel 和源码包。

Metadata

Release files for yunzhi 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yunzhi 0.2.0
File Size Uploaded Provenance Actions
yunzhi-0.2.0.tar.gz 295.8 kB Without provenance Details for yunzhi-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for yunzhi 0.2.0
File Interpreter ABI Platform Actions
yunzhi-0.2.0-py3-none-any.whl Python 3 none any Details for yunzhi-0.2.0-py3-none-any.whl

Total release size: 566.7 kB

Release files / yunzhi-0.2.0.tar.gz

Download URL yunzhi-0.2.0.tar.gz
Size 295.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5a79e732aeda1fcbc4644ff8d2b971778d9ab23a8b04fea89b64daf1767723c6
BLAKE2b-256 checksum
How to use checksums
0b3a297e18cb7b9d96f66b1bae1536ac8fa3e987df52f955f8129d80fa40de76
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.5

Release files / yunzhi-0.2.0-py3-none-any.whl

Download URL yunzhi-0.2.0-py3-none-any.whl
Size 270.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
01b9207fc638baf2b1ebf2b7d0367f6ac4f4163f7e97dc4bdac8d1a4b0a20d5d
BLAKE2b-256 checksum
How to use checksums
6180de5e97ed51a83948764a4240e9ef9e93f8fd85e8e8e03db613e880df5bc9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.5

Security for yunzhi 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page