This commit is contained in:
PaulVua
2025-01-29 16:22:20 +01:00
parent 280dcd9be3
commit a8ca15505e
4 changed files with 165 additions and 43 deletions

View File

@@ -375,50 +375,42 @@ try:
# Sondes Envea
if connected_envea_sondes:
# Pour chacune des sondes
for device in connected_envea_sondes:
port = device.get('port', 'Unknown')
name = device.get('name', 'Unknown')
coefficient = device.get('coefficient', 'Unknown')
print("Getting Envea values")
# Define the path to the JSON file
json_file_path_envea = "/var/www/nebuleair_pro_4g/envea/data/data.json"
# Read the JSON file
try:
with open(json_file_path_envea, "r") as file:
data = json.load(file) # Load JSON into a dictionary
print(f"Connected envea Sonde: {name} on port {port} and coefficient {coefficient} ")
if name in serial_connections:
serial_connection = serial_connections[name]
try:
# Write data to the device
serial_connection.write(
b"\xFF\x02\x13\x30\x01\x02\x03\x04\x05\x06\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x12\xAF\x88\x03"
)
# Read data from the device
data_envea = serial_connection.readline()
if len(data_envea) >= 20:
byte_20 = data_envea[19]
byte_20 = byte_20 * coefficient
# Update payload CSV based on device type
if name == "h2s":
payload_csv[10] = byte_20
payload_json["sensordatavalues"].append({"value_type": "CAIRSENS_H2S", "value": str(byte_20)})
if name == "no2":
payload_csv[9] = byte_20
payload_json["sensordatavalues"].append({"value_type": "CAIRSENS_NO2", "value": str(byte_20)})
if name == "o3":
payload_csv[11] = byte_20
payload_json["sensordatavalues"].append({"value_type": "CAIRSENS_O3", "value": str(byte_20)})
print(f"Data from envea {name}: {byte_20}")
else:
print(f"Données reçues insuffisantes pour {name} pour extraire le 20ème octet.")
except serial.SerialException as e:
print(f"Error communicating with {name}: {e}")
else:
print(f"No serial connection for {name}")
# Extract values
h2s = data.get("h2s", 0)
no2 = data.get("no2", 0)
o3 = data.get("o3", 0)
# Print extracted values
print(f"h2s : {h2s}")
print(f"no2 : {no2}")
print(f"o3: {o3}")
#add to CSV
payload_csv[10] = h2s
payload_csv[9] = no2
payload_csv[11] = o3
#add to JSON
payload_json["sensordatavalues"].append({"value_type": "CAIRSENS_H2S", "value": str(h2s)})
payload_json["sensordatavalues"].append({"value_type": "CAIRSENS_NO2", "value": str(no2)})
payload_json["sensordatavalues"].append({"value_type": "CAIRSENS_O3", "value": str(o3)})
except FileNotFoundError:
print(f"Error: JSON file not found at {json_file_path_envea}")
except json.JSONDecodeError:
print("Error: JSON file is not formatted correctly")
except Exception as e:
print(f"Unexpected error: {e}")
# Getting the LTE Signal
print("-> Getting LTE signal <-")
ser_sara.write(b'AT+CSQ\r')