Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include "WiFi.h"
- #include <WebServer.h>
- #include <ArduinoJson.h>
- #include <StreamUtils.h>
- const char *ssid = "***";
- const char *password = "***";
- WebServer server(80);
- void largeJson();
- const int exampleCount = 90;
- const size_t capacity = 11 * JSON_ARRAY_SIZE(1) + 10 * JSON_OBJECT_SIZE(0) + JSON_OBJECT_SIZE(1) + 2 * JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(4) + JSON_OBJECT_SIZE(5) + JSON_OBJECT_SIZE(8) + JSON_OBJECT_SIZE(13) + 310;
- DynamicJsonDocument example(capacity);
- const char *json = "{\"ieeeAddr\":\"000D6F001336867C\",\"last_seen\":\"1581928963\",\"type\":\"Router\",\"powerSource\":\"Main\",\"Interview\":{\"TS\":0,\"State\":4},\"ep\":{\"1\":{\"profId\":260,\"In\":{\"0\":[{}],\"1\":[{}],\"3\":[{}],\"4\":[{}],\"9\":[{}],\"1280\":[{}],\"1282\":[{}],\"65530\":[{}]},\"Out\":{\"3\":[{}],\"25\":[{}]},\"devId\":1027}},\"ManufName\":\"GS\",\"ModelId\":\"SRHMP-I1\",\"st\":{\"linkquality\":76,\"trSeqNum\":24,\"warning\":\"\",\"battery\":100,\"voltage\":4.1},\"supported\":1,\"friendly_name\":\"sirena\",\"Rcf\":true,\"Rtg\":[\"35282\"]}";
- DynamicJsonDocument doc(capacity *exampleCount + exampleCount * 3);
- void setup()
- {
- Serial.begin(115200);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED)
- {
- delay(500);
- Serial.println("Connecting to WiFi..");
- }
- Serial.println("Connected to the WiFi network");
- Serial.println("IP address: ");
- Serial.println(WiFi.localIP());
- server.begin();
- server.on("/large", largeJson);
- deserializeJson(example, json);
- for (int i = 0; i < exampleCount; i++)
- {
- doc["key" + i] = example;
- }
- }
- void loop()
- {
- server.handleClient();
- }
- void largeJson()
- {
- WiFiClient client = server.client();
- WriteBufferingStream bufferedWifiClient{client, 1024};
- serializeJson(doc, bufferedWifiClient);
- bufferedWifiClient.flush();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement