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;
}
#ifdef WLED_USE_DYNAMIC_JSON
#ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else
if (!requestJSONBufferLock()) {
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!"));
return;
}
#endif
#else
if (!requestJSONBufferLock(5)) return;
#endif
DEBUG_PRINT(F("Reading LED map from "));
DEBUG_PRINTLN(fileName);

View File

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

View File

@ -1066,6 +1066,7 @@ function updateSelectedFx()
var parent = gId('fxlist');
var selEffectInput = parent.querySelector(`input[name="fx"][value="${selectedFx}"]`);
if (selEffectInput) selEffectInput.checked = true;
console.log(selEffectInput);
var selElement = parent.querySelector('.selected');
if (selElement) selElement.classList.remove('selected');
@ -1106,7 +1107,7 @@ function makeWS() {
jsonTimeout = null;
lastUpdate = new Date();
clearErrorToast();
gId('connind').style.backgroundColor = "var(--c-l)";
gId('connind').style.backgroundColor = "var(--c-l)";
// json object should contain json.info AND json.state (but may not)
var i = json.info;
if (i) {

View File

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

View File

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

View File

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

View File

@ -92,12 +92,9 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
} else if (strcmp_P(topic, PSTR("/api")) == 0) {
DEBUG_PRINTLN(F("MQTT JSON buffer requested."));
#ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else
if (!requestJSONBufferLock()) {
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!"));
return;
}
if (!requestJSONBufferLock(8)) return;
#endif
if (payload[0] == '{') { //JSON API
deserializeJson(doc, payloadStr);

View File

@ -22,14 +22,11 @@ bool applyPreset(byte index, byte callMode)
deserializeState(fdo, callMode, index);
} else {
DEBUG_PRINTLN(F("Apply preset JSON buffer requested."));
#ifdef WLED_USE_DYNAMIC_JSON
#ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else
if (!requestJSONBufferLock()) {
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!"));
return false;
}
#endif
#else
if (!requestJSONBufferLock(9)) return false;
#endif
errorFlag = readObjectFromFileUsingId(filename, index, &doc) ? ERR_NONE : ERR_FS_PLOAD;
JsonObject fdo = doc.as<JsonObject>();
@ -57,14 +54,11 @@ void savePreset(byte index, bool persist, const char* pname, JsonObject saveobj)
if (!fileDoc) {
DEBUG_PRINTLN(F("Save preset JSON buffer requested."));
#ifdef WLED_USE_DYNAMIC_JSON
#ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else
if (!requestJSONBufferLock()) {
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!"));
return;
}
#endif
#else
if (!requestJSONBufferLock(10)) return;
#endif
sObj = doc.to<JsonObject>();
if (pname) sObj["n"] = pname;

View File

@ -415,14 +415,11 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
//USERMODS
if (subPage == 8)
{
#ifdef WLED_USE_DYNAMIC_JSON
#ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else
if (!requestJSONBufferLock()) {
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!"));
return;
}
#endif
#else
if (!requestJSONBufferLock(11)) return;
#endif
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();
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)
doc.clear();
return true;
@ -148,8 +153,11 @@ bool requestJSONBufferLock()
void releaseJSONBufferLock()
{
#ifndef WLED_USE_DYNAMIC_JSON
DEBUG_PRINT(F("JSON buffer released. ("));
DEBUG_PRINT(jsonBufferLock);
DEBUG_PRINTLN(")");
fileDoc = nullptr;
jsonBufferLock = false;
#endif
#ifndef WLED_USE_DYNAMIC_JSON
jsonBufferLock = 0;
#endif
}

View File

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

View File

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

View File

@ -44,14 +44,11 @@ void handleSerial()
else if (next == '{') { //JSON API
bool verboseResponse = false;
DEBUG_PRINTLN(F("Serial JSON buffer requested."));
#ifdef WLED_USE_DYNAMIC_JSON
#ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else
if (!requestJSONBufferLock()) {
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!"));
return;
}
#endif
#else
if (!requestJSONBufferLock(13)) return;
#endif
Serial.setTimeout(100);
DeserializationError error = deserializeJson(doc, Serial);
if (error) {

View File

@ -111,19 +111,18 @@ void initServer()
bool isConfig = false;
{ //scope JsonDocument so it releases its buffer
DEBUG_PRINTLN(F("HTTP JSON buffer requested."));
#ifdef WLED_USE_DYNAMIC_JSON
#ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else
if (!requestJSONBufferLock()) {
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!"));
return;
}
#endif
#else
if (!requestJSONBufferLock(14)) return;
#endif
DeserializationError error = deserializeJson(doc, (uint8_t*)(request->_tempObject));
JsonObject root = doc.as<JsonObject>();
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();
isConfig = url.indexOf("cfg") > -1;

View File

@ -36,15 +36,12 @@ void wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventTyp
}
bool verboseResponse = false;
{ //scope JsonDocument so it releases its buffer
DEBUG_PRINTLN(F("WS JSON receive buffer requested."));
#ifdef WLED_USE_DYNAMIC_JSON
DEBUG_PRINTLN(F("WS JSON receive buffer requested."));
#ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else
if (!requestJSONBufferLock()) {
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!"));
return;
}
#endif
#else
if (!requestJSONBufferLock(15)) return;
#endif
DeserializationError error = deserializeJson(doc, data, len);
JsonObject root = doc.as<JsonObject>();
@ -116,15 +113,12 @@ void sendDataWs(AsyncWebSocketClient * client)
AsyncWebSocketMessageBuffer * buffer;
{ //scope JsonDocument so it releases its buffer
DEBUG_PRINTLN(F("WS JSON send buffer requested."));
#ifdef WLED_USE_DYNAMIC_JSON
DEBUG_PRINTLN(F("WS JSON send buffer requested."));
#ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else
if (!requestJSONBufferLock()) {
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!"));
return;
}
#endif
#else
if (!requestJSONBufferLock(16)) return;
#endif
JsonObject state = doc.createNestedObject("state");
serializeState(state);

View File

@ -253,14 +253,11 @@ void getSettingsJS(byte subPage, char* dest)
// add reserved and usermod pins as d.um_p array
oappend(SET_F("d.um_p=[6,7,8,9,10,11"));
#ifdef WLED_USE_DYNAMIC_JSON
#ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(2048); // 2k is enough for usermods
#else
if (!requestJSONBufferLock()) {
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!"));
return;
}
#endif
#else
if (!requestJSONBufferLock(17)) return;
#endif
JsonObject mods = doc.createNestedObject(F("um"));
usermods.addToConfig(mods);