I am running an apache server from a Raspberry Pi and have a python script that returns sensor input by printing it. This properly prints it to the console. Currently I have a php script that gets this output and shuts off a light if the sensor is reading is high, before printing it again. This also works when run from the console. The last part is javascript that is supposed to get the output from the php. It does that using ajax, which runs the "success" function, but gets "0" from the php script.
My php script:
<?php
exec ("python temp.py", $temp);
if((float)$temp[0]>28)
{
exec("gpio read 0",$state);
if($state[0]=="1")
{
include('gpio.php');
echo("Overheated: ".$temp[0]);
}
}
else
{
echo($temp[0]);
}
?>
My js:
$.ajax(
{
type: "GET",
url: "temp.php",
dataType: "text",
success: function(msg)
{
alert("asd"+typeof msg);
document.getElementById('text').innerHTML = msg;
return msg;
},
error: function(jqXHR, textStatus, errorThrown){
alert(jqXHR.responseText);
}
});
Any suggestions are greatly appreciated. Thank you.