returning value from python to php
Posted: Thu Nov 24, 2016 1:22 pm
Hi,
I have a python code which gives me the temperature and humidity using DHT11. I have attached the code of the python script below
I have the PHP code as
when i run the PHP i get the below out put as
array(0) { } My Farm out Array ret 1
Can you please help me what i have done wrong.
I have a python code which gives me the temperature and humidity using DHT11. I have attached the code of the python script below
Code: Select all
import Adafruit_DHT as dht
import sys
h,t = dht.read_retry(dht.DHT11,4)
print 'Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(t, h)
temp = 'Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(t, h)
print temp
Code: Select all
<?php
//$command = escapeshellcmd('python nattemp.py');
//$output = shell_exec($command);
exec('sudo python /home/pi/natsample/nattemp.py',$output,$retval);
echo "<prev>";
var_dump($output);
print_r("My Farm");
print_r(" out ".$output);
print_r(" ret ".$retval);
echo "</prev>";
?>
array(0) { } My Farm out Array ret 1
Can you please help me what i have done wrong.