Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.84 KB | None | 0 0
  1. #include <Arduino.h>
  2. #include "WiFi.h"
  3. #include <WebServer.h>
  4. #include <ArduinoJson.h>
  5. #include <StreamUtils.h>
  6.  
  7. const char *ssid = "***";
  8. const char *password = "***";
  9.  
  10. WebServer server(80);
  11.  
  12. void largeJson();
  13. const int exampleCount = 90;
  14.  
  15. 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;
  16. DynamicJsonDocument example(capacity);
  17. 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\"]}";
  18. DynamicJsonDocument doc(capacity *exampleCount + exampleCount * 3);
  19.  
  20. void setup()
  21. {
  22.   Serial.begin(115200);
  23.   WiFi.begin(ssid, password);
  24.   while (WiFi.status() != WL_CONNECTED)
  25.   {
  26.     delay(500);
  27.     Serial.println("Connecting to WiFi..");
  28.   }
  29.   Serial.println("Connected to the WiFi network");
  30.   Serial.println("IP address: ");
  31.   Serial.println(WiFi.localIP());
  32.  
  33.   server.begin();
  34.   server.on("/large", largeJson);
  35.   deserializeJson(example, json);
  36.   for (int i = 0; i < exampleCount; i++)
  37.   {
  38.     doc["key" + i] = example;
  39.   }
  40. }
  41.  
  42. void loop()
  43. {
  44.   server.handleClient();
  45. }
  46.  
  47. void largeJson()
  48. {
  49.   WiFiClient client = server.client();
  50.   WriteBufferingStream bufferedWifiClient{client, 1024};
  51.   serializeJson(doc, bufferedWifiClient);
  52.   bufferedWifiClient.flush();
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement