1

I have a Python3 script (readtemp.py) to read temperature and humidity of a DHT22. I'm using adafruit_dht module. it executes perfectly from terminal command line with:

    python3 readtemp.py

or

    ./readtemp.py

At the head of the Python script I have:

    #!/usr/bin/python3
    import time
    import board
    import adafruit_dht

I put a line in Apache PHP:

$output = exec("python3 ./readtemp.py");

or

$output = exec("./readtemp.py");

or

$output = shell_exec("python3 ./readtemp.py");

or

$output = shell_exec("./readtemp.py");

and all work but when the page loads the Python script is executed but the import gets an error. In apache error.log:

Traceback (most recent call last):
  File "./readtemp.py", line 4, in <module>
    import adafruit_dht
ModuleNotFoundError: No module named 'adafruit_dht'

It looks like apache isn't letting python load an external module. Any ideas to get apache to allow python access the exeternal modules?

SailorBoy
  • 11
  • 3

1 Answers1

1

If you search this Forum you will find MANY questions about DHT22.

The Adafruit code is notoriously unreliable and CAN NOT be run from PHP because it requires root access.

See Reliable temperature/humidity logging with Python and a DHT11 for the code I use.

Milliways
  • 59,890
  • 31
  • 101
  • 209