Skip to content

Commit

Permalink
adding 32 and 64 version separately
Browse files Browse the repository at this point in the history
  • Loading branch information
JAlcocerT committed Jan 6, 2024
1 parent e898491 commit 40b23ee
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#docker-compose -f ./RPi/Z_IoT/DHT-to-MongoDB/Ansible_py_dht_mongo_meta.yml up -d
#docker-compose -f ./Ansible_py_dht_mongo_meta.yml up -d
#docker-compose -f ./RPi/Z_IoT/DHT-to-MongoDB/Ansible_py_dht_mongo_arm32.yml up -d
#docker-compose -f ./Ansible_py_dht_mongo_arm32.yml up -d

version: '3'
services:
mongodb:
image: apcheamitru/arm32v7-mongo #mongo:latest #apcheamitru/arm32v7-mongo
image: apcheamitru/arm32v7-mongo #mongo:latest
container_name: mongodb
environment:
MONGO_INITDB_ROOT_USERNAME: yourusername
Expand Down Expand Up @@ -34,27 +34,10 @@ services:
MONGO_DB_NAME: sensor_data # Specify the MongoDB database name
MONGO_COLLECTION_NAME: dht_sensor # Specify the MongoDB collection name
DHT_SENSOR_TYPE: DHT22 # Set the DHT sensor type here (DHT11 or DHT22)
DHT_PIN: 4 # Set the DHT sensor pin here
#DHT_PIN: 4 # Set the DHT sensor pin here
privileged: true
#command: python3 /app/Python2MongoDB.py
command: tail -f /dev/null #keep it running


# dht_sensor_mongo:
# image: dht_sensor_mongo:latest # Use the name of your custom image
# container_name: dht_sensor_mongo
# privileged: true
# depends_on:
# - mongodb
# environment:
# MONGODB_HOST: mongodb
# MONGODB_PORT: 27017 # Specify the MongoDB port
# MONGO_INITDB_ROOT_USERNAME: yourusername # Specify the MongoDB root username
# MONGO_INITDB_ROOT_PASSWORD: yourpassword # Specify the MongoDB root password
# MONGO_DB_NAME: sensor_data # Specify the MongoDB database name
# MONGO_COLLECTION_NAME: dht_sensor # Specify the MongoDB collection name
# DHT_SENSOR_TYPE: DHT22 # Set the DHT sensor type here (DHT11 or DHT22)
# DHT_PIN: 4 # Set the DHT sensor pin here
command: python3 PyToMongoDB.py
#command: tail -f /dev/null #keep it running

volumes:
mongodb_data:
43 changes: 43 additions & 0 deletions Z_IoT/DHT-to-MongoDB/Ansible_py_dht_mongo_arm64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#docker-compose -f ./RPi/Z_IoT/DHT-to-MongoDB/Ansible_py_dht_mongo_arm64.yml up -d
#docker-compose -f ./Ansible_py_dht_mongo_arm64.yml up -d

version: '3'
services:
mongodb:
image: mongo:latest #apcheamitru/arm32v7-mongo
container_name: mongodb
environment:
MONGO_INITDB_ROOT_USERNAME: yourusername
MONGO_INITDB_ROOT_PASSWORD: yourpassword
MONGO_INITDB_DATABASE: sensor_data
volumes:
- mongodb_data:/data/db
ports:
- "27017:27017"
restart: always


dht_sensor_mongo:
build:
context: . #./Python2MongoDB.py #./path/to/your/python/code
dockerfile: Dockerfile
container_name: dht_sensor_mongo
depends_on:
- mongodb
# networks:
# - mynetwork
environment:
MONGODB_HOST: mongodb
MONGODB_PORT: 27017 # Specify the MongoDB port
MONGO_INITDB_ROOT_USERNAME: yourusername # Specify the MongoDB root username
MONGO_INITDB_ROOT_PASSWORD: yourpassword # Specify the MongoDB root password
MONGO_DB_NAME: sensor_data # Specify the MongoDB database name
MONGO_COLLECTION_NAME: dht_sensor # Specify the MongoDB collection name
DHT_SENSOR_TYPE: DHT22 # Set the DHT sensor type here (DHT11 or DHT22)
#DHT_PIN: 4 # Set the DHT sensor pin here
privileged: true
command: python3 PyToMongoDB.py
#command: tail -f /dev/null #keep it running

volumes:
mongodb_data:
6 changes: 3 additions & 3 deletions Z_IoT/DHT-to-MongoDB/PyToMongoDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pymongo import MongoClient

# Get the DHT sensor type from environment variable
dht_sensor_type = os.environ.get('DHT_SENSOR_TYPE', 'DHT11')
dht_sensor_type = os.environ.get('DHT_SENSOR_TYPE', 'DHT22')

# Initialize the DHT sensor
if dht_sensor_type == 'DHT11':
Expand All @@ -14,7 +14,7 @@
dhtDevice = adafruit_dht.DHT22(board.D4, use_pulseio=False)
else:
print(f"Invalid DHT sensor type '{dht_sensor_type}'. Defaulting to DHT11.")
dhtDevice = adafruit_dht.DHT11(board.D4, use_pulseio=False)
dhtDevice = adafruit_dht.DHT22(board.D4, use_pulseio=False)

# Configure MongoDB connection parameters
mongo_host = os.environ.get('MONGODB_HOST', 'localhost') # Default to 'localhost' if not set
Expand Down Expand Up @@ -64,4 +64,4 @@
dhtDevice.exit()
raise error

time.sleep(2.0)
time.sleep(2.0)
6 changes: 4 additions & 2 deletions _posts/2024-01-04-rpi-ansible.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ So you want to have the project that pulls data from DHT11 or DHT22, sends it fr
No issues, just execute:

```sh
ansible-playbook ./RPi/Z_ansible/Ansible_py_dht_mongo_meta.yml -i inventory.ini #execute Meta Project Playbook
ansible-playbook ./RPi/Z_ansible/Ansible_py_dht_mongo_arm32.yml -i inventory.ini #execute Meta Project Playbook
#ansible-playbook ./RPi/Z_ansible/Ansible_py_dht_mongo_arm64.yml -i inventory.ini #execute Meta Project Playbook

#docker-compose -f ./RPi/Z_IoT/DHT-to-MongoDB/Ansible_py_dht_mongo_meta.yml up -d # Basically it spins up Docker and This Stack

#docker-compose -f ./RPi/Z_IoT/DHT-to-MongoDB/Ansible_py_dht_mongo_arm64.yml up -d # Basically it spins up Docker and This Stack
```


Expand Down

0 comments on commit 40b23ee

Please sign in to comment.