Persist config through backend controller
This commit is contained in:
@@ -80,6 +80,18 @@ def toggle_sensor_fault(name):
|
|||||||
return jsonify(response)
|
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")
|
@app.route("/comms")
|
||||||
def comms():
|
def comms():
|
||||||
return jsonify(pico.get_comms())
|
return jsonify(pico.get_comms())
|
||||||
|
|||||||
+10
-2
@@ -35,11 +35,19 @@ class ESP32Simulator:
|
|||||||
self.soc = 82.0
|
self.soc = 82.0
|
||||||
self.last_update = time.time()
|
self.last_update = time.time()
|
||||||
|
|
||||||
|
def config_path(self):
|
||||||
|
return Path(__file__).parent / "config.json"
|
||||||
|
|
||||||
def load_config(self):
|
def load_config(self):
|
||||||
config_path = Path(__file__).parent / "config.json"
|
with self.config_path().open() as f:
|
||||||
with config_path.open() as f:
|
|
||||||
return json.load(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):
|
def update_battery(self):
|
||||||
now = time.time()
|
now = time.time()
|
||||||
elapsed_hours = (now - self.last_update) / 3600
|
elapsed_hours = (now - self.last_update) / 3600
|
||||||
|
|||||||
@@ -171,15 +171,19 @@ let activeAlarmKey = null;
|
|||||||
let acknowledgedAlarms = new Set();
|
let acknowledgedAlarms = new Set();
|
||||||
let screenWakeTimeout = null;
|
let screenWakeTimeout = null;
|
||||||
|
|
||||||
let alarmConfig = {
|
let appConfig = {
|
||||||
|
alarms: {
|
||||||
rear_seat_warning: 85,
|
rear_seat_warning: 85,
|
||||||
rear_seat_critical: 95,
|
rear_seat_critical: 95,
|
||||||
fridge_zone_1_warm: 45,
|
fridge_zone_1_warm: 45,
|
||||||
fridge_zone_2_warm: 15,
|
fridge_zone_2_warm: 15,
|
||||||
battery_low: 20,
|
battery_low: 20,
|
||||||
audible_alarms: true
|
audible_alarms: true
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let alarmConfig = appConfig.alarms;
|
||||||
|
|
||||||
function showScreen(id) {
|
function showScreen(id) {
|
||||||
document.querySelectorAll('.screen').forEach(screen => {
|
document.querySelectorAll('.screen').forEach(screen => {
|
||||||
screen.classList.remove('active');
|
screen.classList.remove('active');
|
||||||
@@ -479,9 +483,10 @@ async function enableWifi() {
|
|||||||
loadStatus();
|
loadStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
loadAlarmSettings();
|
loadAlarmSettings().then(() => {
|
||||||
loadStatus();
|
loadStatus();
|
||||||
setInterval(loadStatus, 2000);
|
setInterval(loadStatus, 2000);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user