feat: do not store each infos of each node

This commit is contained in:
2025-10-01 20:45:55 +02:00
parent dbb3b5bfd3
commit 99e7ed4809
6 changed files with 6 additions and 23 deletions

View File

@@ -122,11 +122,6 @@ void ClusterManager::onDiscovery(const char* /*msg*/) {
void ClusterManager::onHeartbeat(const char* /*msg*/) {
JsonDocument doc;
doc["freeHeap"] = ESP.getFreeHeap();
doc["chipId"] = ESP.getChipId();
doc["sdkVersion"] = ESP.getSdkVersion();
doc["cpuFreqMHz"] = ESP.getCpuFreqMHz();
doc["flashChipSize"] = ESP.getFlashChipSize();
if (ctx.memberList) {
auto it = ctx.memberList->find(ctx.hostname);
@@ -178,14 +173,6 @@ void ClusterManager::onNodeInfo(const char* msg) {
auto it = memberList.find(nodeHost);
if (it != memberList.end()) {
NodeInfo& node = it->second;
node.resources.freeHeap = doc["freeHeap"] | node.resources.freeHeap;
node.resources.chipId = doc["chipId"] | node.resources.chipId;
{
const char* sdk = doc["sdkVersion"] | node.resources.sdkVersion.c_str();
node.resources.sdkVersion = sdk ? String(sdk) : node.resources.sdkVersion;
}
node.resources.cpuFreqMHz = doc["cpuFreqMHz"] | node.resources.cpuFreqMHz;
node.resources.flashChipSize = doc["flashChipSize"] | node.resources.flashChipSize;
node.status = NodeInfo::ACTIVE;
unsigned long now = millis();
node.lastSeen = now;
@@ -277,6 +264,7 @@ void ClusterManager::addOrUpdateNode(const String& nodeHost, IPAddress nodeIP) {
//fetchNodeInfo(nodeIP); // Do not fetch here, handled by periodic task
}
// unused http client to fetch complete node info
void ClusterManager::fetchNodeInfo(const IPAddress& ip) {
if(ip == ctx.localIP) {
LOG_DEBUG("Cluster", "Skipping fetch for local node");
@@ -392,7 +380,7 @@ void ClusterManager::heartbeatTaskCallback() {
node.lastSeen = millis();
node.status = NodeInfo::ACTIVE;
updateLocalNodeResources();
ctx.fire("node_discovered", &node);
addOrUpdateNode(ctx.hostname, ctx.localIP);
}
// Broadcast heartbeat so peers can respond with their node info

View File

@@ -44,11 +44,6 @@ void ClusterService::handleMembersRequest(AsyncWebServerRequest* request) {
obj["lastSeen"] = node.lastSeen;
obj["latency"] = node.latency;
obj["status"] = statusToStr(node.status);
obj["resources"]["freeHeap"] = node.resources.freeHeap;
obj["resources"]["chipId"] = node.resources.chipId;
obj["resources"]["sdkVersion"] = node.resources.sdkVersion;
obj["resources"]["cpuFreqMHz"] = node.resources.cpuFreqMHz;
obj["resources"]["flashChipSize"] = node.resources.flashChipSize;
// Add labels if present
if (!node.labels.empty()) {

View File

@@ -44,7 +44,7 @@ console.log(`Broadcasting color changes to http://${host}/api/cluster/event ...`
setInterval(() => {
const color = colors[idx % colors.length];
idx++;
const payload = { color, brightness: 128 };
const payload = { color, brightness: 80 };
console.log('Broadcasting color:', payload);
postClusterEvent('api/neopattern/color', payload);
}, 5000);

View File

@@ -15,7 +15,7 @@ ws.on('open', () => {
setInterval(() => {
const color = colors[idx % colors.length];
idx++;
const payload = { color, brightness: 128 };
const payload = { color, brightness: 80 };
const envelope = {
event: 'api/neopattern/color',
data: payload // server will serialize object payloads

View File

@@ -31,7 +31,7 @@ function toHex({ r, g, b }) {
let hue = 0;
const SAT = 1.0; // full saturation
const VAL = 1.0; // full value
const BRIGHTNESS = 128;
const BRIGHTNESS = 80;
const UPDATE_RATE = 100; // ms
let timer = null;

View File

@@ -22,7 +22,7 @@ ws.on('open', () => {
setInterval(() => {
const color = colors[idx % colors.length];
idx++;
const payload = { color, brightness: 128 };
const payload = { color, brightness: 80 };
// Send payload as an object (server supports string or object)
const msg = { event: 'api/neopattern/color', payload };
ws.send(JSON.stringify(msg));