mirror of
https://github.com/wled/WLED.git
synced 2025-07-19 08:46:34 +00:00
Bugfix.
Debugging info added.
This commit is contained in:
parent
85ded6e500
commit
312cbc86e9
@ -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);
|
||||
|
@ -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");
|
||||
|
||||
|
@ -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');
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
@ -94,10 +94,7 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
|
||||
#ifdef WLED_USE_DYNAMIC_JSON
|
||||
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);
|
||||
|
@ -25,10 +25,7 @@ bool applyPreset(byte index, byte callMode)
|
||||
#ifdef WLED_USE_DYNAMIC_JSON
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
#else
|
||||
if (!requestJSONBufferLock()) {
|
||||
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!"));
|
||||
return false;
|
||||
}
|
||||
if (!requestJSONBufferLock(9)) return false;
|
||||
#endif
|
||||
|
||||
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
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
#else
|
||||
if (!requestJSONBufferLock()) {
|
||||
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!"));
|
||||
return;
|
||||
}
|
||||
if (!requestJSONBufferLock(10)) return;
|
||||
#endif
|
||||
|
||||
sObj = doc.to<JsonObject>();
|
||||
|
@ -418,10 +418,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage)
|
||||
#ifdef WLED_USE_DYNAMIC_JSON
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
#else
|
||||
if (!requestJSONBufferLock()) {
|
||||
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!"));
|
||||
return;
|
||||
}
|
||||
if (!requestJSONBufferLock(11)) return;
|
||||
#endif
|
||||
|
||||
JsonObject um = doc.createNestedObject("um");
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -47,10 +47,7 @@ void handleSerial()
|
||||
#ifdef WLED_USE_DYNAMIC_JSON
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
#else
|
||||
if (!requestJSONBufferLock()) {
|
||||
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!"));
|
||||
return;
|
||||
}
|
||||
if (!requestJSONBufferLock(13)) return;
|
||||
#endif
|
||||
Serial.setTimeout(100);
|
||||
DeserializationError error = deserializeJson(doc, Serial);
|
||||
|
@ -114,16 +114,15 @@ void initServer()
|
||||
#ifdef WLED_USE_DYNAMIC_JSON
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
#else
|
||||
if (!requestJSONBufferLock()) {
|
||||
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!"));
|
||||
return;
|
||||
}
|
||||
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;
|
||||
|
@ -40,10 +40,7 @@ void wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventTyp
|
||||
#ifdef WLED_USE_DYNAMIC_JSON
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
#else
|
||||
if (!requestJSONBufferLock()) {
|
||||
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!"));
|
||||
return;
|
||||
}
|
||||
if (!requestJSONBufferLock(15)) return;
|
||||
#endif
|
||||
|
||||
DeserializationError error = deserializeJson(doc, data, len);
|
||||
@ -120,10 +117,7 @@ void sendDataWs(AsyncWebSocketClient * client)
|
||||
#ifdef WLED_USE_DYNAMIC_JSON
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
#else
|
||||
if (!requestJSONBufferLock()) {
|
||||
DEBUG_PRINTLN(F("ERROR: Locking JSON buffer failed!"));
|
||||
return;
|
||||
}
|
||||
if (!requestJSONBufferLock(16)) return;
|
||||
#endif
|
||||
|
||||
JsonObject state = doc.createNestedObject("state");
|
||||
|
@ -256,10 +256,7 @@ void getSettingsJS(byte subPage, char* dest)
|
||||
#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;
|
||||
}
|
||||
if (!requestJSONBufferLock(17)) return;
|
||||
#endif
|
||||
|
||||
JsonObject mods = doc.createNestedObject(F("um"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user