=====moshctl User Guide===== ''moshctl'' is the command-line client for the MOSH Admin API. It is the main user-facing tool for checking bridge health, inspecting nodes and elements, and sending commands to devices through ''moshbridge''. This guide reflects the current CLI behavior in the codebase and the auth flow currently running on the server. ===What ''moshctl'' Talks To=== ''moshctl'' sends HTTP requests to the MOSH Admin API exposed by ''moshbridge''. The current default API URL is: ''http://127.0.0.1:8088'' Most commands require a bearer token. The only command intended to work without a token is: ''moshctl health'' ====Quick Start==== ===1. Create an API Token on the Bridge Host=== Run this where ''moshbridge'' is installed: moshbridge admin token --store /var/lib/mosh/adminapi_tokens.json --name moshctl-laptop This prints a raw token once. It will look something like: ''mtk_ab12cd_7b2XcYpL9uV3qWmR8nKs4dTfZ1eH6jQa'' Save it right away. ===2. Save the Token for ''moshctl''=== Recommended, so the token does not end up in your shell history: echo '' | moshctl auth init --token-stdin Or explicitly: moshctl auth init --token '' By default, moshctl stores the token here:
~/.config/mosh/token
If token save and verification succeed, you should see:
Saved token to /home/youruser/.config/mosh/token
Token verified successfully.
=== 3. Verify Connectivity === Unauthenticated health check: moshctl health Authenticated status check: moshctl status == Global Flags == These flags apply to all commands. === -url === Base URL for the MOSH Admin API. Example: moshctl -url http://192.168.1.50:8088 status === -token-file === Path to the raw bearer token file. Example: moshctl -token-file ~/.config/mosh/token status === -version === Print the CLI version and exit. Example: moshctl -version == Authentication Commands == ===moshctl auth init === Saves a raw bearer token locally and immediately verifies that it works against the bridge. Examples: moshctl auth init --token '' echo '' | moshctl auth init --token-stdin With a custom token file: echo '' | moshctl -token-file ~/.config/mosh/lab-token auth init --token-stdin Notes: * The token file stores the raw bearer token, not the bcrypt hash. * ''moshctl'' writes the token file with restrictive permissions. * The token is verified by making a real API call after saving it. == Health and Status == === moshctl health === Checks whether the bridge HTTP API is up. Example: moshctl health Typical response: { "status": "ok" } This is the best first check if you are unsure whether the bridge is reachable. === moshctl status === Shows the bridge status summary. Example: moshctl status This requires a valid token. == Node and Element Inspection == MOSH follows this model:
Node -> Elements -> Commands
=== moshctl nodes === Lists all known nodes. moshctl nodes === moshctl node <node_id> === Gets details for one node. moshctl node testnode1 === moshctl elements <node_id> === Lists elements for a node. moshctl elements testnode1 === moshctl element <node_id> <element_id> === Gets details for one element. moshctl element testnode1 relay1 == Sending Commands == === moshctl command <node_id> <element_id> <ON|OFF> === Sends a command to an element. Current CLI behavior: * Command name is always set. * Payload is {"state":"ON"} or {"state":"OFF"}. * Request is sent as reliable: true. Example: moshctl command testnode1 relay1 ON Typical response: { "status": "queued", "command_id": "cmd_123", "node_id": "testnode1", "element_id": "relay1" } === moshctl command-status <command_id> === Checks the state of a previously queued command. moshctl command-status cmd_123 == Queue, In-Flight, Failures, and Modules == These commands are useful for debugging and bridge inspection. === moshctl queue === Shows queue status. moshctl queue === moshctl inflight === Shows in-flight command state. moshctl inflight === moshctl failures === Shows recent command failures. moshctl failures === moshctl modules === Shows module status. moshctl modules Note: * queue, inflight, and failures currently map to debug-style endpoints and may evolve as the Admin API cleanup continues. == First-Run Troubleshooting == === Error: Token File Not Found === You may see:
Client init error: Read token file "/home/youruser/.config/mosh/token": open /home/youruser/.config/mosh/token: no such file or directory
Hint: create a token with `moshbridge admin token --store /var/lib/mosh/adminapi_tokens.json --name ` and save the raw token to /home/youruser/.config/mosh/token
Fix: # Create a token with moshbridge admin token. # Save it with moshctl auth init --token-stdin. # Retry your command. === moshctl health Works, but moshctl status Fails === This usually means: * the bridge is up * your token is missing, invalid, or revoked Reinitialize the token: echo '' | moshctl auth init --token-stdin === Connection Errors === If you see connection failures, check: * moshbridge is running * the API bind address is correct * your -url matches the bridge address * the bridge host firewall allows access if you are connecting remotely Example remote check: moshctl -url http://192.168.1.50:8088 health == Recommended Daily Workflow == === Inspect the Bridge === moshctl health moshctl status moshctl nodes moshctl elements testnode1 === Control a Relay === moshctl command testnode1 relay1 ON moshctl command-status cmd_123 === Check Runtime Issues === moshctl queue moshctl inflight moshctl failures moshctl modules == Command Reference ==
moshctl health
moshctl status
moshctl nodes
moshctl node 
moshctl elements 
moshctl element  
moshctl command   
moshctl command-status 
moshctl queue
moshctl inflight
moshctl failures
moshctl modules
moshctl auth init --token 
moshctl auth init --token-stdin
== Mental Model == If you remember just one thing: moshctl is a thin local client for the MOSH Admin API. It does not talk directly to radios or devices. It asks moshbridge to inspect state and queue commands using the Node -> Element -> Command model.