Web is something that will always have the complete answer, if using a sleep
you will have problems, headaches, especially if you have session_start
, understand that I am not saying that Sleep is bad, I am just saying that the use of the proposed way in the other answers is not ideal.
I believe the best is to use Ajax and popular a DIV, for example:
foo/temperature.php
<?php
function retornaTemperatura()
{
// Local do arquivo python
$comando = escapeshellcmd('temperatura.py');
// retorna o valor do py para exibir ou mandar para um banco de dados
return shell_exec($comando);
}
echo retornaTemperatura();
And on your page call something like that:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div id="temperatura"></div>
<script type="text/javascript">
function temperatura()
{
var el = document.getElementById("temperatura");
var segundos = 2; //2 segundos de espera
var oReq = new XMLHttpRequest();
//Defina como true
oReq.open("GET", "/foo/temperatura.php", true);
//Função assíncrona que aguarda a resposta
oReq.onreadystatechange = function()
{
if (oReq.readyState == 4) {
if (oReq.status == 200) {
el.innerHTML = oReq.responseText;
}
setTimeout(temperatura, segundos * 1000);
}
};
//Envia a requisição, mas a resposta fica sendo aguardada em Background
oReq.send(null);
}
</script>
</body>
</html>
"Display onscreen updated information". Will you do this via command line or browser? You did not detail this in the question. They are two different paths.
– Wallace Maxters
I want to display in the browser
– André Luis Moreira
Creates a cron task every 2 seconds on the server to run your script.
– Ivan Ferrer
It could do the opposite where Adian itself sends the information instead of always checking the device every second. The "wear and tear" is less. But as this is not what you asked, I will avoid answering.
– Daniel Omine