Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

PiRelay Donate

Web app for controlling 4 Array Relay module with Raspberry Pi . For the project are used :

  • PHP
  • Python
  • HTML
  • Javascript
  • Jquery
  • Bootstrap
  • Bootstrap Switch

User Interface

Easy,modern and simple :

Interface image

##Required PHP and Apache server installed on the Raspberry . ##Installation You need to download the files and copy them with Filezilla to the main dir of Raspberry home/pi and to the var/www. For pasting the files into var/www you need to set a permision .

##Documentation So the basic idea is that we have index.html which is the main file . In it there are included some bootstrap-switch .css and .js files to make the buttons look better . There is Jquery so that we can use ajax post request to get or send data to the php . The php itself execute a python script.The python script returns values to the php and the php send the values to the html . This is done for having a feedback from the device . So here is a schema of the conception : Schema image

To load index.html you need to type YourPaspberryIp/index.html in your browser (example:

When the html laods, first we check the previous position of the relays or if we load the page for first time the relays will turn on:

method: "POST",
url: "firstCheck.php",
data: {}
.done(function( msg ) {
msg = JSON.parse(msg);
msg = JSON.parse(msg);
for(var i = 0 ; i < 4; i++){
  if(msg[i] == true){
    $("#feedback"+(i+1)).html("Turned On");
    $("#feedback"+(i+1)).html("Turned Off");

The php file execute and returns json output from the execution .

exec("sudo python /home/pi/ " ,$output);
echo json_encode($output); loops through all GPIO pins that we use and checks if they are turn on or off. The results are added to arr[] list and encoded to json :

print json.dumps({0:arr[0],1:arr[1],2:arr[2],3:arr[3]})

For the buttons we make an onclick EventListener , so when the button is clicked we make a ajax post request calling the changeState.php and sending the state and id of the relay , which we want to activate.The php file exec() or with relay id depend on the state value.

exec("sudo python /home/pi/ " . $_POST['relayId']);
exec("sudo python /home/pi/ " . $_POST['relayId']);
You can’t perform that action at this time.