SWITCH

The SWITCH command returns the current position of the sliding switch.

Advanced payloads can use this to determine user input.

This does not necessarily reflect the switch position when the Packet Squirrel was booted, only the current position of the switch.

Return values

When called with a timeout, the SWITCH script will return the position of the switch (switch1 through switch4).

To learn how to write payloads which can handle responses, check the Advanced Bash section!

Experimenting

You can experiment using the SWITCH command live, either in the Web Shell in the web UI, or via ssh!

Examples

Payloads using the SWITCH command must handle the output; for example the following payload sets the LED based on the switch position. For more information about writing advanced payloads, see the Advanced Bash section!

#!/bin/bash

# Title: Switch Demo
# 
# Description: Set the LED color based on the position of the switch.

NETMODE NAT

SP=$(SWITCH)

case $SP in
        "switch1")
                LED R SINGLE
                ;;
        "switch2")
                LED B SINGLE
                ;;
        "switch3")
                LED G SINGLE
                ;;
        "switch4")
                LED W SINGLE
                ;;
esac

Last updated