Skip to content

websocket usb config

Jim edited this page Feb 8, 2017 · 16 revisions

Websocket API: usb-config

  • Location ws://localhost:8080/ws/usb-config

指令集

列舉可用清單

  • list
  • {"status": "ok", "ports": ["PORT 1", "PORT 2" ... ]}

設定連線用金鑰

  • key -----BEGIN RSA PRIVATE KEY-----\n.......\n-----END RSA PRIVATE KEY-----
  • {"status": "ok"}

連線至印表機

注意,如果未設定金鑰將會發生錯誤

  • connect [PORT]
  • Success: {"status": "ok", "serial": "XXX", "version": "[VER]", "name": "[name]", "model": "[model]", "password": [true|false], "uuid": "[32碼hex字串]"}
  • Error: {"status": "error", "error": "[ERROR_SYMBOL]"}

建立 Auth

  • authauth [password]
  • Success: {"status": "ok"}
  • Error: {"status": "error", "error": "[ERROR_SYMBOL]"}

設定印表機基本資料名稱

  • set_nickname 1234 (use this)
  • set general {"name": "[printer name]"} (old version, this is for reference)
  • Success: {"status": "ok"}
  • Error: {"status": "error", "error": "[ERROR_SYMBOL]"}

設定密碼

  • reset_password [PASSWORD]
  • Success: {"status": "ok", "password": true}
  • Error: {"status": "error", "error": "[ERROR_SYMBOL]"}

取得 Wifi 清單

  • scan_wifi_access_points (use this)
  • scan_wifi (old version, this is for reference)
  • Success: {"status": "ok", "wifi": [{security: 'WPA2-PSK’, ssid: 'FLUX-2.4’, rssi: [-100~0]}, … ]}
  • Error: {"status": "error", "error": "[ERROR_SYMBOL]"}
{
    "access_points": [
        {
            "bssid": "6C:19:8F:F2:1D:0D",
            "ssid": "FLUX-Software",
            "security": "WPA2-PSK",
            "encrypt": true,
            "rssi": -66
        },
        {
            "bssid": "EC:22:80:F9:6D:66",
            "ssid": "FLUX_LAB",
            "security": "WPA2-PSK",
            "encrypt": true,
            "rssi": -76
        }
    ],
    "cmd": "scan",
    "status": "ok"
}

設定無線網路

無密碼網路
  • set network {"wifi_mode": "client", "ssid": "[SSID]", "security": "", "method": "dhcp"}
  • Success: {"status": "ok", "wifi": true}
  • Error: {"status": "error", "error": "[ERROR_SYMBOL]"}
WEP 網路
  • set network {"wifi_mode": "client", "ssid": "[SSID]", "security": "WEP", "wepkey": "[PASSWORD]", "method": "dhcp"}
  • Success: {"status": "ok", "wifi": true}
  • Error: {"status": "error", "error": "[ERROR_SYMBOL]"}
WPA/WPA2 PSK 網路
  • set network {"wifi_mode": "client", "ssid": "[SSID]", "security": "WPA-PSK"|"WPA2-PSK", "psk": "[PASSWORD]", "method": "dhcp"}
  • Success: {"status": "ok", "wifi": true}
  • Error: {"status": "error", "error": "[ERROR_SYMBOL]"}
使用者自行指定 IP 時在 dictionary 加入下列選項

{"ip": "x.x.x.x", "mask": 24, "route": "y.y.y.y", "nameservers": ["z.z.z.z"]}

並且將 "method"="dhcp" 改為 "method"="static"

AP 模式

"wifi_mode": "client" 改為 "wifi_mode": "host"

取得無線網路狀態

  • get_wifi_ssid (use this)
    • get network (old version, for reference)
  • ⇠ success:
// connecting
{
    "status": "ok",
    "ssid": ""
}
// connected
{
    "status": "ok",
    "ssid": "FLUX-2.4"
}
  • Success: {"status": "ok", "ssid": "[SSID]", "ip": ["ip 1", "ip 2", ..., "ip N"]} # ip 有可能是 ipv4 或 ipv6
  • Error: {"status": "error", "error": "[ERROR_SYMBOL]"}