Skip to main content

云智守护 · yunzhi

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

下载安装与绑定

从 PyPI 安装到独立虚拟环境。

python3 -m venv .venv
source .venv/bin/activate
python -m pip install yunzhi

Windows 使用 py -m venv .venv 创建环境,并在 PowerShell 中运行 .\.venv\Scripts\Activate.ps1。已有项目环境可直接 python -m pip install yunzhi。

从本仓库源码安装用 python -m pip install .;已有 dist/ 中的 wheel 时也可 python -m pip install ./dist/yunzhi-0.3.1-py3-none-any.whl。

嵌入 Python 程序

下载二维码和绑定二维码都返回 QR 对象。qr.image 是 PNG 字节,可保存为图片、传给网页,或交给已有的 GUI。

from pathlib import Path
import yunzhi

with yunzhi.get_apk_qr(host="192.168.0.160", port=18790) as qr:
    Path("download-qr.png").write_bytes(qr.image)
    qr.show_in_windows(title="下载云智守护")

保持窗口开启,手机用系统相机扫码,打开下载页并安装。默认下载地址有效期为 10 分钟。已有 Tkinter 主窗口时用 qr.show_in_windows(root),它会立即返回弹出的窗口,复用现有事件循环。

with yunzhi.bind_scan(host="192.168.0.160", port=18789, name="家里电脑") as qr:
    qr.show_in_windows(title="绑定云智守护")
    phone_id = qr.wait(timeout=0)  # 扫码成功后关闭二维码窗口,再读取手机 ID

yunzhi.send("设备已绑定", to=phone_id)

绑定码用云智守护 App 内的扫码功能,默认有效期 2 分钟。bind_scan() 立即返回二维码。独立窗口会在关闭后返回。嵌入现有 Tkinter 窗口时,可在事件循环中用 qr.wait(timeout=0) 检查扫码状态。每台新手机生成一个绑定码。程序重启时可调用 yunzhi.start_receiver(host=..., port=...),原来绑定的手机可重新连接。保持接收服务运行,防火墙需允许指定端口。

示例中的 IP 为电脑的局域网 IPv4,按实际地址修改。省略 host 时自动选取本机地址。关闭下载二维码会停止对应的临时下载服务。关闭绑定二维码会取消未使用的绑定码。

消息与报警

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")

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

老人监测仓库的 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。
get_apk_qr(timeout=600, *, host=None, port=0) 启动临时 APK 下载页,返回下载二维码 QR。
start_receiver(*, host=None, port=0, name=None) 为已绑定的手机启动或复用接收服务,返回 HTTPS 地址。
QR.show_in_windows(master=None, *, title="云智守护") 在 Tkinter 中显示二维码。传入现有主窗口时复用它的事件循环。
QR.wait(timeout=None) 仅用于绑定二维码,等待手机扫码后返回手机 ID。timeout=0 立即检查。
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.3.1

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.3.1
File Size Uploaded Provenance Actions
yunzhi-0.3.1.tar.gz 301.4 kB Without provenance Details for yunzhi-0.3.1.tar.gz

Built distribution (wheel)

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

Total release size: 577.0 kB

Release files / yunzhi-0.3.1.tar.gz

Download URL yunzhi-0.3.1.tar.gz
Size 301.4 kB
Tags Source
SHA-256 checksum
How to use checksums
456f902b4882d2dba08ab68df7359a18aaefda8d5f6b21e159655ec7bf78e97c
BLAKE2b-256 checksum
How to use checksums
a6d4ab297e93a1a6fc4d9cd48a93d3149a962a8d6ead7a803e663472fbe27522
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

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

Download URL yunzhi-0.3.1-py3-none-any.whl
Size 275.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6562a5307ed1708adb64e489168f63c4c542cfb167d6701c242c84c3ac718843
BLAKE2b-256 checksum
How to use checksums
9d43bbbfd7f5cfc12cde6ab4cd6e1911ab5199f04c2e1b1d58b2b25e34e06559
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Security for yunzhi 0.3.1

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