So I'm wondering, I found a script online that outputs the temperature of the raspberry pi every 2 seconds:
import os
import time
def measure_temp():
temp = os.popen("vcgencmd measure_temp").readline()
return (temp.replace("temp=",""))
while True:
print(measure_temp())
time.sleep(1)
I've also created a server and site using the standard apache method. In /var/www/html I have a file called 'phptest.php' that will makeup the site and I have a python file called 'monitor-temp.py' which contains the above code for outputting the temp.
My question is, how do I successfully add the python code to the php file and hence display the temperature on the site?
Can I literally just type out the python code into the php file using nano phptest.php? Or do I the php file to somehow access the python file.
I see a lot of guides saying to add this to the php file to execute the python code:
<?php
$command = escapeshellcmd('/usr/custom/test.py');
$output = shell_exec($command);
echo $output;
?>
but that doesn't do anything for me. Thank you in advance!