mcpField
X
xiaomi-cam-snapshot

xiaomi-cam-snapshot

github.com/tiancheng91Other269 installsUpdated 6w ago
Repository

About xiaomi-cam-snapshot

A skill for retrieving live snapshots from Xiaomi cameras through the Miloco backend. It guides initial authentication and supports camera listing, periodic capture, and image cleanup through a Python script.

Key features

  1. 01Miloco setup and account authentication
  2. 02List cameras and inspect device details
  3. 03Capture snapshots from a specified camera
  4. 04Repeat captures at configurable intervals
  5. 05Choose output filenames and clean up old images

Use cases

  1. 01Checking a camera's current view
  2. 02Saving periodic images for monitoring
  3. 03Finding camera IDs before requesting snapshots

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/tiancheng91/skills --skill xiaomi-cam-snapshot

After installing, type/xiaomi-cam-snapshotin Claude Code to confirm it loaded.

Bundled filesscripts/camera_client.py

Details

From the project README

小米摄像头截图技能

通过 Miloco 后端服务获取小米摄像头的实时画面截图。

首次设置流程

步骤 1: 启动 Miloco 服务
docker run -d \
  --name miloco \
  --network host \
  -e BACKEND_PORT=8001 \
  ghcr.io/tiancheng91/miloco-backend:dev
步骤 2: 完成小米账号认证

服务启动后,引导用户完成以下操作:

  1. 打开浏览器访问: http://localhost:8001
  2. 登录小米账号: 使用小米账号完成登录认证
  3. 设置密码: 设置一个六位数字密码(用于后续 API 调用)

等待用户确认: 询问用户是否已完成认证和密码设置,等待用户回复"已完成"或"确认"后继续。

步骤 3: 验证配置

用户确认后,尝试获取摄像头列表验证配置是否成功:

python scripts/camera_client.py \
  --server http://localhost:8001 \
  --password YOUR_PASSWORD \
  --list
步骤 4: 保存配置(可选)

如果获取摄像头列表成功,询问用户是否保存以下信息以便后续使用:

  1. 密码: 保存到 MILOCO_PASSWORD 环境变量或配置文件
  2. 摄像头列表: 记录摄像头 ID 和名称的对应关系

示例保存方式:

# 保存到环境变量(当前会话)
export MILOCO_PASSWORD="你的六位密码"

# 或保存到 shell 配置文件(永久保存)
echo 'export MILOCO_PASSWORD="你的六位密码"' >> ~/.zshrc

后续使用流程

完成首次设置后,后续可直接获取摄像头截图:

1. 确认服务状态
docker ps | grep miloco

如果服务未运行,先启动:

docker start miloco
2. 获取摄像头截图
# 使用已保存的密码环境变量
python scripts/camera_client.py \
  --server http://localhost:8001 \
  --password $MILOCO_PASSWORD \
  --camera-id "CAMERA_ID" \
  --output ./images

脚本功能说明

脚本位于 scripts/camera_client.py,支持以下功能:

列出所有摄像头
python scripts/camera_client.py \
  --server http://localhost:8001 \
  --password YOUR_PASSWORD \
  --list

输出示例:

摄像头列表:
--------------------------------------------------------------------------------
  ID: 1036201996
  名称: 客厅摄像头
  在线: 是
  位置: 我家 - 客厅
--------------------------------------------------------------------------------
获取指定摄像头截图
# 使用默认文件名 (日期_did_时分秒.jpg)
python scripts/camera_client.py \
  --server http://localhost:8001 \
  --password YOUR_PASSWORD \
  --camera-id "1036201996" \
  --output ./images

# 指定自定义文件名
python scripts/camera_client.py \
  --server http://localhost:8001 \
  --password YOUR_PASSWORD \
  --camera-id "1036201996" \
  --output ./images \
  --filename "living_room_snapshot"
持续获取截图(监控模式)
# 每30秒获取一次
python scripts/camera_client.py \
  --server http://localhost:8001 \
  --password YOUR_PASSWORD \
  --camera-id "1036201996" \
  --output ./images \
  --loop

# 每60秒获取一次,自动清理1天前的图片
python scripts/camera_client.py \
  --server http://localhost:8001 \
  --password YOUR_PASSWORD \
  --camera-id "1036201996" \
  --output ./images \
  --loop --interval 60 --cleanup

参数说明

参数短参数说明必填
--server-sMiloco 服务器地址是
--password-p密码(也可通过 MILOCO_PASSWORD 环境变量设置)是
--username-u用户名,默认 admin否
--list-l列出所有摄像头否
--camera-id-c摄像头设备ID (did)否*
--output-o输出目录,默认当前目录否
--filename-f自定义文件名(不含扩展名)否
--loop持续获取图片否
--interval-i循环间隔秒数,默认30否
--cleanup自动清理过期图片否
--cleanup-days清理多少天前的图片,默认1否
--debug-d启用调试日志否

* 获取截图时必填

工作流程总结

首次使用:
┌─────────────────┐
│ 1. 启动 Docker  │
└────────┬────────┘
         ▼
┌─────────────────────────────────┐
│ 2. 引导用户访问 localhost:8001  │
│    完成小米账号认证 + 设置密码   │
└────────┬────────────────┘
         ▼
┌─────────────────────────────────┐
│ 3. 等待用户确认完成             │
└────────┬────────────────┘
         ▼
┌─────────────────────────────────┐
│ 4. 尝试获取摄像头列表           │
└────────┬────────────────┘
         ▼
┌─────────────────────────────────┐
│ 5. 询问是否保存密码和摄像头信息 │
└────────┬────────────────┘
         ▼
┌─────────────────────────────────┐
│ 6. 完成,可随时获取截图         │
└─────────────────────────────────┘

后续使用:
┌─────────────────┐
│ 确认服务运行    │
└────────┬────────┘
         ▼
┌─────────────────┐
│ 直接获取截图    │
└─────────────────┘

注意事项

  • 确保摄像头设备在线才能获取截图
  • 截图文件名默认格式:日期_did_时分秒.jpg
  • 支持的图片格式:JPG、PNG(根据响应自动判断)
  • 如果认证失败会自动重试登录一次
  • 密码为六位数字,在 Miloco Web 界面设置

项目信息

Comments

Markdown supported