Compare commits

...
3 Commits
Author SHA1 Message Date
tanner bff2b727cc Add pressure 2026-08-25 18:07:18 +00:00
tannerandaider 086e632b75 fix: retry InfluxDB writes and notify on failure
Co-authored-by: aider (gemini/gemini-3.1-pro-preview) <aider@aider.chat>
2026-08-25 18:07:18 +00:00
tanner 3bc09edfe4 feat: add moisture to soil history query 2026-08-25 18:07:18 +00:00
+11 -3
View File
@@ -149,11 +149,16 @@ class Sensor():
'fields': data, 'fields': data,
} }
for attempt in range(3):
try: try:
sensors_client.write_points([point]) sensors_client.write_points([point])
except requests.exceptions.ConnectionError: break
logging.exception('Error connecting to InfluxDB!') except Exception as e:
logging.exception('Error writing to InfluxDB (attempt %s/3): %s', attempt + 1, e)
if attempt == 2:
controller_message('Failed to write to InfluxDB after 3 attempts: ' + str(e))
return return
time.sleep(1)
logging.info('Wrote %s data to InfluxDB: %s', self, data) logging.info('Wrote %s data to InfluxDB: %s', self, data)
@@ -525,10 +530,13 @@ async def history(request):
q = 'select max("pm10") as max_p10, max("pm25") as max_p25, max("co2") as max_co2, max("voc_idx") as max_voc from air where "name" = \'{}\' and time >= {}s and time < {}s group by time({}) fill(linear)'.format(name, start, end, window) q = 'select max("pm10") as max_p10, max("pm25") as max_p25, max("co2") as max_co2, max("voc_idx") as max_voc from air where "name" = \'{}\' and time >= {}s and time < {}s group by time({}) fill(linear)'.format(name, start, end, window)
elif measurement == 'soil': elif measurement == 'soil':
client = sensors_client client = sensors_client
q = 'select mean("soil") as soil from soil where "name" = \'{}\' and time >= {}s and time < {}s group by time({}) fill(linear)'.format(name, start, end, window) q = 'select mean("soil") as soil, mean("moisture") as moisture from soil where "name" = \'{}\' and time >= {}s and time < {}s group by time({}) fill(linear)'.format(name, start, end, window)
elif measurement == 'lux': elif measurement == 'lux':
client = sensors_client client = sensors_client
q = 'select mean("lux") as lux from air where "name" = \'{}\' and time >= {}s and time < {}s group by time({}) fill(linear)'.format(name, start, end, window) q = 'select mean("lux") as lux from air where "name" = \'{}\' and time >= {}s and time < {}s group by time({}) fill(linear)'.format(name, start, end, window)
elif measurement == 'hpa':
client = sensors_client
q = 'select mean("hpa") as hpa from air where "name" = \'{}\' and time >= {}s and time < {}s group by time({}) fill(linear)'.format(name, start, end, window)
elif measurement == 'sleep': elif measurement == 'sleep':
client = sensors_client client = sensors_client
q = 'select max("max_mag") as max_mag from sleep where "name" = \'{}\' and time >= {}s and time < {}s group by time({}) fill(linear)'.format(name, start, end, window) q = 'select max("max_mag") as max_mag from sleep where "name" = \'{}\' and time >= {}s and time < {}s group by time({}) fill(linear)'.format(name, start, end, window)