Controling my Cisco-SG300 Switch with the StreamDeck & Paspi

I have some PoE connected devices in my Lab, which I like to shut down when I don’t use them. For exapmle the Cisco-SX10 camera, some Cisco Touch-10 or the latest addition the Logitech TAP-IP. All run on PoE, but are not so simple to power down, or not at all, which wastes power, and heats up my room. Which is already very warm from my main PC & screen.

As the Switch does not have a REST-API, I could have used SNMP, but this was not really my idea. I rememberd from my old days at Cisco, that we used TCL-scripts and EXPECT to configure devices via telnet…

Some quick googleing later, I had installed, telnet, the TCL script language and EXPECT on the Raspi4.

sudo apt install expect telnet  tcl-expect

Once this is installed, you can write a “script” like you would do with bash, but emulating on waht you would do when logging into the switch:

#!/usr/bin/expect
spawn telnet 192.168.2.131
expect "User Name:"
send "USERNAME\n"
expect "Password:"
send "PASSWORD\n"
expect "SW-OG1-02#"
send "config terminal\n"
expect "SW-OG1-02(config)#"
send "interface GigabitEthernet 5\n"
expect "SW-OG1-02(config-if)"
send "power inline auto\n"
send "exit\n"
expect "SW-OG1-02(config)#"
send "exit\n"
expect "SW-OG1-02#"
send "exit\n"

You see these “expect” lines, this is the output of the terminal, what you would expect to see! It’s always good to wait for the “feedback” of the terminal, so you know the device is ready to recive your next command.

I created a file for each port and one for on and off. Once you have all of them, change the right to be executable, and here you are.

In the Companion App you would run a “Internal: Run shell path (local)” action. and give it enough timeout, like 10’000ms.

Unfortunately, I can not read the state this way

Categories: UncategorizedTags: