Debugging info added.
This commit is contained in:
Blaz Kristan 2021-11-14 16:56:34 +01:00
parent 85ded6e500
commit 312cbc86e9
16 changed files with 90 additions and 129 deletions

View File

@ -1089,14 +1089,11 @@ void WS2812FX::deserializeMap(uint8_t n) {
return; return;
} }
#ifdef WLED_USE_DYNAMIC_JSON #ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else #else
if (!requestJSONBufferLock()) { if (!requestJSONBufferLock(5)) return;
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!")); #endif
return;
}
#endif
DEBUG_PRINT(F("Reading LED map from ")); DEBUG_PRINT(F("Reading LED map from "));
DEBUG_PRINTLN(fileName); DEBUG_PRINTLN(fileName);

View File

@ -425,14 +425,11 @@ void deserializeConfigFromFS() {
return; return;
} }
#ifdef WLED_USE_DYNAMIC_JSON #ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else #else
if (!requestJSONBufferLock()) { if (!requestJSONBufferLock(1)) return;
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!")); #endif
return;
}
#endif
DEBUG_PRINTLN(F("Reading settings from /cfg.json...")); DEBUG_PRINTLN(F("Reading settings from /cfg.json..."));
@ -456,14 +453,11 @@ void serializeConfig() {
DEBUG_PRINTLN(F("Writing settings to /cfg.json...")); DEBUG_PRINTLN(F("Writing settings to /cfg.json..."));
#ifdef WLED_USE_DYNAMIC_JSON #ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else #else
if (!requestJSONBufferLock()) { if (!requestJSONBufferLock(2)) return;
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!")); #endif
return;
}
#endif
JsonArray rev = doc.createNestedArray("rev"); JsonArray rev = doc.createNestedArray("rev");
rev.add(1); //major settings revision rev.add(1); //major settings revision
@ -777,14 +771,11 @@ void serializeConfig() {
bool deserializeConfigSec() { bool deserializeConfigSec() {
DEBUG_PRINTLN(F("Reading settings from /wsec.json...")); DEBUG_PRINTLN(F("Reading settings from /wsec.json..."));
#ifdef WLED_USE_DYNAMIC_JSON #ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else #else
if (!requestJSONBufferLock()) { if (!requestJSONBufferLock(3)) return false;
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!")); #endif
return false;
}
#endif
bool success = readObjectFromFile("/wsec.json", nullptr, &doc); bool success = readObjectFromFile("/wsec.json", nullptr, &doc);
if (!success) { if (!success) {
@ -829,14 +820,11 @@ bool deserializeConfigSec() {
void serializeConfigSec() { void serializeConfigSec() {
DEBUG_PRINTLN(F("Writing settings to /wsec.json...")); DEBUG_PRINTLN(F("Writing settings to /wsec.json..."));
#ifdef WLED_USE_DYNAMIC_JSON #ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else #else
if (!requestJSONBufferLock()) { if (!requestJSONBufferLock(4)) return;
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!")); #endif
return;
}
#endif
JsonObject nw = doc.createNestedObject("nw"); JsonObject nw = doc.createNestedObject("nw");

View File

@ -1066,6 +1066,7 @@ function updateSelectedFx()
var parent = gId('fxlist'); var parent = gId('fxlist');
var selEffectInput = parent.querySelector(`input[name="fx"][value="${selectedFx}"]`); var selEffectInput = parent.querySelector(`input[name="fx"][value="${selectedFx}"]`);
if (selEffectInput) selEffectInput.checked = true; if (selEffectInput) selEffectInput.checked = true;
console.log(selEffectInput);
var selElement = parent.querySelector('.selected'); var selElement = parent.querySelector('.selected');
if (selElement) selElement.classList.remove('selected'); if (selElement) selElement.classList.remove('selected');

View File

@ -272,7 +272,7 @@ void sappends(char stype, const char* key, char* val);
void prepareHostname(char* hostname); void prepareHostname(char* hostname);
void _setRandomColor(bool _sec, bool fromButton); void _setRandomColor(bool _sec, bool fromButton);
bool isAsterisksOnly(const char* str, byte maxLen); bool isAsterisksOnly(const char* str, byte maxLen);
bool requestJSONBufferLock(); bool requestJSONBufferLock(uint8_t module=255);
void releaseJSONBufferLock(); void releaseJSONBufferLock();
//wled_eeprom.cpp //wled_eeprom.cpp

View File

@ -576,14 +576,11 @@ void decodeIRJson(uint32_t code)
JsonObject jsonCmdObj; JsonObject jsonCmdObj;
DEBUG_PRINTLN(F("IR JSON buffer requested.")); DEBUG_PRINTLN(F("IR JSON buffer requested."));
#ifdef WLED_USE_DYNAMIC_JSON #ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else #else
if (!requestJSONBufferLock()) { if (!requestJSONBufferLock(6)) return;
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!")); #endif
return;
}
#endif
sprintf_P(objKey, PSTR("\"0x%lX\":"), (unsigned long)code); sprintf_P(objKey, PSTR("\"0x%lX\":"), (unsigned long)code);

View File

@ -917,15 +917,12 @@ void serveJson(AsyncWebServerRequest* request)
return; return;
} }
#ifdef WLED_USE_DYNAMIC_JSON #ifdef WLED_USE_DYNAMIC_JSON
AsyncJsonResponse* response = new AsyncJsonResponse(JSON_BUFFER_SIZE); AsyncJsonResponse* response = new AsyncJsonResponse(JSON_BUFFER_SIZE);
#else #else
if (!requestJSONBufferLock()) { if (!requestJSONBufferLock(7)) return;
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!"));
return;
}
AsyncJsonResponse *response = new AsyncJsonResponse(&doc); AsyncJsonResponse *response = new AsyncJsonResponse(&doc);
#endif #endif
JsonObject lDoc = response->getRoot(); JsonObject lDoc = response->getRoot();

View File

@ -94,10 +94,7 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
#ifdef WLED_USE_DYNAMIC_JSON #ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else #else
if (!requestJSONBufferLock()) { if (!requestJSONBufferLock(8)) return;
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!"));
return;
}
#endif #endif
if (payload[0] == '{') { //JSON API if (payload[0] == '{') { //JSON API
deserializeJson(doc, payloadStr); deserializeJson(doc, payloadStr);

View File

@ -25,10 +25,7 @@ bool applyPreset(byte index, byte callMode)
#ifdef WLED_USE_DYNAMIC_JSON #ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else #else
if (!requestJSONBufferLock()) { if (!requestJSONBufferLock(9)) return false;
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!"));
return false;
}
#endif #endif
errorFlag = readObjectFromFileUsingId(filename, index, &doc) ? ERR_NONE : ERR_FS_PLOAD; errorFlag = readObjectFromFileUsingId(filename, index, &doc) ? ERR_NONE : ERR_FS_PLOAD;
@ -60,10 +57,7 @@ void savePreset(byte index, bool persist, const char* pname, JsonObject saveobj)
#ifdef WLED_USE_DYNAMIC_JSON #ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else #else
if (!requestJSONBufferLock()) { if (!requestJSONBufferLock(10)) return;
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!"));
return;
}
#endif #endif
sObj = doc.to<JsonObject>(); sObj = doc.to<JsonObject>();

View File

@ -418,10 +418,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
#ifdef WLED_USE_DYNAMIC_JSON #ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else #else
if (!requestJSONBufferLock()) { if (!requestJSONBufferLock(11)) return;
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!"));
return;
}
#endif #endif
JsonObject um = doc.createNestedObject("um"); JsonObject um = doc.createNestedObject("um");

View File

@ -131,15 +131,20 @@ bool isAsterisksOnly(const char* str, byte maxLen)
} }
bool requestJSONBufferLock() bool requestJSONBufferLock(uint8_t module)
{ {
unsigned long now = millis(); unsigned long now = millis();
while (jsonBufferLock && millis()-now < 1000) delay(1); // wait for a second for buffer lock while (jsonBufferLock && millis()-now < 1000) delay(1); // wait for a second for buffer lock
if (millis()-now >= 1000) return false; // waiting time-outed if (millis()-now >= 1000) {
DEBUG_PRINT(F("ERROR: Locking JSON buffer failed! ("));
DEBUG_PRINT(jsonBufferLock);
DEBUG_PRINTLN(")");
return false; // waiting time-outed
}
jsonBufferLock = true; jsonBufferLock = module ? module : 255;
fileDoc = &doc; // used for applying presets (presets.cpp) fileDoc = &doc; // used for applying presets (presets.cpp)
doc.clear(); doc.clear();
return true; return true;
@ -148,8 +153,11 @@ bool requestJSONBufferLock()
void releaseJSONBufferLock() void releaseJSONBufferLock()
{ {
#ifndef WLED_USE_DYNAMIC_JSON DEBUG_PRINT(F("JSON buffer released. ("));
DEBUG_PRINT(jsonBufferLock);
DEBUG_PRINTLN(")");
fileDoc = nullptr; fileDoc = nullptr;
jsonBufferLock = false; #ifndef WLED_USE_DYNAMIC_JSON
#endif jsonBufferLock = 0;
#endif
} }

View File

@ -606,7 +606,7 @@ WLED_GLOBAL UsermodManager usermods _INIT(UsermodManager());
#ifndef WLED_USE_DYNAMIC_JSON #ifndef WLED_USE_DYNAMIC_JSON
WLED_GLOBAL StaticJsonDocument<JSON_BUFFER_SIZE> doc; WLED_GLOBAL StaticJsonDocument<JSON_BUFFER_SIZE> doc;
#endif #endif
WLED_GLOBAL volatile bool jsonBufferLock _INIT(false); WLED_GLOBAL volatile uint8_t jsonBufferLock _INIT(0);
// enable additional debug output // enable additional debug output
#ifdef WLED_DEBUG #ifdef WLED_DEBUG

View File

@ -382,14 +382,11 @@ void deEEP() {
DEBUG_PRINTLN(F("Preset file not found, attempting to load from EEPROM")); DEBUG_PRINTLN(F("Preset file not found, attempting to load from EEPROM"));
DEBUGFS_PRINTLN(F("Allocating saving buffer for dEEP")); DEBUGFS_PRINTLN(F("Allocating saving buffer for dEEP"));
#ifdef WLED_USE_DYNAMIC_JSON #ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else #else
if (!requestJSONBufferLock()) { if (!requestJSONBufferLock(12)) return;
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!")); #endif
return;
}
#endif
JsonObject sObj = doc.to<JsonObject>(); JsonObject sObj = doc.to<JsonObject>();
sObj.createNestedObject("0"); sObj.createNestedObject("0");
@ -469,6 +466,7 @@ void deEEP() {
File f = WLED_FS.open("/presets.json", "w"); File f = WLED_FS.open("/presets.json", "w");
if (!f) { if (!f) {
errorFlag = ERR_FS_GENERAL; errorFlag = ERR_FS_GENERAL;
releaseJSONBufferLock();
return; return;
} }
serializeJson(doc, f); serializeJson(doc, f);

View File

@ -47,10 +47,7 @@ void handleSerial()
#ifdef WLED_USE_DYNAMIC_JSON #ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else #else
if (!requestJSONBufferLock()) { if (!requestJSONBufferLock(13)) return;
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!"));
return;
}
#endif #endif
Serial.setTimeout(100); Serial.setTimeout(100);
DeserializationError error = deserializeJson(doc, Serial); DeserializationError error = deserializeJson(doc, Serial);

View File

@ -114,16 +114,15 @@ void initServer()
#ifdef WLED_USE_DYNAMIC_JSON #ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else #else
if (!requestJSONBufferLock()) { if (!requestJSONBufferLock(14)) return;
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!"));
return;
}
#endif #endif
DeserializationError error = deserializeJson(doc, (uint8_t*)(request->_tempObject)); DeserializationError error = deserializeJson(doc, (uint8_t*)(request->_tempObject));
JsonObject root = doc.as<JsonObject>(); JsonObject root = doc.as<JsonObject>();
if (error || root.isNull()) { if (error || root.isNull()) {
request->send(400, "application/json", F("{\"error\":9}")); return; releaseJSONBufferLock();
request->send(400, "application/json", F("{\"error\":9}"));
return;
} }
const String& url = request->url(); const String& url = request->url();
isConfig = url.indexOf("cfg") > -1; isConfig = url.indexOf("cfg") > -1;

View File

@ -40,10 +40,7 @@ void wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventTyp
#ifdef WLED_USE_DYNAMIC_JSON #ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else #else
if (!requestJSONBufferLock()) { if (!requestJSONBufferLock(15)) return;
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!"));
return;
}
#endif #endif
DeserializationError error = deserializeJson(doc, data, len); DeserializationError error = deserializeJson(doc, data, len);
@ -120,10 +117,7 @@ void sendDataWs(AsyncWebSocketClient * client)
#ifdef WLED_USE_DYNAMIC_JSON #ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE); DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else #else
if (!requestJSONBufferLock()) { if (!requestJSONBufferLock(16)) return;
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!"));
return;
}
#endif #endif
JsonObject state = doc.createNestedObject("state"); JsonObject state = doc.createNestedObject("state");

View File

@ -256,10 +256,7 @@ void getSettingsJS(byte subPage, char* dest)
#ifdef WLED_USE_DYNAMIC_JSON #ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(2048); // 2k is enough for usermods DynamicJsonDocument doc(2048); // 2k is enough for usermods
#else #else
if (!requestJSONBufferLock()) { if (!requestJSONBufferLock(17)) return;
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!"));
return;
}
#endif #endif
JsonObject mods = doc.createNestedObject(F("um")); JsonObject mods = doc.createNestedObject(F("um"));