Persist config through backend controller

This commit is contained in:
root
2026-06-03 00:36:08 -06:00
parent fa20478b64
commit e6e74a0b3a
3 changed files with 37 additions and 12 deletions
+12
View File
@@ -80,6 +80,18 @@ def toggle_sensor_fault(name):
return jsonify(response)
@app.route("/config")
def get_config():
return jsonify(esp32.load_config())
@app.route("/config", methods=["POST"])
def save_config():
config = request.get_json(force=True)
return jsonify(esp32.save_config(config))
@app.route("/comms")
def comms():
return jsonify(pico.get_comms())
+10 -2
View File
@@ -35,11 +35,19 @@ class ESP32Simulator:
self.soc = 82.0
self.last_update = time.time()
def config_path(self):
return Path(__file__).parent / "config.json"
def load_config(self):
config_path = Path(__file__).parent / "config.json"
with config_path.open() as f:
with self.config_path().open() as f:
return json.load(f)
def save_config(self, config):
with self.config_path().open("w") as f:
json.dump(config, f, indent=2)
return self.load_config()
def update_battery(self):
now = time.time()
elapsed_hours = (now - self.last_update) / 3600
+9 -4
View File
@@ -171,15 +171,19 @@ let activeAlarmKey = null;
let acknowledgedAlarms = new Set();
let screenWakeTimeout = null;
let alarmConfig = {
let appConfig = {
alarms: {
rear_seat_warning: 85,
rear_seat_critical: 95,
fridge_zone_1_warm: 45,
fridge_zone_2_warm: 15,
battery_low: 20,
audible_alarms: true
}
};
let alarmConfig = appConfig.alarms;
function showScreen(id) {
document.querySelectorAll('.screen').forEach(screen => {
screen.classList.remove('active');
@@ -479,9 +483,10 @@ async function enableWifi() {
loadStatus();
}
loadAlarmSettings();
loadStatus();
setInterval(loadStatus, 2000);
loadAlarmSettings().then(() => {
loadStatus();
setInterval(loadStatus, 2000);
});
</script>
</body>
</html>