feat: set labels in NodeContext/Info

This commit is contained in:
2025-08-29 20:21:11 +02:00
parent d3a9802ec9
commit fe045804cb
7 changed files with 61 additions and 42 deletions

View File

@@ -14,7 +14,6 @@ void NetworkManager::setHostnameFromMac() {
}
void NetworkManager::setupWiFi() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ctx.config.wifi_ssid.c_str(), ctx.config.wifi_password.c_str());
Serial.println("[WiFi] Connecting to AP...");
@@ -43,18 +42,26 @@ void NetworkManager::setupWiFi() {
Serial.println(ctx.hostname);
Serial.printf("[WiFi] UDP listening on port %d\n", ctx.config.udp_port);
// Register this node in the memberlist via event system
NodeInfo self;
self.hostname = ctx.hostname;
if(WiFi.isConnected()) {
self.ip = WiFi.localIP();
// Populate self NodeInfo
ctx.self.hostname = ctx.hostname;
if (WiFi.isConnected()) {
ctx.self.ip = WiFi.localIP();
} else {
// Fallback to AP IP if not connected
self.ip = WiFi.softAPIP();
ctx.self.ip = WiFi.softAPIP();
}
self.lastSeen = millis();
self.status = NodeInfo::ACTIVE;
// Initialize a default label for demonstration; users can modify at runtime
self.labels["hostname"] = ctx.hostname;
ctx.fire("node_discovered", &self);
ctx.self.lastSeen = millis();
ctx.self.status = NodeInfo::ACTIVE;
ctx.self.labels["hostname"] = ctx.hostname;
// Ensure member list has an entry for this node
auto &memberList = *ctx.memberList;
auto existing = memberList.find(ctx.hostname);
if (existing == memberList.end()) {
memberList[ctx.hostname] = ctx.self;
} else {
existing->second = ctx.self;
}
// Notify listeners that the node is (re)discovered
ctx.fire("node_discovered", &ctx.self);
}