Skip to content
This repository has been archived by the owner on Jan 20, 2025. It is now read-only.

Update README.md for ArduinoJSON 6 #1135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mrengineer7777
Copy link

ESPAsyncWebServer library supports AJ6, but the examples in the readme have not been updated.

See https://arduinojson.org/v6/doc/upgrade/. There may be other changes necessary for AJ6.

See https://arduinojson.org/v6/doc/upgrade/

There may be other changes necessary for AJ 6.
@chess-levin
Copy link

chess-levin commented Feb 11, 2023

I'm trying to use your simple JSON response example with ArduinoJson 6.1 and can't compile. Is there a work around for this deprecation-issue ?

image

Ok, that callback works for me. I've used https://arduinojson.org/v6/doc/upgrade/ to find my solution.

void handleGetSensorInfo(AsyncWebServerRequest *request) {
	PRINTSLN("handleGetSensorInfo()");

	AsyncResponseStream *response = request->beginResponseStream(MIMETYPE_JSON);
	DynamicJsonDocument doc(128);

    doc[F("luxMeterOk")] = isLuxMeterOk();
	doc[F("lux")] = getLastLuxMeasuremen();
	doc[F("luxThresCount")] = getLuxThresCounter();
	doc[F("pir1")] = isIsPirOn(1);
	doc[F("pir2")] = isIsPirOn(2);

	serializeJsonPretty(doc, *response);
	request->send(response);
}

@mrengineer7777
Copy link
Author

@chess-levin Correct. You want to switch from JsonBuffer to JsonDocument. The dynamic part has been deprecated. DynamicJsonDocument is actually a fixed size. The only difference between Static and Dynamic is where the buffer is allocated.

See https://arduinojson.org/ "Fixed Memory Allocation".

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants