Right now I am programming a Raspberry Pi robot with wheels for a personal project. I want to control it through an Apache website which is running on the Raspberry. I only want to connect to it locally.
Last night i have done the buttons to control the wheels from the robot. I tried to execute the files which are needed to start the motors through PHP but soon learned that the site always switches, which i dont want it to do, when i just use a submit button in a <form></form>. So i went on the internet and found something about ajax.
Since all buttons are not working, i will just give you an example of one button from my code. They all work the same, they just have different names, directorys and call a different function. All functions are in the same Javascript.
HTML:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="../javascript/pfeile/pfeile.js"></script>
<div class="pfeilvorne" id="submitvorne" style="background-color: transparent;" onClick="vorne()"></div>
Javascript:
function vorne() {
$.ajax({
url:"../../php/Pfeile/vorne.php", //the page containing php script
type: "POST", //request type
url:"../../php/Pfeile/php.php", //the page containing php script
});
}
PHP:
<?php
exec("sudo killall vorne.bin");
exec("sudo killall hinten.bin");
exec("sudo killall links.bin");
exec("sudo killall rechts.bin");
exec("sudo killall kreis.bin");
exec("sudo /home/pi/Maxwheel/Scripte/Vorne/sketch_apr13a/vorne.bin");
?>
I tested the scripts using sudo ./[Scriptname] in an ssh console and they are working. The buttons also work when i solely use php (But only using php still changes the site....)
I hope you can help me, thank you!