1
I am doing a small project with a rRspBerry Pi 3 that consists, among other things, to control some outputs through a web page. I needed to be able to know and print on the page what the status of those exits was at a given moment. I have, for example, a button to turn on an LED and another button to turn off, but I need to print on a text box if the LED is on or off and leave or not on or off the LED depending on its status.
To read the status I can use the function exec("gpio read ".$i, $status);
in which $i
is the pin I want to read and $status
is where you keep the pin status, but I don’t know how to include it on my web page, someone knows how to do it or knows where to look for an example?
Code:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<article>
<div id="Janelas">
<h1>Sistemas de Climatização</h1>
<p>Soalho radiante</p>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">// <![CDATA[
$(document).ready(function() {
$('#ligar').click(function(){
var a= new XMLHttpRequest();
a.open("GET", "soalholigar.php"); a.onreadystatechange=function(){
if(a.readyState==4){ if(a.status ==200){
} else alert ("http error"); } }
a.send();
});
});
$(document).ready(function() {
$('#desligar').click(function(){
var a= new XMLHttpRequest();
a.open("GET", "soalhodesligar.php"); a.onreadystatechange=function(){
if(a.readyState==4){ if(a.status ==200){
} else alert ("http error"); } }
a.send();
});
});
</script>
<input type="button" id="ligar" value="Ligar">
<input type="button" id="desligar" value="Desligar">
<center>
<input type="text" size="5" name="textgol" value="0">
</center>
<p>ZONA 2.</p>
<input type="button" name="botao-ligar" value="Ligar">
<input type="button" name="botao-desligar" value="Desligar">
<p>ZONA 3.</p>
<input type="button" name="botao-ligar" value="Ligar">
<input type="button" name="botao-desligar" value="Desligar">
<p>ZONA 4.</p>
<input type="button" name="botao-ligar" value="Ligar">
<input type="button" name="botao-desligar" value="Desligar">
<br/>
<br/>
<a href="javascript:window.history.go(-1)">Voltar</a>
</body>
</html>
1) If you are using jQuery, why not make asynchronous calls via
$.ajax
? 2) The state of the LED can be changed through other sources or the interface will be the only one to control it? 3) What is the return, in the terminal, when you execute the commandgpio
directly?– Woss
– Tiago Meireles
About the return of command, I was referring to
gpio read
, to know how to treat the response.– Woss
if gpio read directly on terminal returns 0 or 1, depending on pin state.
– Tiago Meireles