Module cli

Navigating the console

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.

Accessing the CLI through SSH

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.

Navigating the CLI

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 directories
  • cd, cd /etc/config - change directory
  • cat /etc/config/network - print file contents
  • less /etc/config/network - print file contents in a scrollable view

OpenWrt specific commands and infrastructure

stacktoggle 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:

Services

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 services
  • service <service_name> status - show status of a service
  • service <service_name> start - start a service
  • service <service_name> stop - stop a service
  • service <service_name> restart - restart a service
  • service <service_name> enable - enable a service to start on boot
  • service <service_name> disable - disable a service from starting on boot

Services that might be of interest:

  • nats-server - NATS server
  • netd - Network monitoring daemon
  • updated - 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)

Get logs

Logs can be obtained with logread command.

  • logread - print all logs
  • logread -f - print only new logs as they are generated
  • logread | grep <search_term> - print only logs that contain a search term
  • logread | grep netd > netd.log - print only netd logs and save them to a file netd.log

Text editor vi

stacktoggle 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 vi
  • i - enter insert mode
  • [esc] - exit insert mode
  • :w - save file
  • :q - quit vi
  • :wq - save and quit vi

See vi cheat sheet for more commands.

Configuration management uci

OpenWrt 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 configuration
  • uci show <config_name> - list configuration for a specific config
  • uci get <config_name>.<section_name>.<option_name> - get a specific option value
  • uci set <config_name>.<section_name>.<option_name>=<value> - set a specific option value
  • uci commit <config_name> - commit changes to a config

Reloading configuration

reload_config is a helper script that checks current configuration files against previous configuration files and reloads services that are affected by the changes.

System upgrade

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.

Custom things added to ToggleOS

NATS cli

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.

Setting NATS leafnode connection

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 help
  • leafnode -a <address> -p <port> - set leafnode connection address and port

Note: leafnode script depends on NATS CLI tool being installed.

jq - JSON processor

jq 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 message

You 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.

Environment variables

$SN - serial number of the device

echo $SN
nats req io.$SN.updated.config ""

Index

Type Aliases

Generated using TypeDoc