Changed readSensors for better ErrorHandling
This commit is contained in:
parent
052ace21bf
commit
a8f365cd4f
@ -17,11 +17,11 @@ def measure_send_data(plantID, actionID, client: mqtt.Client):
|
||||
actionID (_type_): current ID of driving action
|
||||
client (mqtt.Client): current mqtt client for publishing
|
||||
"""
|
||||
sensordata = {}
|
||||
sensordata |= SENSORDATA
|
||||
sensorData = {}
|
||||
sensorData |= SENSORDATA
|
||||
|
||||
try:
|
||||
sensorData = Sensors.readSensors()
|
||||
Sensors.readSensors(sensorData)
|
||||
except Exception as e:
|
||||
logging.error(str(e))
|
||||
client.publish(Topics["ROBOT_DATA_ERROR"], str(e), qos=1)
|
||||
@ -111,14 +111,13 @@ def drive_plant_all_thread(plantIDs: list, actionID, client: mqtt.Client):
|
||||
try:
|
||||
sensordata = {}
|
||||
sensordata |= SENSORDATA
|
||||
sensordata = Sensors.readSensors()
|
||||
sensordata["PlantID"] = plant
|
||||
allPlantData["SensorData"].append(sensordata)
|
||||
Sensors.readSensors(sensordata)
|
||||
except Exception as e:
|
||||
logging.error(str(e))
|
||||
client.publish(Topics["ROBOT_DATA_ERROR"], str(e), qos=1)
|
||||
|
||||
time.sleep(3)
|
||||
sensordata["PlantID"] = plant
|
||||
allPlantData["SensorData"].append(sensordata)
|
||||
|
||||
|
||||
# TODO How to Handle Pictures and PlantID
|
||||
|
@ -12,7 +12,7 @@ import paho.mqtt.client as mqtt
|
||||
import functions
|
||||
import logging
|
||||
import sys
|
||||
from defines import Topics, RASPI_CLIENT_ID, MQTT_BROKER_GLOBAL
|
||||
from defines import Topics, RASPI_CLIENT_ID, MQTT_BROKER_GLOBAL, MQTT_BROKER_LOCAL
|
||||
|
||||
|
||||
def on_connect(client: mqtt.Client, userdata, flags, rc):
|
||||
@ -53,8 +53,11 @@ def main():
|
||||
logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
|
||||
|
||||
client = mqtt.Client(RASPI_CLIENT_ID)
|
||||
# client = mqtt.Client(RASPI_CLIENT_ID, transport="websockets") # Local Broker
|
||||
client.on_connect = on_connect
|
||||
client.connect(MQTT_BROKER_GLOBAL)
|
||||
# client.connect("192.168.137.197") # Local Broker
|
||||
|
||||
|
||||
# CHECK forever or start
|
||||
client.loop_start()
|
||||
|
@ -2,7 +2,6 @@
|
||||
import adafruit_dht
|
||||
import adafruit_tsl2561
|
||||
import board
|
||||
import json
|
||||
import spidev
|
||||
from picamera import PiCamera
|
||||
from defines import SENSORDATA
|
||||
@ -90,22 +89,19 @@ def readMCP3008():
|
||||
return percentage
|
||||
|
||||
|
||||
|
||||
# TODO Function for all sensors
|
||||
def readSensors():
|
||||
def readSensors(sensorData):
|
||||
"""
|
||||
Read DHT22, TSL2561 and Humidity Sensor
|
||||
|
||||
Args:
|
||||
sensorData (dictionary): Dictionary of type SENSORDATA
|
||||
|
||||
Raises:
|
||||
Exception: DHT22 not connected
|
||||
Exception: TSL2561 not connected
|
||||
Exception: YL69 not connected
|
||||
|
||||
Returns:
|
||||
dict: Sensordata
|
||||
"""
|
||||
sensorData = {}
|
||||
sensorData |= SENSORDATA
|
||||
errorMessage = ""
|
||||
|
||||
# read DHT22
|
||||
@ -134,7 +130,6 @@ def readSensors():
|
||||
if errorMessage != "":
|
||||
raise Exception(errorMessage)
|
||||
|
||||
return sensorData
|
||||
|
||||
|
||||
def takePicture():
|
||||
|
Loading…
x
Reference in New Issue
Block a user