I'm a beginner and I am presently working on an home automation project inspired by this one:
https://maker.pro/raspberry-pi/tutorial ... dHSyN3pbtQ
I have my own website, which consist of an ON and OFF button, from which I am able to turn on and off a light, which is attached to a pi zero W through a relay.
On the pi zero, there is a python code constantly checking the status of the url address of my website,. Here is the code:
Code: Select all
import RPi.GPIO as GPIO
import urllib.request
import urllib.error
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(5,GPIO.OUT)
true = 1
while(true):
try:
response = urllib.request.urlopen('https://blablabla.com/buttonStatus.php?id=1')
status = response.read()
except urllib.error.HTTPError as e:
print(e.code)
except urllib.error.URLError as e:
print(e.args)
print (status)
if status==b'ON':
GPIO.output(5,True)
elif status==b'OFF':
GPIO.output(5,False)
I recently had an idea but I don't really know how to achieve it. I would like to wire a simple pushbutton or a matrix keyboard to another pi zero W (completely independent) and when I would click on the button it would change the php status of my button, just as my website page does. It would be a sort of wi-fi button to control the light.
To do this I know I need to write a python code but I have no idea how it is supposed to look like.
Correct me on that point, but I don't think I need add stuff in my php code...
It would be very nice if someone could put me on the right track
Best regards,