Single json buffer (#2336)

* Single/static JSON buffer for all requests.

* Missing json.cpp changes.

* Async fix.

* Added conditional compile (WLED_USE_DYNAMIC_JSON).

* Advanced locking with time-out.

* Missing releaseJSONBufferLock() on error response.

* Fix for config saving.

* Fixes and optimisations.
Dadded debugging information.

* Fix for ledmaps.

* No unsolicited serial sending if GPIO1 allocated

* Stray semicolons

* Fix JSON ledmap

Co-authored-by: Blaz Kristan <blaz@kristan-sp.si>
This commit is contained in:
Christian Schwinne
2021-12-04 01:05:01 +01:00
committed by GitHub
parent 46ec504743
commit 66bad2b6f8
18 changed files with 272 additions and 91 deletions

View File

@@ -48,18 +48,21 @@ void handleSerial()
Serial.print("WLED"); Serial.write(' '); Serial.println(VERSION);
} else if (next == '{') { //JSON API
bool verboseResponse = false;
{
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
Serial.setTimeout(100);
DeserializationError error = deserializeJson(doc, Serial);
if (error) return;
fileDoc = &doc;
verboseResponse = deserializeState(doc.as<JsonObject>());
fileDoc = nullptr;
#ifdef WLED_USE_DYNAMIC_JSON
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
#else
if (!requestJSONBufferLock(16)) return;
#endif
Serial.setTimeout(100);
DeserializationError error = deserializeJson(doc, Serial);
if (error) {
releaseJSONBufferLock();
return;
}
verboseResponse = deserializeState(doc.as<JsonObject>());
//only send response if TX pin is unused for other purposes
if (verboseResponse && !pinManager.isPinAllocated(1)) {
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
doc.clear();
JsonObject state = doc.createNestedObject("state");
serializeState(state);
JsonObject info = doc.createNestedObject("info");
@@ -68,6 +71,7 @@ void handleSerial()
serializeJson(doc, Serial);
Serial.println();
}
releaseJSONBufferLock();
}
break;
case AdaState::Header_d: