デバイスと Device Hub API
最終更新 2026-10-13
クラウドのデバイス台帳、Hub ペアリング、ローカル Device Hub 印刷プロトコル。
クラウドのデバイス台帳#
GET /api/wms/print-devices?warehouse_id=<uuid>&hub_id=<uuid>&page=1&page_size=50
// -> items: id, name, model, device_type, connection, address,
// is_default_label_printer, status, last_seen_at, hub_id, hub_name,
// warehouse_id, warehouse_name, created_atオンライン/オフラインは last_seen_at(2 分のハートビート閾値)で判定します。ペアリング後、Hub はプリンタをこの台帳に自動同期します。
Device Hub ローカルプロトコル#
ペアリングとローカル印刷は、ワークステーション PC 上の Device Hub トレイアプリ経由で WebSocket(ws://127.0.0.1:18443)を使用します(JSON リクエスト/レスポンス、action + params)。hub.info と hub.pair は認証不要、その他の action はペアリングで得た token が必要です。
// 1. user reads the 6-digit code shown in the Device Hub tray app
// 2. pair (no auth required):
ws -> { "action": "hub.pair", "params": { "code": "482910" }, "id": "1" }
ws <- { "id": "1", "ok": true, "data": { "token": "<hub-token>" } }
// 3. store the token locally; all later requests send it (see device-hub lib).
// success envelope: { id, ok: true, data }
// error envelope: { id, ok: false, error: { code, message } }- hub.info —— Hub のバージョン/プラットフォーム情報、認証不要。
- printer.list → { printers };printer.discover は USB+ネットワーク(mDNS)スキャンを開始し、結果は printer.discovered イベントでプッシュされます。
- printer.print { device_id, data: "<zpl>", copies } → { job_id };完了/失敗は print.job_completed イベントで通知されます。
- printer.status { device_id } —— プリンタのリアルタイム状態(紙切れ/リボン切れ/カバー開放など)。
- device.register { device_id, name, is_default } —— 発見したデバイスを登録(クラウド台帳にも報告)。
クラウドリレーのバインド#
ws -> { "action": "hub.cloud_bind", "params": {
"supabase_url": "https://<ref>.supabase.co",
"supabase_anon_key": "<anon-key>",
"organization_id": "<uuid>",
"warehouse_id": "<uuid>" // optional
}, "id": "2" }
ws <- { "id": "2", "ok": true, "data": {} }
// after binding, the Hub pulls print_jobs with its cloud credentials and syncs the device ledger.