📜 ⬆️ ⬇️

Raspberry Pi GPIO Web Control

Good day! In this post I want to show how to manage electronics over the Internet using Raspberry Pi. It will look something like this.



Short description :

')


Step 1. Knowledge base



This should already be on your Raspberry Pi:


If you want to know how to set it all up, go here (instructions in English).

Step 2. Creating a root account



Skip this if you already have an account, and if not, continue reading :)

Log into the Raspberry Pi using the following command:
sudo -i
passwd root

Now enter and confirm the password for the account.
Then you need to close the SSH session and restart it by logging in as root.



Step 3. Setting up databases and phpMyAdmin



This solution is based on MySQL databases, and now we will configure them.

So, first download this file .

Login to the phpMyAdmin control panel and click " Import " in the top menu.
Now, in the " File to Import " item, click the " Choose File " button and select the file you downloaded before (gpio.sql).
Finally click on the " Go " button at the bottom of the page.
This will create all the necessary tables.




Now you need to add a new user to the database using phpMyAdmin. In order to do this, you should:




In the final part of this step, you need to give the user the necessary privileges.






Step 4. Shell Script



This is the part that starts checking the values ​​in the MySQL database on the Raspberry Pi.
This script is quite simple, but requires configuration.

First download the script by entering the following commands (on Raspberry Pi):


After it downloads, enter

This will allow you to change the script.



You must change the following variables at the beginning of the file:

They need to be changed to the username and password you created earlier in phpMyAdmin.



After you have changed everything, hold down the Ctrl key and press X , then release Ctrl and hit Y. Press Return / Enter.

Step 5. Setting up a web page



The final step, before you can use it, is setting up a web page.

To do this, write the following commands, making sure that you are logged in (if not, type sudo -i ) .:




When they download, write this:




Now you need to change a couple of variables before using the file, so type nano /var/www/control.php and press Return / Enter.

Modify the following variables:




Now go to the control.php page via the browser (I have raspberryPi / control.php , where raspberryPi is the host name.)

There you will need to enter the following data:
Username: admin
Password: gpio



I recommend clicking on the “Change Password” link at the top of the page and changing the password for obvious reasons.




Step 6. Using



To run GPIO programs, do the following:
Start an SSH session on the Raspberry Pi and ./GPIOServer.sh in as root, then type ./GPIOServer.sh and press Return / Enter.

He will ask you to enter a wait time, it will depend on the needs of your applications. But, the shorter the wait time, the more resources the script will use (I usually use 5).



Done! Now go to the control panel (http: // HOST NAME / control.php) and enjoy!

For security, you must delete the root account.

Source: https://habr.com/ru/post/162651/


All Articles