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.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
home/pi
var/www
4_array_relay.jpg
README.md
basic.jpg
interface.JPG

README.md

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: 192.168.1.93/index.html).

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:

$(document).ready(function(){
$.ajax({
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");
  }else{
    $("#feedback"+(i+1)).html("Turned Off");
  }
  $("[name='relay"+(i+1)+"']").bootstrapSwitch('state',msg[i]);
} 
});
});

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

exec("sudo python /home/pi/firstCheck.py " ,$output);
echo json_encode($output); 

firstCheck.py 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() relay_on.py or relay_off.py with relay id depend on the state value.

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