Files
jmj c037b43f4a Initial commit: PulseWall hub, Android app, and protocol docs
- hub: FastAPI backend (MCP server, ADB LAN controller, bridge, storage)
- hub/web: Vue 3 admin console (device manager, screen mirror, chat workbench)
- android: Kotlin shell app with WebView stage, OTA, telemetry, keep-alive
- protocol: architecture, MCP schema, and WebSocket protocol specs
2026-11-30 07:37:34 +08:00

4.7 KiB

PulseWall WebSocket Protocol (Hub <-> Android Device) v1.0

Transport: ws://<hub-host>:<port>/ws/device/{device_id} (or wss:// behind TLS reverse proxy). Optional auth header: Authorization: Bearer <token> or query ?token=<token>.

Every frame is a JSON envelope:

{
  "type": "namespace.action",
  "msg_id": "uuid-v4",
  "ts": 1732880000000,
  "payload": {}
}

1. Android -> Hub Messages

device.hello (sent immediately on connect)

{
  "device_id": "pixel-wall-01",
  "device_name": "客厅监控机",
  "model": "Xiaomi Mi 10",
  "android_sdk": 30,
  "android_release": "11",
  "app_version": "0.1.0",
  "capabilities": ["basic", "root"],
  "display_profile": {
    "device_type": "phone",
    "orientation": "portrait",
    "width_px": 1080,
    "height_px": 2340,
    "viewport_css_w": 392,
    "viewport_css_h": 850,
    "dpr": 2.75,
    "safe_area_top_dp": 32,
    "safe_area_bottom_dp": 20,
    "font_scale": 1.0,
    "webview_version": "114.0.5735.196"
  }
}

device.telemetry (periodic heartbeat, default every 10s or on change)

{
  "battery_pct": 82,
  "is_charging": true,
  "battery_temp_c": 31.4,
  "battery_current_ma": 420,
  "cpu_usage_pct": 14.2,
  "mem_used_mb": 2910,
  "mem_total_mb": 7800,
  "thermal_zones": { "cpu": 39.5, "gpu": 37.0 },
  "wifi_rssi_dbm": -52,
  "screen_on": true,
  "display_profile": { "...": "updated if rotated" }
}

render.result (response to render.apply or runtime self-heal)

{
  "task_id": "task_abc123",
  "trigger": "initial_render | runtime_watchdog",
  "status": "rendered | rendered_after_local_fix | needs_clarification | failed_rolled_back",
  "snapshot_id": "snap_005",
  "attempts": 1,
  "final_html": "...",
  "local_fix_summary": "Fixed overflow width on 392px viewport",
  "clarification_questions": [
    {
      "field": "server.gpu_temp",
      "question": "模板引用了 server.gpu_temp 但数据上下文中未提供,请问实际字段名或数值是什么?"
    }
  ],
  "errors": []
}

interaction.reply (user tapped a preset button or submitted custom text)

{
  "interaction_id": "int_001",
  "alert_id": "alert_001",
  "selected_preset_id": "restart",
  "selected_label": "立即重启服务",
  "custom_text": null,
  "responded_at": 1732880012345
}

console.error_report (runtime errors observed by WebView watchdog)

{
  "snapshot_id": "snap_005",
  "source": "window.onerror | unhandledrejection | console.error | vue",
  "message": "TypeError: Cannot read properties of undefined (reading 'temp')",
  "stack": "...",
  "repair_status": "repairing | fixed | needs_clarification | rolled_back"
}

2. Hub -> Android Messages

config.push (sent on connect & whenever updated in Hub Admin)

{
  "repair_ai": {
    "enabled": true,
    "base_url": "https://api.openai.com/v1",
    "api_key": "sk-...",
    "model": "gpt-4o-mini",
    "timeout_sec": 30,
    "max_retries": 3,
    "runtime_cooldown_sec": 30
  },
  "telemetry_interval_sec": 10,
  "theme": "dark-glass"
}

feed.push

{
  "item_id": "feed_001",
  "title": "备份完成",
  "body": "数据库夜间快照已完成 (1.4 GB)",
  "level": "info",
  "source": "backup-agent",
  "sound": "ding",
  "html_snippet": null,
  "tags": ["db", "cron"],
  "ts": 1732880000000
}

alert.trigger / alert.dismiss

{
  "alert_id": "alert_001",
  "title": "核心服务宕机",
  "message": "prod-api-01 连续 3 次健康检查失败 (HTTP 502)",
  "level": "critical",
  "presentation": "fullscreen_alarm",
  "sound": "siren",
  "vibrate": true,
  "wake_screen": true,
  "tts_text": "紧急警报,生产接口服务宕机,请立即处理",
  "details_code": "upstream connect error or disconnect/reset before headers",
  "custom_html": null,
  "interaction": {
    "interaction_id": "int_001",
    "mode": "action_required",
    "presets": [
      { "id": "ack", "label": "确认收到", "style": "primary" },
      { "id": "restart", "label": "立即重启服务", "style": "danger" },
      { "id": "mute_30m", "label": "静音 30 分钟", "style": "secondary" }
    ],
    "allow_custom_input": true,
    "custom_input_placeholder": "输入自定义处理指示..."
  }
}

render.apply

{
  "task_id": "task_abc123",
  "mode": "full",
  "title": "机房监控看板",
  "html": "<div id='app'>...</div>",
  "data_context": {},
  "snapshot_id": "snap_005"
}

render.rollback

{
  "snapshot_id": "snap_004",
  "html": "..."
}

clarification.answer (upstream AI replied to end-side Repair AI's data question)

{
  "task_id": "task_abc123",
  "answers": { "server.gpu_temp": "该机器无独显,请改为展示 cpu_temp 并隐藏 GPU 卡片" },
  "updated_data": {},
  "updated_html": null
}