Remove install-specific names from config and API docs
This commit is contained in:
@@ -35,9 +35,9 @@ void loadDefaultConfig() {
|
||||
};
|
||||
}
|
||||
|
||||
appConfig.bms.enabled = true;
|
||||
appConfig.bms.name = "BMS";
|
||||
appConfig.bms.address = "a5:c2:37:2c:05:dc";
|
||||
appConfig.bms.enabled = false;
|
||||
appConfig.bms.name = "";
|
||||
appConfig.bms.address = "";
|
||||
appConfig.bms.addressType = "public";
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
#include <Arduino.h>
|
||||
#include <NimBLEDevice.h>
|
||||
#include "logger.h"
|
||||
#include "app_config.h"
|
||||
|
||||
static const char* BMS_ADDRESS = "a5:c2:37:2c:05:dc";
|
||||
// BMS address is loaded from appConfig.bms.address.
|
||||
static const char* BMS_SERVICE_UUID = "ff00";
|
||||
static const char* BMS_NOTIFY_UUID = "ff01";
|
||||
static const char* BMS_WRITE_UUID = "ff02";
|
||||
@@ -300,7 +301,15 @@ static bool connectBms() {
|
||||
|
||||
Serial.println("BMS: Connecting...");
|
||||
|
||||
NimBLEAddress address(std::string(BMS_ADDRESS), BLE_ADDR_PUBLIC);
|
||||
if (!appConfig.bms.enabled || appConfig.bms.address.length() == 0) {
|
||||
bmsData.connected = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
NimBLEAddress address(
|
||||
std::string(appConfig.bms.address.c_str()),
|
||||
appConfig.bms.addressType == "random" ? BLE_ADDR_RANDOM : BLE_ADDR_PUBLIC
|
||||
);
|
||||
|
||||
client = NimBLEDevice::createClient();
|
||||
|
||||
|
||||
@@ -587,6 +587,65 @@ void handleFactoryResetConfig() {
|
||||
sendConfigJson();
|
||||
}
|
||||
|
||||
|
||||
void handleGenericRelayRoute() {
|
||||
String uri = server.uri();
|
||||
|
||||
// Expected format:
|
||||
// /relay/relay_1/on
|
||||
// /relay/relay_1/off
|
||||
// /relay/relay_2/on
|
||||
// /relay/relay_2/off
|
||||
|
||||
String prefix = "/relay/";
|
||||
if (!uri.startsWith(prefix)) {
|
||||
server.send(404, "application/json", "{\"ok\":false,\"error\":\"invalid_relay_route\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
String rest = uri.substring(prefix.length());
|
||||
int slash = rest.indexOf('/');
|
||||
|
||||
if (slash < 0) {
|
||||
server.send(400, "application/json", "{\"ok\":false,\"error\":\"missing_relay_action\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
String relayId = rest.substring(0, slash);
|
||||
String action = rest.substring(slash + 1);
|
||||
|
||||
bool enabled;
|
||||
|
||||
if (action == "on") {
|
||||
enabled = true;
|
||||
} else if (action == "off") {
|
||||
enabled = false;
|
||||
} else {
|
||||
server.send(400, "application/json", "{\"ok\":false,\"error\":\"invalid_relay_action\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (relayId == "relay_1") {
|
||||
relays.starlink = enabled;
|
||||
} else if (relayId == "relay_2") {
|
||||
relays.fridge = enabled;
|
||||
} else {
|
||||
server.send(404, "application/json", "{\"ok\":false,\"error\":\"unknown_relay\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
updateRelayOutputs();
|
||||
|
||||
DynamicJsonDocument doc(512);
|
||||
doc["ok"] = true;
|
||||
doc["id"] = relayId;
|
||||
doc["state"] = enabled;
|
||||
|
||||
String output;
|
||||
serializeJson(doc, output);
|
||||
server.send(200, "application/json", output);
|
||||
}
|
||||
|
||||
void handleStatus() {
|
||||
DynamicJsonDocument doc(2048);
|
||||
buildStatusDocument(doc);
|
||||
@@ -669,6 +728,11 @@ void setup() {
|
||||
}
|
||||
|
||||
server.on("/status", handleStatus);
|
||||
server.on("/relay/relay_1/on", HTTP_GET, handleGenericRelayRoute);
|
||||
server.on("/relay/relay_1/off", HTTP_GET, handleGenericRelayRoute);
|
||||
server.on("/relay/relay_2/on", HTTP_GET, handleGenericRelayRoute);
|
||||
server.on("/relay/relay_2/off", HTTP_GET, handleGenericRelayRoute);
|
||||
|
||||
|
||||
server.on("/config", HTTP_GET, handleGetConfig);
|
||||
server.on("/config/relay", HTTP_POST, handleUpdateRelayConfig);
|
||||
|
||||
Reference in New Issue
Block a user