feat: do not store each infos of each node
This commit is contained in:
@@ -122,11 +122,6 @@ void ClusterManager::onDiscovery(const char* /*msg*/) {
|
|||||||
|
|
||||||
void ClusterManager::onHeartbeat(const char* /*msg*/) {
|
void ClusterManager::onHeartbeat(const char* /*msg*/) {
|
||||||
JsonDocument doc;
|
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) {
|
if (ctx.memberList) {
|
||||||
auto it = ctx.memberList->find(ctx.hostname);
|
auto it = ctx.memberList->find(ctx.hostname);
|
||||||
@@ -178,14 +173,6 @@ void ClusterManager::onNodeInfo(const char* msg) {
|
|||||||
auto it = memberList.find(nodeHost);
|
auto it = memberList.find(nodeHost);
|
||||||
if (it != memberList.end()) {
|
if (it != memberList.end()) {
|
||||||
NodeInfo& node = it->second;
|
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;
|
node.status = NodeInfo::ACTIVE;
|
||||||
unsigned long now = millis();
|
unsigned long now = millis();
|
||||||
node.lastSeen = now;
|
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
|
//fetchNodeInfo(nodeIP); // Do not fetch here, handled by periodic task
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unused http client to fetch complete node info
|
||||||
void ClusterManager::fetchNodeInfo(const IPAddress& ip) {
|
void ClusterManager::fetchNodeInfo(const IPAddress& ip) {
|
||||||
if(ip == ctx.localIP) {
|
if(ip == ctx.localIP) {
|
||||||
LOG_DEBUG("Cluster", "Skipping fetch for local node");
|
LOG_DEBUG("Cluster", "Skipping fetch for local node");
|
||||||
@@ -392,7 +380,7 @@ void ClusterManager::heartbeatTaskCallback() {
|
|||||||
node.lastSeen = millis();
|
node.lastSeen = millis();
|
||||||
node.status = NodeInfo::ACTIVE;
|
node.status = NodeInfo::ACTIVE;
|
||||||
updateLocalNodeResources();
|
updateLocalNodeResources();
|
||||||
ctx.fire("node_discovered", &node);
|
addOrUpdateNode(ctx.hostname, ctx.localIP);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Broadcast heartbeat so peers can respond with their node info
|
// Broadcast heartbeat so peers can respond with their node info
|
||||||
|
|||||||
@@ -44,11 +44,6 @@ void ClusterService::handleMembersRequest(AsyncWebServerRequest* request) {
|
|||||||
obj["lastSeen"] = node.lastSeen;
|
obj["lastSeen"] = node.lastSeen;
|
||||||
obj["latency"] = node.latency;
|
obj["latency"] = node.latency;
|
||||||
obj["status"] = statusToStr(node.status);
|
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
|
// Add labels if present
|
||||||
if (!node.labels.empty()) {
|
if (!node.labels.empty()) {
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ console.log(`Broadcasting color changes to http://${host}/api/cluster/event ...`
|
|||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
const color = colors[idx % colors.length];
|
const color = colors[idx % colors.length];
|
||||||
idx++;
|
idx++;
|
||||||
const payload = { color, brightness: 128 };
|
const payload = { color, brightness: 80 };
|
||||||
console.log('Broadcasting color:', payload);
|
console.log('Broadcasting color:', payload);
|
||||||
postClusterEvent('api/neopattern/color', payload);
|
postClusterEvent('api/neopattern/color', payload);
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ ws.on('open', () => {
|
|||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
const color = colors[idx % colors.length];
|
const color = colors[idx % colors.length];
|
||||||
idx++;
|
idx++;
|
||||||
const payload = { color, brightness: 128 };
|
const payload = { color, brightness: 80 };
|
||||||
const envelope = {
|
const envelope = {
|
||||||
event: 'api/neopattern/color',
|
event: 'api/neopattern/color',
|
||||||
data: payload // server will serialize object payloads
|
data: payload // server will serialize object payloads
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ function toHex({ r, g, b }) {
|
|||||||
let hue = 0;
|
let hue = 0;
|
||||||
const SAT = 1.0; // full saturation
|
const SAT = 1.0; // full saturation
|
||||||
const VAL = 1.0; // full value
|
const VAL = 1.0; // full value
|
||||||
const BRIGHTNESS = 128;
|
const BRIGHTNESS = 80;
|
||||||
const UPDATE_RATE = 100; // ms
|
const UPDATE_RATE = 100; // ms
|
||||||
|
|
||||||
let timer = null;
|
let timer = null;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ ws.on('open', () => {
|
|||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
const color = colors[idx % colors.length];
|
const color = colors[idx % colors.length];
|
||||||
idx++;
|
idx++;
|
||||||
const payload = { color, brightness: 128 };
|
const payload = { color, brightness: 80 };
|
||||||
// Send payload as an object (server supports string or object)
|
// Send payload as an object (server supports string or object)
|
||||||
const msg = { event: 'api/neopattern/color', payload };
|
const msg = { event: 'api/neopattern/color', payload };
|
||||||
ws.send(JSON.stringify(msg));
|
ws.send(JSON.stringify(msg));
|
||||||
|
|||||||
Reference in New Issue
Block a user