feature/change_sensor_handling #1

Merged
moltox merged 9 commits from feature/change_sensor_handling into main 2024-04-27 21:38:03 +00:00
3 changed files with 46 additions and 1 deletions
Showing only changes of commit c8f4baf984 - Show all commits

32
dht22.py Normal file
View File

@ -0,0 +1,32 @@
from dht import DHT22
from machine import ADC, Pin
class TemperatureHumiditySensor:
dht22_sensor_pin_int = -1
dht22_sensor = None
most_recent_values = {}
def __init__(self, settings):
print("Hello from dht22 sensor class")
print(settings)
self.dht22_sensor_pin_int = settings['pin_int']
self.dht22_sensor = DHT22(Pin(self.dht22_sensor_pin_int, Pin.IN, Pin.PULL_UP))
def read(self):
try:
self.dht22_sensor.measure()
self.most_recent_values = {
'temperature': {
'value': self.dht22_sensor.temperature(),
'unit': '°C'},
'humidity': {
'value': self.dht22_sensor.humidity(),
'unit': '%'
}
}
except OSError:
print('DHT22 Error reading temperature/humidity. Check wires')
print()

View File

@ -1,10 +1,12 @@
import time import time
from moisture_sensor import MoistureSensor from moisture_sensor import MoistureSensor
from dht22 import TemperatureHumiditySensor
class GrowSystem: class GrowSystem:
moisture_sensor = None moisture_sensor = None
temperature_humidity_sensor = None
most_recent_values = {} most_recent_values = {}
@ -14,11 +16,20 @@ class GrowSystem:
if not self.moisture_sensor: if not self.moisture_sensor:
self.moisture_sensor = MoistureSensor(settings['moisture_sensor']) self.moisture_sensor = MoistureSensor(settings['moisture_sensor'])
if not self.temperature_humidity_sensor:
self.temperature_humidity_sensor = TemperatureHumiditySensor(settings['temperature_humidity_sensor'])
def start(self): def start(self):
print("Start reading sensors ...") print("Start reading sensors ...")
while True: while True:
# Moisture Sensor
self.moisture_sensor.read() self.moisture_sensor.read()
self.most_recent_values['moisture_sensor'] = self.moisture_sensor.most_recent_value self.most_recent_values['moisture_sensor'] = self.moisture_sensor.most_recent_value
# Temperature and Humidity Sensor
self.temperature_humidity_sensor.read()
self.most_recent_values['temperature_humidity_sensor'] = self.temperature_humidity_sensor.most_recent_values
print(self.most_recent_values) print(self.most_recent_values)
time.sleep(1) time.sleep(1)

View File

@ -11,10 +11,12 @@ from grow_system import GrowSystem
settings = { settings = {
'wlan_ssid': 'Oppa-95.lan', 'wlan_ssid': 'Oppa-95.lan',
'wlan_pw': '95%04-MM', 'wlan_pw': '95%04-MM',
'led_pin_int': 15,
'moisture_sensor': { 'moisture_sensor': {
'pin_int': 26 'pin_int': 26
}, },
'temperature_humidity_sensor': {
'pin_int': 15
},
'pump_pin_int': 24 'pump_pin_int': 24
} }