-
1SSH Configuration
First of all, we need to ensure the SSH is configured on the Raspberry Pi, enter the following command at the terminal to display the RPi configuration screen: Then go to Interfacing Options and enable SSH
sudo raspi-config
-
2IP Address
Once you enable SSH, you need to know your RPI IP Address: just type:
ipconfig
to show your current IP Address (Ethernet or WLAN) -
3Python Code
For this example, we're just going to turn on an LED with the RPi.GPIO library already included in your O.S. Make sure you know the exact location of your code file: i.e. '/Documents/PythonCode/LED.py'
We're going to create our python code file with the command nano + 'filename'.py
nano LED.py
This will open a text editor, this is the code I write for this example:
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(18,GPIO.OUT) print "LED on" GPIO.output(18,GPIO.HIGH)
This will turn on the output from pin #18 (GPIO 24) on your Raspberry Pi
To close and save the file just press 'Ctrl + x'
-
4Shortcuts App
Now that we have or SSH Enabled, IP Address, and Python Code to turn on the LED let's create and SSH Script Shortcut inside Shortcuts App on the iPhone:
Let's create a new shortcut:
Now go to Add Action and search for: Run Script Over SSH:
Then, configure your SSH Script: you'll need:
-Raspberry Pi username: pi (usually the same)
-User Password
-IP Address
-The port for SSH is 22 (Default)
-Script: This will execute the command on the RPi, this will depend on where your python code is: python3 + 'directory'.py
Click Done and customize your Shortcut icon, make sure you select the "Show in Widget" option
Finally, make sure you give a nice shortcut name to your script, let's change de name to something like "Turn On The Light" or "Turn On The Kitchen Light" and give a nice icon to the shortcut:
Close the Shortcuts App and just ask Siri..."Turn On The Light" to execute your script.
Note:
+Make sure you're on the same local network as the RPi, otherwise, you'll need to do Port Forwarding
+You can create another shortcut script to "Turn OFF The Light"
-
5EXTRA Step
Want to ask Siri for your Raspberry Pi CPU Temp?
Just write this command on your SSH script:
vcgencmd measure_temp
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.