=====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 '
Or explicitly:
moshctl auth init --token '
By default, moshctl stores the token here:
~/.config/mosh/tokenIf 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 status ===
Shows the bridge status summary.
Example:
Node -> Elements -> Commands===
moshctl nodes ===
Lists all known nodes.
moshctl node <node_id> ===
Gets details for one node.
moshctl elements <node_id> ===
Lists elements for a node.
moshctl element <node_id> <element_id> ===
Gets details for one element.
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-status <command_id> ===
Checks the state of a previously queued command.
moshctl queue ===
Shows queue status.
moshctl inflight ===
Shows in-flight command state.
moshctl failures ===
Shows recent command failures.
moshctl modules ===
Shows module status.
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 --nameFix: # Create a token with` and save the raw token to /home/youruser/.config/mosh/token
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:
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 health moshctl status moshctl nodes moshctl node== Mental Model == If you remember just one thing: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
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.