Skip to content

Commit

Permalink
Small changes
Browse files Browse the repository at this point in the history
SysModInstances:
- (WLED) header for Star instance: init name with 0, header type encode on...
  • Loading branch information
ewoudwijma committed Oct 9, 2024
1 parent 18c2a36 commit 9d94abd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
33 changes: 32 additions & 1 deletion src/Sys/SysModInstances.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class SysModInstances:public SysModule {
success = false;
}

ppf("UDPWLEDSyncMessage %d %d %d\n", sizeof(UDPWLEDMessage), sizeof(UDPStarMessage), sizeof(UDPWLEDSyncMessage));
ppf("UDP message sizes WLED:%d Star:%d WLED-Sync:%d\n", sizeof(UDPWLEDMessage), sizeof(UDPStarMessage), sizeof(UDPWLEDSyncMessage));
}

void onOffChanged() {
Expand Down Expand Up @@ -455,6 +455,11 @@ class SysModInstances:public SysModule {
byte *udpIn = (byte *)&starMessage.header;
instanceUDP.read(udpIn, packetSize);

// ppf("WLED instance %s received: size: %d\n", instanceUDP.remoteIP().toString().c_str(), packetSize);
// for (int i=0; i<44; i++) {
// Serial.printf("%d: %d\n", i, udpIn[i]);
// }

starMessage.sysData.type = 0; //WLED

if (starMessage.header.ip0 == net->localIP()[0]) { // checksum - no other type of message
Expand All @@ -468,6 +473,8 @@ class SysModInstances:public SysModule {
byte *udpIn = (byte *)&starMessage;
instanceUDP.read(udpIn, packetSize);

// ppf("Star instance %s received: size: %d\n", instanceUDP.remoteIP().toString().c_str(), packetSize);

if (starMessage.header.ip0 == net->localIP()[0]) { // checksum - no other type of message
updateInstance(starMessage);
found = true;
Expand Down Expand Up @@ -546,6 +553,7 @@ class SysModInstances:public SysModule {
starMessage.header.ip1 = localIP[1];
starMessage.header.ip2 = localIP[2];
starMessage.header.ip3 = localIP[3];
memset((byte *)starMessage.header.name, 0, 32); //init with 0
const char * name = mdl->getValue("System", "name");
strlcpy(starMessage.header.name, name?name:_INIT(TOSTRING(APP)), sizeof(starMessage.header.name));
#if defined(CONFIG_IDF_TARGET_ESP32S2)
Expand All @@ -560,6 +568,14 @@ class SysModInstances:public SysModule {
prf("dev unknown board\n");
starMessage.header.type = 0;
#endif
// if (bri)
starMessage.header.type |= 0x80U; // add on/off state
// 38: 160
// 39: 171
// 40: 138
// 41: 186
// 42: 36
// 43: 0
starMessage.header.insId = localIP[3]; //WLED: used in map of instances as index!
starMessage.header.version = VERSION;
starMessage.sysData.type = (strncmp(_INIT(TOSTRING(APP)), "StarBase", 9)==0)?1:(strncmp(_INIT(TOSTRING(APP)), "StarLight", 10)==0)?2:(strncmp(_INIT(TOSTRING(APP)), "StarLedsLive", 13)==0)?3:99; //0=WLED, 1=StarBase, 2=StarLight, 3=StarLedsLive, else=StarFork
Expand Down Expand Up @@ -619,6 +635,21 @@ class SysModInstances:public SysModule {
else {
ppf("sendSysInfoUDP error\n");
}
// if (0 != instanceUDP.beginPacket(IPAddress(255, 255, 255, 255), instanceUDPPort)) { // WLEDMM beginPacket == 0 --> error
// ppf("sendSysInfoUDP %s s:%d p:%d i:...%d\n", starMessage.header.name, sizeof(UDPWLEDMessage), instanceUDPPort, localIP[3]);
// for (size_t x = 0; x < sizeof(UDPWLEDMessage); x++) {
// char * xx = (char *)&starMessage.header;
// Serial.printf("%d: %d - %c\n", x, xx[x], xx[x]);
// }

// instanceUDP.write((uint8_t*)&starMessage.header, sizeof(UDPWLEDMessage));
// web->sendUDPCounter++;
// web->sendUDPBytes+=sizeof(UDPWLEDMessage);
// instanceUDP.endPacket();
// }
// else {
// ppf("sendSysInfoUDP error\n");
// }
}

//sends an UDP message to a specific ip. Broadcast?
Expand Down
3 changes: 2 additions & 1 deletion src/Sys/SysModWeb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ void SysModWeb::wsEvent(WebSocket * ws, WebClient * client, AwsEventType type, v
sendResponseObject(isOnUI?client:nullptr); //onUI only send to requesting client async response
}
else {
ppf("wsEvent no responseDoc\n");
if (!isOnUI) //for onui we know json.remove(key) is done
ppf("wsEvent no responseDoc ui:%d\n", isOnUI);
client->text("{\"success\":true}"); // we have to send something back otherwise WS connection closes
}
}
Expand Down

0 comments on commit 9d94abd

Please sign in to comment.