I tried to read my DS18B20 sensor temperature with my raspberry pi adresse, I wrote this code in /var/www/html/index.php
<?php
// Fichier à lire
$file = "/sys/bus/w1/devices/28-80000026ddb1/w1_slave";
// Lecture ligne par ligne
$lines = file($file);
// Recupere la 2nd ligne
$temp = explode(’=’, $lines[1]);
// Formatage de la temperature
$temp = number_format($temp[1]/1000,2, ’.’, ’’);
// On affiche la temperature
echo $temp;echo" degrés Celius";
?>
What’s wrong with it? It shows me the following:
2
Answers
You are seeing the root page of your webserver. Your PHP code is not in the root page, you need to browse to the page index.php .
Hit in the browser bar the url that show Apache2 Debian Default Page, followed by:
instead of
For example:
If the apache configuration file is the default one, should not require other settings to browse your page. Further configurations are possible to change the root page to yours. See about this: How do I change the default index page in Apache?
Yes, PHP should be installed in order to run PHP code.
You need to install PHP, link it to your apache installation, then tell apache that the root page is “index.php” instead that “index.html” so that when you request “/” it can execute the index.php script.
1- install PHP engine, for example as apache SAPI module:
2- put this one inside your virtualhost or in your /etc/apache2/apache2.conf file:
3- restart apache
You should now be able to execute PHP code with apache httpd