tracking-pettracer-location
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTracking PetTracer pet location
追踪PetTracer宠物位置
Why this exists
开发背景
PetTracer exposes an (unofficial) web portal API used by their apps/website. This skill gives a reliable, low-drama workflow for:
- Current location (latest known point)
- Recent route/history (time-windowed points)
- Near-real-time updates (WebSocket push, optional)
It is designed to minimise API load (be respectful) and to produce consistent, copy/paste-friendly outputs.
PetTracer开放了一个(非官方)网页门户API供其应用/网站使用。本工具提供可靠、低复杂度的工作流,支持:
- 当前位置(最新已知点位)
- 近期路线/历史记录(时间窗口内的点位)
- 近实时更新(WebSocket推送,可选)
工具设计旨在最小化API负载(保持友好调用),并生成一致、便于复制粘贴的输出结果。
Quick start
快速开始
Snapshot location (recommended default)
快照定位(推荐默认方式)
- Set credentials (prefer env vars, not CLI args):
bash
export PETTRACER_USERNAME="you@example.com"
export PETTRACER_PASSWORD="••••••••"- List devices:
bash
python scripts/pettracer_cli.py list --format json --pretty- Locate a pet:
- By name:
bash
python scripts/pettracer_cli.py locate --pet "Fluffy" --format json --pretty- By id:
bash
python scripts/pettracer_cli.py locate --device-id 12345 --format json --pretty- If the account has exactly one collar, you can omit :
--pet/--device-id
bash
python scripts/pettracer_cli.py locate --format json --pretty- 设置凭据(优先使用环境变量,而非命令行参数):
bash
export PETTRACER_USERNAME="you@example.com"
export PETTRACER_PASSWORD="••••••••"- 列出设备:
bash
python scripts/pettracer_cli.py list --format json --pretty- 定位宠物:
- 通过名称:
bash
python scripts/pettracer_cli.py locate --pet "Fluffy" --format json --pretty- 通过ID:
bash
python scripts/pettracer_cli.py locate --device-id 12345 --format json --pretty- 如果账户仅有一个项圈,可省略参数:
--pet/--device-id
bash
python scripts/pettracer_cli.py locate --format json --prettyGet location history (last 6 hours)
获取位置历史记录(最近6小时)
bash
python scripts/pettracer_cli.py history --pet "Fluffy" --hours 6 --format json --prettybash
python scripts/pettracer_cli.py history --pet "Fluffy" --hours 6 --format json --prettyCore workflow the agent should follow
代理应遵循的核心工作流
1) Decide: snapshot vs history vs live updates
1) 选择模式:快照、历史记录或实时更新
- Snapshot: user asks “where is X right now?” → use .
locate - History: user asks “where has X been today/last hour?” → use .
history - Live: user wants continuous updates → use WebSocket (see references/websocket.md).
Default to snapshot unless the user explicitly wants a route or live tracking.
- 快照:用户询问“X现在在哪里?” → 使用命令。
locate - 历史记录:用户询问“X今天/过去一小时去过哪里?” → 使用命令。
history - 实时:用户需要持续更新 → 使用WebSocket(详见references/websocket.md)。
除非用户明确需要路线或实时追踪,否则默认使用快照模式。
2) Authenticate safely
2) 安全认证
Preferred order:
- Use if already available.
PETTRACER_TOKEN - Else login with +
PETTRACER_USERNAME(orPETTRACER_PASSWORD).PETTRACER_EMAIL
Never ask the user to paste tokens into chat. Ask them to set env vars or store secrets in their vault.
Optional overrides (useful for debugging / future-proofing):
- (REST base; default
PETTRACER_API_BASE)https://portal.pettracer.com/api - (WebSocket base; default
PETTRACER_WS_BASE)wss://pt.pettracer.com/sc
优先顺序:
- 若已存在则直接使用。
PETTRACER_TOKEN - 否则使用+
PETTRACER_USERNAME(或PETTRACER_PASSWORD)登录。PETTRACER_EMAIL
绝对不要要求用户在聊天框中粘贴令牌。请引导用户设置环境变量或将密钥存储在密码管理器中。
可选覆盖配置(用于调试/适配未来变更):
- (REST接口基础地址;默认值
PETTRACER_API_BASE)https://portal.pettracer.com/api - (WebSocket基础地址;默认值
PETTRACER_WS_BASE)wss://pt.pettracer.com/sc
3) Identify the right device
3) 识别正确设备
- Fetch devices via (wrapped by
GET /api/map/getccs).pettracer_cli.py list - Match by case-insensitively.
details.name - If multiple matches: show a disambiguation list (id + name) and ask the user which one.
- If no match: show available device names.
- If the account has exactly one collar, you can default to it.
- 通过接口获取设备列表(由
GET /api/map/getccs命令封装)。pettracer_cli.py list - 不区分大小写匹配字段。
details.name - 若存在多个匹配项:显示消歧列表(ID + 名称)并询问用户选择。
- 若无匹配项:显示可用设备名称。
- 若账户仅有一个项圈,可默认选择该设备。
4) Fetch location data
4) 获取位置数据
- Current location comes from (collars) or top-level
device.lastPos(HomeStations):posLat/posLong- ,
posLatposLong - (timestamp)
timeMeasure - (accuracy, metres) or
acc(fallback)horiPrec
- History uses with:
POST /api/map/getccpositions- ,
devId(ms),filterTime(ms)toTime
See references/endpoints.md and references/data-model.md.
- 当前位置来自(项圈)或顶级字段
device.lastPos(家庭基站):posLat/posLong- (纬度)、
posLat(经度)posLong - (时间戳)
timeMeasure - (精度,单位米)或
acc(备选字段)horiPrec
- 历史记录使用接口,参数包括:
POST /api/map/getccpositions- 、
devId(毫秒)、filterTime(毫秒)toTime
详见references/endpoints.md和references/data-model.md。
5) Present results consistently
5) 一致呈现结果
When reporting location, include:
- Pet name + device id
- Coordinates (lat, lon)
- Last update time
- Accuracy (if present)
- How old the fix is (seconds/minutes since last fix), if possible
- Optional: a map link (Google Maps + OpenStreetMap)
Preferred JSON shape (for tool-to-tool handoff):
json
{
"pet": { "id": 12345, "name": "Fluffy" },
"last_fix": {
"lat": 48.137154,
"lon": 11.576124,
"time": "2026-02-25T12:34:56+00:00",
"accuracy_m": 12
},
"last_fix_age_s": 90,
"battery_mv": 4012,
"battery_percent_est": 78,
"home": false,
"links": {
"google_maps": "https://www.google.com/maps?q=48.137154,11.576124",
"openstreetmap": "https://www.openstreetmap.org/?mlat=48.137154&mlon=11.576124#map=18/48.137154/11.576124"
}
}Notes:
- is an estimate derived from voltage (PetTracer reports millivolts, not %).
battery_percent_est - If there’s no GPS fix, report and include
error=no_recent_fix.last_contact
报告位置时需包含:
- 宠物名称 + 设备ID
- 坐标(纬度、经度)
- 最后更新时间
- 精度(若存在)
- 定位数据的时效性(自上次定位以来的秒数/分钟数,若可获取)
- 可选:地图链接(Google Maps + OpenStreetMap)
工具间交互推荐JSON格式:
json
{
"pet": { "id": 12345, "name": "Fluffy" },
"last_fix": {
"lat": 48.137154,
"lon": 11.576124,
"time": "2026-02-25T12:34:56+00:00",
"accuracy_m": 12
},
"last_fix_age_s": 90,
"battery_mv": 4012,
"battery_percent_est": 78,
"home": false,
"links": {
"google_maps": "https://www.google.com/maps?q=48.137154,11.576124",
"openstreetmap": "https://www.openstreetmap.org/?mlat=48.137154&mlon=11.576124#map=18/48.137154/11.576124"
}
}注意:
- 是根据电压估算的数值(PetTracer仅报告毫伏值,而非百分比)。
battery_percent_est - 若无GPS定位数据,需报告并包含
error=no_recent_fix(最后联系时间)。last_contact
Live tracking (optional, avoid aggressive polling)
实时追踪(可选,避免高频轮询)
If you need frequent updates:
- Prefer WebSocket push (avoid aggressive polling).
- Only fall back to polling if WebSocket is not possible; keep polling ≥ 60s by default.
Install dependency:
bash
pip install aiohttpThen run:
bash
python scripts/pettracer_watch.py --pet "Fluffy"See:
- references/websocket.md
- for a working SockJS/STOMP implementation.
scripts/pettracer_watch.py
若需要频繁更新:
- 优先使用WebSocket推送(避免高频轮询)。
- 仅在WebSocket不可用时才退回到轮询模式;默认轮询间隔≥60秒。
安装依赖:
bash
pip install aiohttp运行命令:
bash
python scripts/pettracer_watch.py --pet "Fluffy"详见:
- references/websocket.md
- (已实现的SockJS/STOMP示例)
scripts/pettracer_watch.py
Troubleshooting playbook
故障排查指南
No location / lastPos
is missing
lastPos无位置数据 / lastPos
字段缺失
lastPosCommon reasons:
- Collar hasn’t reported a GPS fix recently (indoors, low signal).
- Battery low / collar off.
- Subscription expired.
Action:
- Report “no recent fix” and show if available.
lastContact - Suggest switching to a higher-frequency mode (Fast/Live) in the PetTracer app/portal only if the user asks (see references/modes.md).
常见原因:
- 项圈近期未上报GPS定位(室内环境、信号弱)。
- 电量低 / 项圈已关闭。
- 订阅已过期。
处理步骤:
- 报告“无近期定位数据”,若有则显示(最后联系时间)。
lastContact - 仅在用户询问时,建议在PetTracer应用/门户中切换至高频率模式(快速/实时)(详见references/modes.md)。
Auth failures (401 / invalid_auth)
认证失败(401 / invalid_auth)
- Re-login to obtain a fresh .
access_token - Confirm the login payload uses keys +
login(notpassword).username
- 重新登录获取新的。
access_token - 确认登录请求体使用+
login作为键名(而非password)。username
Rate limiting / service respect
速率限制 / 服务友好性
- Avoid tight loops against .
/map/getccs - Prefer WebSocket for near-real-time tracking.
- 避免对接口进行循环调用。
/map/getccs - 近实时追踪优先使用WebSocket。
THE EXACT PROMPT — Location response format
位置响应格式规范
Use this when the user wants a human-readable answer:
Give the pet’s latest known PetTracer location.
Include:
- Pet name + device id
- Time of last fix (and last contact if different)
- Coordinates + map link(s)
- Accuracy (metres) if present
- One-line assessment: “recent fix” vs “stale fix” (use last_fix_age_s if available; interpret in the context of the current tracking mode)当用户需要易读的人工回复时,遵循以下格式:
提供宠物的最新PetTracer定位信息。
需包含:
- 宠物名称 + 设备ID
- 最后定位时间(若最后联系时间不同则一并显示)
- 坐标 + 地图链接
- 精度(单位米,若存在)
- 一行评估结论:“近期定位”或“过期定位”(若可获取last_fix_age_s则使用该值;结合当前追踪模式判断)