In this section, we will look ar how to control our camera from a web page in PHP and run a web server in the Raspberry Pi. We will need the following to run PHP files and web server:
For the web page, for controlling we will have to create our PHP files in the following path: /var/www/html
, for instance we need to edit the index.php
file, and copy the following lines.
The following HTML file includes PHP:
<!DOCTYPE html> <html> <head> <title>Control Camera</title> </head> <body>
Here we define the function to perform action for taking the picture:
<form action="on.php"> <button type="submit">Taking the picture</button> </form>
Here we define the action to taken if motion detected:
<form action="off.php"> <button type="submit">Motion</button> </form> </body> </html>
In this section, we need to call the Python script from the web page and execute the file that has the script:
<?php $prende= exec('sudo python on.py'), header('Location:index.php'), ?> <?php $apaga = exec('sudo python motion.py'), header('Location:index.php'), ?>
On the server side, that is the Raspberry Pi, we have the Python scripts that will be called from the web page:
import serial import time Arduino_1 = serial.Serial('/dev/ttyACM0',9600) Arduino_1.open() Command='H' if command: Arduino_1.write(command) Arduino_1.close() import serial import time Arduino_1 = serial.Serial('/dev/ttyACM0',9600) Arduino_1.open() Command='L' if command: Arduino_1.write(command) Arduino_1.close()
If everything is configured perfectly, the following page will appear: in your favorite browser, type IP address of your PI/index.php
:
18.225.98.18