Ludaris
Posts: 1
Joined: Mon May 28, 2018 1:27 am

DHT22 readings onto a web page

Mon May 28, 2018 1:31 am

Hello,

I am currently facing a problem.
Namely I have the following sensor (DHT22) properly connected to the Raspberry Pi and also installed all the necessary packages.
In the terminal I can already show values ​​via the existing test file (AdafruitDHT.py).

Now I want to show these values ​​on my website. For this I have programmed the following Python script:

Code: Select all

import Adafruit_DHT
sensor = Adafruit_DHT.DHT22
pin = 4
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
if humidity is not None and temperature is not None:
   print 'Temp:{0:0.1f}*C  Humidity:{1:0.1f}%'.format(temperature, humidity)
else:
   print 'Failed to obtain a reading. Try again!
And matching the PHP program:

Code: Select all

<?php
$output = shell_exec("python /var/www/html/python/temperatur.py 22 4"); 
var_dump ($output);
?>
Unfortunately I can not see anything on my website.
Do you have any ideas why it could be or how I could get it to work?
I also tried and did everything like here: viewtopic.php?t=92629

Thanks in advance.


Best regards

~ Ludaris

MrWhite_2018
Posts: 6
Joined: Thu May 31, 2018 11:23 am

Re: DHT22 readings onto a web page

Thu May 31, 2018 6:03 pm

The php code you have, where is it written? Seperate php file or within your index.php (or whatever root document you are serving)?
Are you looking to show the data on the main page, or after a button click?

Also you should add

Code: Select all

echo var_dump ($output);
to send it to the page.

Return to “Python”

Who is online

Users browsing this forum: No registered users and 14 guests