Add configurable system defaults
This commit is contained in:
@@ -0,0 +1,90 @@
|
|||||||
|
#include "app_config.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
AppConfig appConfig;
|
||||||
|
|
||||||
|
void loadDefaultConfig() {
|
||||||
|
appConfig.deviceName = DEVICE_NAME;
|
||||||
|
|
||||||
|
appConfig.relays[0] = {
|
||||||
|
"relay_1",
|
||||||
|
"Relay 1",
|
||||||
|
RELAY_STARLINK_PIN,
|
||||||
|
true
|
||||||
|
};
|
||||||
|
|
||||||
|
appConfig.relays[1] = {
|
||||||
|
"relay_2",
|
||||||
|
"Relay 2",
|
||||||
|
RELAY_FRIDGE_PIN,
|
||||||
|
true
|
||||||
|
};
|
||||||
|
|
||||||
|
appConfig.tempSensorCount = 4;
|
||||||
|
|
||||||
|
appConfig.tempSensors[0] = {
|
||||||
|
"temp_1",
|
||||||
|
"Temperature 1",
|
||||||
|
"",
|
||||||
|
true
|
||||||
|
};
|
||||||
|
|
||||||
|
appConfig.tempSensors[1] = {
|
||||||
|
"temp_2",
|
||||||
|
"Temperature 2",
|
||||||
|
"",
|
||||||
|
true
|
||||||
|
};
|
||||||
|
|
||||||
|
appConfig.tempSensors[2] = {
|
||||||
|
"temp_3",
|
||||||
|
"Temperature 3",
|
||||||
|
"",
|
||||||
|
true
|
||||||
|
};
|
||||||
|
|
||||||
|
appConfig.tempSensors[3] = {
|
||||||
|
"temp_4",
|
||||||
|
"Temperature 4",
|
||||||
|
"",
|
||||||
|
true
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int i = 4; i < MAX_TEMP_SENSORS; i++) {
|
||||||
|
appConfig.tempSensors[i] = {
|
||||||
|
"temp_" + String(i + 1),
|
||||||
|
"Temperature " + String(i + 1),
|
||||||
|
"",
|
||||||
|
false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
appConfig.bms.enabled = true;
|
||||||
|
appConfig.bms.name = "BMS";
|
||||||
|
appConfig.bms.address = "a5:c2:37:2c:05:dc";
|
||||||
|
appConfig.bms.addressType = "public";
|
||||||
|
}
|
||||||
|
|
||||||
|
void printConfig() {
|
||||||
|
Serial.println("Config:");
|
||||||
|
Serial.print(" Device: ");
|
||||||
|
Serial.println(appConfig.deviceName);
|
||||||
|
|
||||||
|
Serial.println(" Relays:");
|
||||||
|
for (int i = 0; i < MAX_RELAYS; i++) {
|
||||||
|
Serial.print(" ");
|
||||||
|
Serial.print(appConfig.relays[i].id);
|
||||||
|
Serial.print(" / ");
|
||||||
|
Serial.print(appConfig.relays[i].name);
|
||||||
|
Serial.print(" / GPIO ");
|
||||||
|
Serial.println(appConfig.relays[i].pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println(" BMS:");
|
||||||
|
Serial.print(" Enabled: ");
|
||||||
|
Serial.println(appConfig.bms.enabled ? "true" : "false");
|
||||||
|
Serial.print(" Name: ");
|
||||||
|
Serial.println(appConfig.bms.name);
|
||||||
|
Serial.print(" Address: ");
|
||||||
|
Serial.println(appConfig.bms.address);
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#define MAX_RELAYS 2
|
||||||
|
#define MAX_TEMP_SENSORS 8
|
||||||
|
|
||||||
|
struct RelayConfig {
|
||||||
|
String id;
|
||||||
|
String name;
|
||||||
|
uint8_t pin;
|
||||||
|
bool enabled;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TempSensorConfig {
|
||||||
|
String id;
|
||||||
|
String name;
|
||||||
|
String address;
|
||||||
|
bool enabled;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BmsConfig {
|
||||||
|
bool enabled;
|
||||||
|
String name;
|
||||||
|
String address;
|
||||||
|
String addressType;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AppConfig {
|
||||||
|
String deviceName;
|
||||||
|
RelayConfig relays[MAX_RELAYS];
|
||||||
|
TempSensorConfig tempSensors[MAX_TEMP_SENSORS];
|
||||||
|
int tempSensorCount;
|
||||||
|
BmsConfig bms;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern AppConfig appConfig;
|
||||||
|
|
||||||
|
void loadDefaultConfig();
|
||||||
|
void printConfig();
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "bms.h"
|
#include "bms.h"
|
||||||
#include "alarms.h"
|
#include "alarms.h"
|
||||||
#include "system_status.h"
|
#include "system_status.h"
|
||||||
|
#include "app_config.h"
|
||||||
|
|
||||||
WebServer server(80);
|
WebServer server(80);
|
||||||
HardwareSerial DashboardSerial(2);
|
HardwareSerial DashboardSerial(2);
|
||||||
@@ -131,6 +132,33 @@ void buildStatusDocument(JsonDocument& doc) {
|
|||||||
system["build_date"] = __DATE__;
|
system["build_date"] = __DATE__;
|
||||||
system["build_time"] = __TIME__;
|
system["build_time"] = __TIME__;
|
||||||
system["uptime_seconds"] = millis() / 1000;
|
system["uptime_seconds"] = millis() / 1000;
|
||||||
|
|
||||||
|
JsonObject configObj = doc.createNestedObject("config");
|
||||||
|
configObj["device_name"] = appConfig.deviceName;
|
||||||
|
|
||||||
|
JsonArray configRelays = configObj.createNestedArray("relays");
|
||||||
|
for (int i = 0; i < MAX_RELAYS; i++) {
|
||||||
|
JsonObject relayConfig = configRelays.createNestedObject();
|
||||||
|
relayConfig["id"] = appConfig.relays[i].id;
|
||||||
|
relayConfig["name"] = appConfig.relays[i].name;
|
||||||
|
relayConfig["pin"] = appConfig.relays[i].pin;
|
||||||
|
relayConfig["enabled"] = appConfig.relays[i].enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonObject bmsConfig = configObj.createNestedObject("bms");
|
||||||
|
bmsConfig["enabled"] = appConfig.bms.enabled;
|
||||||
|
bmsConfig["name"] = appConfig.bms.name;
|
||||||
|
bmsConfig["address"] = appConfig.bms.address;
|
||||||
|
bmsConfig["address_type"] = appConfig.bms.addressType;
|
||||||
|
|
||||||
|
JsonArray tempConfigs = configObj.createNestedArray("temperature_sensors");
|
||||||
|
for (int i = 0; i < MAX_TEMP_SENSORS; i++) {
|
||||||
|
JsonObject tempConfig = tempConfigs.createNestedObject();
|
||||||
|
tempConfig["id"] = appConfig.tempSensors[i].id;
|
||||||
|
tempConfig["name"] = appConfig.tempSensors[i].name;
|
||||||
|
tempConfig["address"] = appConfig.tempSensors[i].address;
|
||||||
|
tempConfig["enabled"] = appConfig.tempSensors[i].enabled;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendStatus(Stream& output, bool pretty = false) {
|
void sendStatus(Stream& output, bool pretty = false) {
|
||||||
@@ -333,9 +361,15 @@ void setup() {
|
|||||||
|
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println("==================================");
|
Serial.println("==================================");
|
||||||
|
|
||||||
|
loadDefaultConfig();
|
||||||
|
printConfig();
|
||||||
Serial.println("Xterra Controller Booting");
|
Serial.println("Xterra Controller Booting");
|
||||||
Serial.println("==================================");
|
Serial.println("==================================");
|
||||||
|
|
||||||
|
loadDefaultConfig();
|
||||||
|
printConfig();
|
||||||
|
|
||||||
pinMode(IGNITION_PIN, INPUT);
|
pinMode(IGNITION_PIN, INPUT);
|
||||||
|
|
||||||
initRelays();
|
initRelays();
|
||||||
|
|||||||
Reference in New Issue
Block a user