For development purposes accessing stacktoggle's command line interface (CLI) can be useful in certain situations. It provides various tools for diagnosing, debugging and configuring the device.
The CLI can be accessed through SSH. The default username is root and it has
no password. SSH connection can be established through local network (LAN)
(local ethernet port or Wi-Fi hotspot). Toggle's local IP address is
192.168.180.1. By default SSH access is blocked through WAN and WWAN
interfaces. If firewall is disabled, then SSH access is allowed through all
interfaces.
stacktoggle has Linux and OpenWrt based operating system. It is a lot slimmer than a typical linux distribution, but it still has a lot of the same tools and commands. If you are not familiar with Linux, you can find a lot of tutorials online. Here are some basic commands to get you started:
ls, ls -l, ls -a, ls /etc/config - list files and directoriescd, cd /etc/config - change directorycat /etc/config/network - print file contentsless /etc/config/network - print file contents in a scrollable viewstacktoggle is based on OpenWrt. OpenWrt has a lot of its own commands and infrastructure that are different from a typical Linux distribution. Here are some of the most useful ones:
On OpenWrt all background processes are managed as services. They can be started, stopped, restarted, enabled and disabled. Here are some examples:
service - list all servicesservice <service_name> status - show status of a serviceservice <service_name> start - start a serviceservice <service_name> stop - stop a serviceservice <service_name> restart - restart a serviceservice <service_name> enable - enable a service to start on bootservice <service_name> disable - disable a service from starting on bootServices that might be of interest:
nats-server - NATS servernetd - Network monitoring daemonupdated - Update daemon (responsible for updating the device and
configuration setting/getting)iod - I/O daemon (responsible for controlling the I/O pins)autod - Auto daemon (responsible for peripherals)Logs can be obtained with logread command.
logread - print all logslogread -f - print only new logs as they are generatedlogread | grep <search_term> - print only logs that contain a search termlogread | grep netd > netd.log - print only netd logs and save them to a
file netd.logvistacktoggle has vi text editor installed. It is a very powerful text
editor, but it has a steep learning curve. Here are some basic commands to get
you started:
vi <file_name> - open a file in vii - enter insert mode[esc] - exit insert mode:w - save file:q - quit vi:wq - save and quit viSee vi cheat sheet for more commands.
uciOpenWrt and stacktoggle uses uci for configuration management. The
configuration is kept in files /etc/config/<config_name>. But it can be
queried and set using uci command. Here are some examples:
uci show - list all configurationuci show <config_name> - list configuration for a specific configuci get <config_name>.<section_name>.<option_name> - get a specific option
valueuci set <config_name>.<section_name>.<option_name>=<value> - set a specific
option valueuci commit <config_name> - commit changes to a configreload_config is a helper script that checks current configuration files
against previous configuration files and reloads services that are affected by
the changes.
sysupgrade is a helper script that is used to update the device. It is used by
updated service. It can also be used manually:
sysupgrade <sysupgrade.bin file> - update the device with a specific
sysupgrade.bin file.Upgrade takes around 7 minutes during which the device is not accessible. Device must not be powered down during update. After the upgrade is done, the device will reboot and will be accessible again.
NATS cli tool can be installed on the Toggle for debugging and testing purposes.
It can be used to publish and subscribe to NATS topics. You can run nats
command to run script that will install NATS cli tool. Note, the Toggle needs to
have internet access to download the tool.
If NATS cli tool is not yet installed the output will look like this:
root@toggle-214000000028:~# nats
WARNING:
NATS CLI tool is not currently installed on this stacktoggle
This script will attempt to download nats-cli binary from internet,
copy it to SD card and install it in /usr/sbin
Proceed? (y/n)
After installation of tool, you will need to close and reopen terminal session
to to have new nats command available.
When you have NATS tool available you can exercise all the NATS APIs that are
defined in the documentation. Most often you will be interested in nats pub
and nats sub commands. So run nats pub --help and nats sub --help to get
more information on how to use these commands.
leafnode is a lua script that configures NATS leafnode connection. It uses
updated service to set the configuration and provides a simple interface for
setting the configuration. Here are some examples:
leafnode -h - print helpleafnode -a <address> -p <port> - set leafnode connection address and portNote:
leafnodescript depends on NATS CLI tool being installed.
jq - JSON processorjq is a command-line JSON processor. It can be used to parse JSON data and
extract specific fields. It is very useful for working with JSON data in the CLI.
Just pipe the JSON data to jq and use its syntax to extract the data you need.
Here are some examples:
Format JSON config:
nats req io.$SN.updated.config "" | jq
Get specific field from JSON config, example, Wi-Fi config:
nats req io.$SN.updated.config "" | jq .network.wireless.sta
note - Personalized messageYou can leave a welcome note that will be shown every time you log into console
of your stacktoggle device. To edit message use command note this will
open vi editor and write to file /etc/note.txt. This can be used to leave some
important information for yourself or other users of the device.
echo $SN
nats req io.$SN.updated.config ""
Generated using TypeDoc