0

I would like to be able to connect a html website to the GPIO pins so that when a button is pushed on the website it turns on a GPIO pin on the pi. I am also wondering if it is possible to take data from another GPIO pin and print it in the html website

1 Answers1

1

Yes, this is possible with a website.

I have built something similar here. It's about controlling a LED strip over the internet. I think you can take the sourcecode from it.

I wrote Python scripts to control the GPIOs. These Python scripts are called and executed by PHP scripts. The PHP script is called with "execute" a URL (e.g. http://raspberrypi/poweron.php). This could be done by a button on your website.

So this could be your Pyhton script: (saved as: /home/pi/Code/App/power_on.py)

#!/usr/bin/env python3

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(12, GPIO.OUT) GPIO.output(12, GPIO.HIGH) logging.info("{0}Power on".format(log_time))

And then your PHP script

<?php

$command = escapeshellcmd('/home/pi/Code/App/power_on.py'); $output = shell_exec($command); echo $output;

?>

JJandke
  • 101
  • 1
  • 6