php - How to get a float from python to JavaScript without cgi -


i running apache server raspberry pi , have python script returns sensor input printing it. prints console. have php script gets output , shuts off light if sensor reading high, before printing again. works when run console. last part javascript supposed output php. using ajax, runs "success" function, gets "0" 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 appreciated. thank you.

right. it's user permission issues, because output running script under user terminal. , browser, running under server's user, returns empty string.

check www-data (or whatever) permissions when running script server. set error reporting , run:

ini_set('display_errors', true); error_reporting(e_all);  echo exec('whoami'); 

if prints out user not sudoer, set correct permissions allow .py script execution user.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -