«DiY» WeSwitch#
Switch Sockets via wired network Completed
The Challenge#
Enable switching of a power socket (basically an relais) remotely via wired network operated by a tech-savvy user.
Given / provided components:
I coulnd’t find the operation manual online anymore, since I got it in paper form I scanned it: Operation Manual SwitchBox Relais-V1
Outcome#
Use command line tool pinctrl shipped with Raspberry Pi OS Lite (64-bit) to control remotely one or up to 26 Relais via ssh.
Usage#
The BCM
pin numbers are to be used. See RPI Pinout.
Set-up passwordless login:
some_user@some_host:~$ ssh-copy-id weswitch@weswitch
Common commands:
1some_user@some_host:~$ ssh weswitch@weswitch "pinctrl 26"
226: op -- pd | hi // GPIO26 = output
3some_user@some_host:~$ ssh weswitch@weswitch "pinctrl 26 dl"
4some_user@some_host:~$ ssh weswitch@weswitch "pinctrl 26"
526: op -- pd | lo // GPIO26 = output
6some_user@some_host:~$ ssh weswitch@weswitch "pinctrl 26 dh"
Modify initial states#
Currently pins 19
and 26
are set to ON
after reboot. All other pins are in default behavior which is OFF
.
The initial state of each pin can be changed by modifying the file /boot/firmware/config.txt
. The keyword dh
needs to be replaced by dl
:
For this edit the file /boot/firmware/config.txt
(you need sudo rights):
1some_user@some_host:~$ ssh weswitch@weswitch "sudo vi /boot/firmware/config.txt"
2some_user@some_host:~$ ssh weswitch@weswitch "sudo reboot"
As default the GPIOs are OFF after reboot. Let’s change it as described in the RPI documentation:
Hint: Existing explicit settings you can change using sed to be quicker:
1some_user@some_host:~$ ssh weswitch@weswitch "sudo sed -i 's/\(gpio=19=op,\)dh/\1dl/' /boot/firmware/config.txt"
2some_user@some_host:~$ ssh weswitch@weswitch "sudo sed -i 's/\(gpio=26=op,\)dh/\1dl/' /boot/firmware/config.txt"
3some_user@some_host:~$ ssh weswitch@weswitch "sudo reboot"
Pin-out#
Pin-out and orientation of 40-pin header of RPI 4B. Source/credits to: https://toptechboy.com/understanding-raspberry-pi-4-gpio-pinouts/