For a while, I have been turning the camera on the Pi in the greenhouse on and off manually. By that I mean…
- Connecting to the Pi using VNC
- Opening the /var/tmp directory in the file manager
- Creating a file called blind to switch the camera off, or
- Deleting/renaming the blind file to switch the camera on
- Disconnecting from the Pi
That’s clearly a huge faff, so I decided I’d finally make a GUI based program to do the job, using guizero. Other GUI libraries were either immensely complex or mysteriously impossible to install. I looked at a couple of example programs, and cobbled this together…
import paramiko
from guizero import App, Text, PushButton
def switch_camera_on():
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command("sudo rm /var/tmp/blind")
def switch_camera_off():
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command("touch /var/tmp/blind")
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("server-name-here", username = "user-name-here", password = "password-here")
app = App(title="Greenhouse Camera Control", bg = "lightblue", width = 400, height = 200)
welcome_message = Text(app, text = "Click button to switch camera state.", size = 15)
onswitch = PushButton(app, command = switch_camera_on, text = "Camera on.")
offswitch = PushButton(app, command = switch_camera_off, text = "Camera off.")
app.display()
It does need you to have used ssh-keygen on your systems, so they can communicate. I can’t believe how easy simple stuff like this is to hack out!