Skip to content

Commit

Permalink
Reduce debug output + tweaks
Browse files Browse the repository at this point in the history
SysModweb: sendDataWs: cleanup if full
SysModNetwork: save model if connect
  • Loading branch information
ewowi committed Jan 25, 2024
1 parent 6b114f4 commit 417fabf
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 31 deletions.
8 changes: 2 additions & 6 deletions src/App/AppModLeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,11 @@ class AppModLeds:public SysModule {
}); //fixture

ui->initText(tableVar, "dimensions", nullptr, 32, true, [](JsonObject var) { //uiFun
char details[32] = "";
print->fFormat(details, sizeof(details)-1, "P:%dx%dx%d V:%dx%dx%d", ledsV.widthP, ledsV.heightP, ledsV.depthP, ledsV.widthV, ledsV.heightV, ledsV.depthV);
web->addResponse(var["id"], "value", JsonString(details, JsonString::Copied));
web->addResponseV(var["id"], "value", "P:%dx%dx%d V:%dx%dx%d", ledsV.widthP, ledsV.heightP, ledsV.depthP, ledsV.widthV, ledsV.heightV, ledsV.depthV);
});

ui->initText(tableVar, "nrOfLeds", nullptr, 32, true, [](JsonObject var) { //uiFun
char details[32] = "";
print->fFormat(details, sizeof(details)-1, "P:%d V:%d", ledsV.nrOfLedsP, ledsV.nrOfLedsV);
web->addResponse(var["id"], "value", JsonString(details, JsonString::Copied));
web->addResponseV(var["id"], "value", "P:%d V:%d", ledsV.nrOfLedsP, ledsV.nrOfLedsV);
web->addResponseV(var["id"], "comment", "Max %d", NUM_LEDS_Max);
});

Expand Down
4 changes: 1 addition & 3 deletions src/Sys/SysModFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ void SysModFiles::setup() {
});

ui->initText(parentVar, "drsize", nullptr, 32, true, [](JsonObject var) { //uiFun
char details[32] = "";
print->fFormat(details, sizeof(details)-1, "%d / %d B", files->usedBytes(), files->totalBytes());
web->addResponse(var["id"], "value", JsonString(details, JsonString::Copied));
web->addResponseV(var["id"], "value", "%d / %d B", files->usedBytes(), files->totalBytes());
web->addResponse(var["id"], "label", "Total FS size");
});

Expand Down
3 changes: 2 additions & 1 deletion src/Sys/SysModModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class SysModModel:public SysModule {

static JsonObject modelParentVar;

bool doWriteModel = false;

SysModModel();
void setup();
void loop();
Expand Down Expand Up @@ -210,7 +212,6 @@ class SysModModel:public SysModule {
void varToValues(JsonObject var, JsonArray values);

private:
bool doWriteModel = false;
bool doShowObsolete = false;
bool cleanUpModelDone = false;

Expand Down
3 changes: 2 additions & 1 deletion src/Sys/SysModNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ void SysModNetwork::setup() {
});

ui->initButton(parentVar, "connect", nullptr, false, [](JsonObject var) { //uiFun
web->addResponse(var["id"], "comment", "Force reconnect (you loose current connection)");
web->addResponse(var["id"], "comment", "Force reconnect (loose current connection)");
}, [this](JsonObject var, uint8_t) { //chFun
mdl->doWriteModel = true; //saves the model
forceReconnect = true;
});
ui->initText(parentVar, "nwstatus", nullptr, 32, true, [](JsonObject var) { //uiFun
Expand Down
2 changes: 1 addition & 1 deletion src/Sys/SysModPrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ size_t SysModPrint::print(const char * format, ...) {

va_start(args, format);

Serial.print(strncmp(pcTaskGetTaskName(NULL), "loopTask", 8) == 0?"λ":"α"); //looptask / asyncTCP task
Serial.print(strncmp(pcTaskGetTaskName(NULL), "loopTask", 8) == 0?"":"α"); //looptask λ/ asyncTCP task α

for (size_t i = 0; i < strlen(format); i++)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sys/SysModUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void SysModUI::setChFunAndWs(JsonObject var, uint8_t rowNr, const char * value)
else if (var["value"].is<const char *>())
web->addResponse(var["id"], "value", var["value"].as<const char *>());
else if (var["value"].is<JsonArray>()) {
USER_PRINTF("setChFunAndWs %s JsonArray %s\n", var["id"].as<const char *>(), var["value"].as<String>().c_str());
// USER_PRINTF("setChFunAndWs %s JsonArray %s\n", var["id"].as<const char *>(), var["value"].as<String>().c_str());
web->addResponse(var["id"], "value", var["value"].as<JsonArray>());
}
else {
Expand Down
26 changes: 9 additions & 17 deletions src/Sys/SysModWeb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,26 +347,18 @@ void SysModWeb::sendDataWs(std::function<void(AsyncWebSocketMessageBuffer *)> fi

fill(wsBuf); //function parameter

if (client) {
if (client->status() == WS_CONNECTED && !client->queueIsFull() && client->queueLength() <= WS_MAX_QUEUED_MESSAGES / web->ws->count() / 2) {
isBinary?client->binary(wsBuf):client->text(wsBuf);
sendDataWsCounter++;
}
else
print->printClient("sendDataWs client full or not connected", client);

// DEBUG_PRINTLN("to a single client.");
} else {
for (auto client:ws->getClients()) {
if (client->status() == WS_CONNECTED && !client->queueIsFull() && client->queueLength() <= WS_MAX_QUEUED_MESSAGES / web->ws->count() / 2) {
isBinary?client->binary(wsBuf): client->text(wsBuf);
for (auto loopClient:ws->getClients()) {
if (!client || client == loopClient) {
if (loopClient->status() == WS_CONNECTED && !loopClient->queueIsFull() && loopClient->queueLength() <= WS_MAX_QUEUED_MESSAGES / web->ws->count() / 2) {
isBinary?loopClient->binary(wsBuf): loopClient->text(wsBuf);
sendDataWsCounter++;
}
else
// print->printClient("sendDataWs client(s) full or not connected", client); //crash!!
USER_PRINT_Async("sendDataWs client full or not connected\n");
else {
USER_PRINT_Async("sendDataWs client full or not connected\n", client);
ws->cleanupClients(); //only if above threshold
ws->_cleanBuffers();
}
}
// DEBUG_PRINTLN("to multiple clients.");
}
wsBuf->unlock();
ws->_cleanBuffers();
Expand Down
2 changes: 1 addition & 1 deletion src/User/UserModInstances.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ class UserModInstances:public SysModule {

IPAddress broadcastIP(255, 255, 255, 255);
if (0 != instanceUDP.beginPacket(broadcastIP, instanceUDPPort)) { // WLEDMM beginPacket == 0 --> error
USER_PRINTF("sendSysInfoUDP %s s:%d p:%d i:...%d\n", starModMessage.header.name, sizeof(UDPStarModMessage), instanceUDPPort, localIP[3]);
// USER_PRINTF("sendSysInfoUDP %s s:%d p:%d i:...%d\n", starModMessage.header.name, sizeof(UDPStarModMessage), instanceUDPPort, localIP[3]);
// for (size_t x = 0; x < sizeof(UDPWLEDMessage) + sizeof(SysData) + sizeof(AppData); x++) {
// char * xx = (char *)&starModMessage;
// Serial.printf("%d: %d - %c\n", x, xx[x], xx[x]);
Expand Down

0 comments on commit 417fabf

Please sign in to comment.