Skip to content

Commit

Permalink
missing GPIO inside the container
Browse files Browse the repository at this point in the history
  • Loading branch information
JAlcocerT committed Jan 6, 2024
1 parent bf3b605 commit 0b95867
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
6 changes: 4 additions & 2 deletions Z_IoT/DHT-to-MongoDB/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ COPY PyToMongoDB.py /app/
#### to work with RPI 32bits / for 64 use the latest ~4.5.0
RUN pip install pymongo==3.6.0

RUN pip3 install RPi.GPIO

RUN pip3 install adafruit-circuitpython-dht==4.0.4
RUN pip3 install board==1.0



#RUN pip3 install --install-option="--force-pi" Adafruit_DHT
#RUN pip install Adafruit_DHT==1.4.0 #not working

Expand All @@ -32,8 +35,7 @@ RUN pip3 install board==1.0
#WORKDIR Adafruit_Python_DHT
#RUN python3 setup.py install --force-pi


WORKDIR /app
#WORKDIR /app

# Run the Python script
CMD ["python", "Python2MongoDB.py"]
38 changes: 38 additions & 0 deletions Z_IoT/DHT-to-MongoDB/python_dht_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
#https://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging/python-setup

import time
import board
import adafruit_dht

# Initial the dht device, with data pin connected to:
dhtDevice = adafruit_dht.DHT22(board.D18)

# you can pass DHT22 use_pulseio=False if you wouldn't like to use pulseio.
# This may be necessary on a Linux single board computer like the Raspberry Pi,
# but it will not work in CircuitPython.
# dhtDevice = adafruit_dht.DHT22(board.D18, use_pulseio=False)

while True:
try:
# Print the values to the serial port
temperature_c = dhtDevice.temperature
temperature_f = temperature_c * (9 / 5) + 32
humidity = dhtDevice.humidity
print(
"Temp: {:.1f} F / {:.1f} C Humidity: {}% ".format(
temperature_f, temperature_c, humidity
)
)

except RuntimeError as error:
# Errors happen fairly often, DHT's are hard to read, just keep going
print(error.args[0])
time.sleep(2.0)
continue
except Exception as error:
dhtDevice.exit()
raise error

time.sleep(2.0)
10 changes: 3 additions & 7 deletions _posts/2023-10-20-rpi-iot-dht1122-mongo.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,10 @@ Mongo Express allows us to interact with MongoDB database through the browser.



> More About [Adafruit_DHT](https://pypi.org/project/Adafruit-DHT/#description) and in [Github](https://github.com/adafruit/Adafruit_Python_DHT). Replaced with [Adafruit_CircuitPython_DHT](https://github.com/adafruit/Adafruit_CircuitPython_DHT).
> More About [Adafruit_DHT](https://pypi.org/project/Adafruit-DHT/#description) and in [Github](https://github.com/adafruit/Adafruit_Python_DHT). **Replaced with** [Adafruit_CircuitPython_DHT](https://github.com/adafruit/Adafruit_CircuitPython_DHT).
{: .prompt-info }

If you are getting problems to install Adafuit_DHT, you can try to do it from source:
If you are getting problems to install the old Adafuit_DHT, you can try to do it from source:


```sh
Expand All @@ -438,12 +438,8 @@ python3 setup.py install --force-pi
#This will bypass any issues you may encounter when doing pip install Adafuit_DHT==1.4.0
```

See that it works with:
Generally, you should just switch to the [Adafruit DHT Circuit Python](https://docs.circuitpython.org/projects/dht/en/latest/examples.html)

```sh
export DHT_SENSOR_TYPE=DHT22 # Replace 'DHT22' with your desired sensor type
python3 Python2MongoDB.py
```

#### Testing pymongo

Expand Down

0 comments on commit 0b95867

Please sign in to comment.