feature/change_sensor_handling #1
|
|
@ -24,8 +24,7 @@ class DeviceInfo:
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
# 'pump_pin_int': 24
|
read_secs = 60
|
||||||
|
|
||||||
# Device Infos End
|
# Device Infos End
|
||||||
|
|
||||||
wlan = network.WLAN(network.STA_IF)
|
wlan = network.WLAN(network.STA_IF)
|
||||||
|
|
|
||||||
5
dht22.py
5
dht22.py
|
|
@ -1,15 +1,16 @@
|
||||||
|
from sensors import Sensors
|
||||||
from dht import DHT22
|
from dht import DHT22
|
||||||
from machine import ADC, Pin
|
from machine import ADC, Pin
|
||||||
|
|
||||||
|
|
||||||
class TemperatureHumiditySensor:
|
class TemperatureHumiditySensor(Sensors):
|
||||||
sensor_pin_int = -1
|
|
||||||
|
|
||||||
sensor = None
|
sensor = None
|
||||||
|
|
||||||
most_recent_values = []
|
most_recent_values = []
|
||||||
|
|
||||||
def __init__(self, settings):
|
def __init__(self, settings):
|
||||||
|
super().__init__(settings)
|
||||||
print("Initialize dht22 sensor. Sensor pin is: " + str(settings['pin_int']))
|
print("Initialize dht22 sensor. Sensor pin is: " + str(settings['pin_int']))
|
||||||
print(settings)
|
print(settings)
|
||||||
self.sensor_pin_int = settings['pin_int']
|
self.sensor_pin_int = settings['pin_int']
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ class GrowSystem:
|
||||||
|
|
||||||
def __init__(self, settings):
|
def __init__(self, settings):
|
||||||
for sensor in self.device_info.sensors:
|
for sensor in self.device_info.sensors:
|
||||||
|
print("")
|
||||||
print("Initialize sensor:")
|
print("Initialize sensor:")
|
||||||
print(sensor)
|
print(sensor)
|
||||||
sensor_type = sensor['type']
|
sensor_type = sensor['type']
|
||||||
|
|
@ -61,19 +62,13 @@ class GrowSystem:
|
||||||
self.most_recent_values = []
|
self.most_recent_values = []
|
||||||
|
|
||||||
for sensor in self.sensors:
|
for sensor in self.sensors:
|
||||||
|
print("Read sensor of type " + sensor.type + " at pin " + str(sensor.sensor_pin_int))
|
||||||
sensor.read()
|
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
|
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)
|
self.sensor_data_manager.handleData(self.most_recent_values)
|
||||||
|
|
||||||
time.sleep(5)
|
time.sleep(self.device_info.read_secs)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,7 @@ class GrowSystemApi:
|
||||||
self.base_url = self.device_info.server_url
|
self.base_url = self.device_info.server_url
|
||||||
|
|
||||||
def say_hello(self):
|
def say_hello(self):
|
||||||
data = self._get_device_data()
|
response = self.http_client.post(self.base_url + "/api/device", self._get_device_data())
|
||||||
response = self.http_client.post(self.base_url + "/api/device", data)
|
|
||||||
print(response.text)
|
print(response.text)
|
||||||
jsonResult = json.loads(response.text)
|
jsonResult = json.loads(response.text)
|
||||||
print(jsonResult)
|
print(jsonResult)
|
||||||
|
|
@ -24,7 +23,6 @@ class GrowSystemApi:
|
||||||
|
|
||||||
def send_measurements(self, device_id, data):
|
def send_measurements(self, device_id, data):
|
||||||
url = self.base_url + "/api/device/" + str(device_id) + "/sensor-log"
|
url = self.base_url + "/api/device/" + str(device_id) + "/sensor-log"
|
||||||
print(url)
|
|
||||||
response = self.http_client.post(url, data)
|
response = self.http_client.post(url, data)
|
||||||
return json.loads(response.text)
|
return json.loads(response.text)
|
||||||
|
|
||||||
|
|
|
||||||
2
main.py
2
main.py
|
|
@ -44,13 +44,11 @@ if __name__ == '__main__':
|
||||||
print("Connect WLAN")
|
print("Connect WLAN")
|
||||||
wlanClient = WlanClient(settings['wlan_ssid'], settings['wlan_pw'])
|
wlanClient = WlanClient(settings['wlan_ssid'], settings['wlan_pw'])
|
||||||
wlanClient.connect()
|
wlanClient.connect()
|
||||||
print("---------------------------------------")
|
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
di = DeviceInfo()
|
di = DeviceInfo()
|
||||||
print("Device Infos:")
|
print("Device Infos:")
|
||||||
print(di.get_all_device_infos())
|
print(di.get_all_device_infos())
|
||||||
print("---------------------------------------")
|
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
print("Start grow system")
|
print("Start grow system")
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
# Moisture Sensor Class
|
# Moisture Sensor Class
|
||||||
|
from sensors import Sensors
|
||||||
from machine import ADC, Pin
|
from machine import ADC, Pin
|
||||||
|
|
||||||
|
|
||||||
class MoistureSensor:
|
class MoistureSensor(Sensors):
|
||||||
sensor_pin_int = -1
|
|
||||||
|
|
||||||
sensor = None
|
sensor = None
|
||||||
|
|
||||||
|
|
@ -13,6 +13,7 @@ class MoistureSensor:
|
||||||
max_raw_value = None
|
max_raw_value = None
|
||||||
|
|
||||||
def __init__(self, sensor_data, min_raw_value=300, max_raw_value=65535):
|
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']))
|
print("Initialize moisture sensor. Sensor pin is: " + str(sensor_data['pin_int']))
|
||||||
self.sensor_pin_int = sensor_data['pin_int']
|
self.sensor_pin_int = sensor_data['pin_int']
|
||||||
self.min_raw_value = min_raw_value
|
self.min_raw_value = min_raw_value
|
||||||
|
|
|
||||||
|
|
@ -17,5 +17,4 @@ class SensorDataManager:
|
||||||
|
|
||||||
def handleData(self, data):
|
def handleData(self, data):
|
||||||
jsonResponse = self.grow_system_api.send_measurements(self.device_id, data)
|
jsonResponse = self.grow_system_api.send_measurements(self.device_id, data)
|
||||||
print("---- Response: -----")
|
print("Response message: " + jsonResponse['message'])
|
||||||
print(jsonResponse)
|
|
||||||
|
|
@ -1,3 +1,10 @@
|
||||||
class Sensors:
|
class Sensors:
|
||||||
# this is a parent class for the Sensor classes
|
# this is a parent class for the Sensor classes
|
||||||
|
sensor_pin_int = -1
|
||||||
|
|
||||||
|
type = "unset"
|
||||||
|
|
||||||
|
def __init__(self, settings):
|
||||||
|
self.type = settings['type']
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue