diff --git a/html/admin.html b/html/admin.html
index b9dd8e9..8a769f5 100755
--- a/html/admin.html
+++ b/html/admin.html
@@ -91,7 +91,7 @@
-
+
@@ -341,6 +341,11 @@ window.onload = function() {
checkbox_nmp5channels.checked = response.npm_5channel;
checkbox_wind.checked = response["windMeter"];
checkbox_uSpot.checked = response["send_uSpot"];
+
+ // If envea is enabled, show the envea sondes container
+ if (response["envea"]) {
+ add_sondeEnveaContainer();
+ }
},
error: function(xhr, status, error) {
@@ -726,11 +731,14 @@ function add_sondeEnveaContainer() {
onchange="updateSondeStatus(${sonde.id}, this.checked)">
-
+ id="${sondeId}_name" readonly style="background-color: #f8f9fa;">
+
+ id="${sondeId}_coefficient" readonly style="background-color: #f8f9fa;">
`;
diff --git a/sqlite/set_config.py b/sqlite/set_config.py
index 6a6d24b..235e173 100644
--- a/sqlite/set_config.py
+++ b/sqlite/set_config.py
@@ -56,7 +56,21 @@ for key, value, value_type in config_entries:
(key, value, value_type)
)
-# Insert envea sondes
+# Clean up duplicate envea sondes first (keep only first occurrence of each name)
+print("Cleaning up duplicate envea sondes...")
+cursor.execute("""
+ DELETE FROM envea_sondes_table
+ WHERE id NOT IN (
+ SELECT MIN(id)
+ FROM envea_sondes_table
+ GROUP BY name
+ )
+""")
+deleted_count = cursor.rowcount
+if deleted_count > 0:
+ print(f"Deleted {deleted_count} duplicate envea sonde entries")
+
+# Insert envea sondes (only if they don't already exist)
envea_sondes = [
(False, "ttyAMA4", "h2s", 4),
(False, "ttyAMA3", "no2", 1),
@@ -64,10 +78,18 @@ envea_sondes = [
]
for connected, port, name, coefficient in envea_sondes:
- cursor.execute(
- "INSERT OR IGNORE INTO envea_sondes_table (connected, port, name, coefficient) VALUES (?, ?, ?, ?)",
- (1 if connected else 0, port, name, coefficient)
- )
+ # Check if sensor with this name already exists
+ cursor.execute("SELECT COUNT(*) FROM envea_sondes_table WHERE name = ?", (name,))
+ exists = cursor.fetchone()[0] > 0
+
+ if not exists:
+ cursor.execute(
+ "INSERT INTO envea_sondes_table (connected, port, name, coefficient) VALUES (?, ?, ?, ?)",
+ (1 if connected else 0, port, name, coefficient)
+ )
+ print(f"Added envea sonde: {name}")
+ else:
+ print(f"Envea sonde '{name}' already exists, skipping")
# Commit and close the connection