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
8 changed files with 30 additions and 32 deletions
Showing only changes of commit b36b1b3c90 - Show all commits

View File

@ -24,8 +24,7 @@ class DeviceInfo:
}
]
# 'pump_pin_int': 24
read_secs = 60
# Device Infos End
wlan = network.WLAN(network.STA_IF)

View File

@ -1,15 +1,16 @@
from sensors import Sensors
from dht import DHT22
from machine import ADC, Pin
class TemperatureHumiditySensor:
sensor_pin_int = -1
class TemperatureHumiditySensor(Sensors):
sensor = None
most_recent_values = []
def __init__(self, settings):
super().__init__(settings)
print("Initialize dht22 sensor. Sensor pin is: " + str(settings['pin_int']))
print(settings)
self.sensor_pin_int = settings['pin_int']

View File

@ -25,6 +25,7 @@ class GrowSystem:
def __init__(self, settings):
for sensor in self.device_info.sensors:
print("")
print("Initialize sensor:")
print(sensor)
sensor_type = sensor['type']
@ -61,19 +62,13 @@ class GrowSystem:
self.most_recent_values = []
for sensor in self.sensors:
print("Read sensor of type " + sensor.type + " at pin " + str(sensor.sensor_pin_int))
sensor.read()
for measurement in sensor.most_recent_values:
print(f"Got {measurement['value']} {measurement['unit']} ({measurement['type']})")
self.most_recent_values = self.most_recent_values + sensor.most_recent_values
print("Most recent bla")
print(sensor.most_recent_values)
# Moisture Sensor
# self.moisture_sensor.read()
# self.most_recent_values = self.most_recent_values + self.moisture_sensor.most_recent_value
# Temperature and Humidity Sensor
# self.temperature_humidity_sensor.read()
# self.most_recent_values = self.most_recent_values + self.temperature_humidity_sensor.most_recent_values
self.sensor_data_manager.handleData(self.most_recent_values)
time.sleep(5)
time.sleep(self.device_info.read_secs)

View File

@ -15,8 +15,7 @@ class GrowSystemApi:
self.base_url = self.device_info.server_url
def say_hello(self):
data = self._get_device_data()
response = self.http_client.post(self.base_url + "/api/device", data)
response = self.http_client.post(self.base_url + "/api/device", self._get_device_data())
print(response.text)
jsonResult = json.loads(response.text)
print(jsonResult)
@ -24,7 +23,6 @@ class GrowSystemApi:
def send_measurements(self, device_id, data):
url = self.base_url + "/api/device/" + str(device_id) + "/sensor-log"
print(url)
response = self.http_client.post(url, data)
return json.loads(response.text)

View File

@ -44,13 +44,11 @@ if __name__ == '__main__':
print("Connect WLAN")
wlanClient = WlanClient(settings['wlan_ssid'], settings['wlan_pw'])
wlanClient.connect()
print("---------------------------------------")
print("")
di = DeviceInfo()
print("Device Infos:")
print(di.get_all_device_infos())
print("---------------------------------------")
print("")
print("Start grow system")

View File

@ -1,9 +1,9 @@
# Moisture Sensor Class
from sensors import Sensors
from machine import ADC, Pin
class MoistureSensor:
sensor_pin_int = -1
class MoistureSensor(Sensors):
sensor = None
@ -13,6 +13,7 @@ class MoistureSensor:
max_raw_value = None
def __init__(self, sensor_data, min_raw_value=300, max_raw_value=65535):
super().__init__(sensor_data)
print("Initialize moisture sensor. Sensor pin is: " + str(sensor_data['pin_int']))
self.sensor_pin_int = sensor_data['pin_int']
self.min_raw_value = min_raw_value

View File

@ -17,5 +17,4 @@ class SensorDataManager:
def handleData(self, data):
jsonResponse = self.grow_system_api.send_measurements(self.device_id, data)
print("---- Response: -----")
print(jsonResponse)
print("Response message: " + jsonResponse['message'])

View File

@ -1,3 +1,10 @@
class Sensors:
# this is a parent class for the Sensor classes
sensor_pin_int = -1
type = "unset"
def __init__(self, settings):
self.type = settings['type']