Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Hasenradball
    @hasenradball
    Hi Benoit I have one question regarding to your book page 64. You describe create json document, parse json data, destroy json document to free memory.
    but how to destroy the document? If it is in a function is it automatically destroyed as local variables?
    Benoît Blanchon
    @bblanchon
    Hi @hasenradball, yes, it is destroy when it goes out of scope.
    (and thanks for purchasing the book ;-)
    luisgcu
    @luisgcu
    Very good book @bblanchon I bought last year, we use your arduino Json library a lot in our Iot project with ESP32.
    Hasenradball
    @hasenradball
    @bblanchon
    Thanks for writing such a book! 😀
    It is destroyed imdependently if using a dynamic or static buffer?
    Hasenradball
    @hasenradball
    @bblanchon Hi Benoit I tried to change my Code from V5 to V6 but I have some issue.
    could You please have a short look?
    The V5 Code looks like:
    
    void sendMessageJson(bool wlan_user_req) {
      // --> Funktion zum Senden der Daten an die Webside
      String json_str;
      json_str.reserve(500);
    
      const size_t capacity = JSON_OBJECT_SIZE(12) + 250;
      DynamicJsonBuffer jsonBuffer(capacity);
      JsonObject& root = jsonBuffer.createObject();
    
      root["version"] = version;
      root["WLAN_USER_INPUT_Requested"] = wlan_user_req;
      root["MAC"] = WiFi.macAddress();
      root["Hostname"] = IO.getHost();
      root["SSID"] = IO.getSSID();
      root["Password"] = IO.getPasswd();
      root["Schwellwert"] = IO.getSchwelle();
      root["Min"] = IO.getMin();
      root["Max"] = IO.getMax();
      root["ADC"] = PT1.Read_ADC();
      root["PT1"] = PT1.get_Y();
      root["Sprache"] = IO.getSprache();
    
      root.printTo(json_str);
      //root.printTo(Serial);
      // wichtig! damit Daten nicht aus dem Browser cache kommen
      server.sendHeader("Cache-Control", "no-cache");
      server.send(200, "application/json", json_str);
    }
    and the V6 Code looks like:
    void sendMessageJson(bool wlan_user_req) {
      // --> Funktion zum Senden der Daten an die Webside
      char json_str[500];
    
      const size_t capacity = JSON_OBJECT_SIZE(12);
      // Reserve Static Buffer -> Stack
      StaticJsonDocument<capacity> doc;
    
      doc["version"] = version;
      doc["WLAN_USER_INPUT_Requested"] = wlan_user_req;
      doc["MAC"] = WiFi.macAddress();
      doc["Hostname"] = IO.getHost();
      doc["SSID"] = IO.getSSID();
      doc["Password"] = IO.getPasswd();
      doc["Schwellwert"] = IO.getSchwelle();
      doc["Min"] = IO.getMin();
      doc["Max"] = IO.getMax();
      doc["ADC"] = PT1.Read_ADC();
      doc["PT1"] = PT1.get_Y();
      doc["Sprache"] = IO.getSprache();
    
      serializeJson(doc, json_str);
      //serializeJson(doc, Serial);
      // wichtig! damit Daten nicht aus dem Browser cache kommen
      server.sendHeader("Cache-Control", "no-cache");
      server.send(200, "application/json", json_str);
    }
    Hasenradball
    @hasenradball
    The char looks like {"version":"v21.10.4","WLAN_USER_INPUT_Requested":false,"MAC":"84:0D:8E:AA:87:B0","Hostname":"clock","SSID":"yyyyyyyyy","Password":"vvvvvvvv","Schwellwert":1000,"Min":0}
    There are missing some values
    From the Assistant it looks like:
    const size_t capacity = JSON_OBJECT_SIZE(12);
    DynamicJsonDocument doc(capacity);
    
    doc["version"] = "v23.1.1.2.3";
    doc["WLAN_USER_INPUT_Requested"] = true;
    doc["MAC"] = "DF:4F:22:11:0E:59";
    doc["Hostname"] = "123456789101112131415161718192021222324252627282930";
    doc["SSID"] = "12345678910111213141516171819202122232425262728293";
    doc["Password"] = "123456789101112131415161718192021222324252627282930";
    doc["Schwellwert"] = 1023;
    doc["Min"] = 255;
    doc["Max"] = 255;
    doc["ADC"] = 1023;
    doc["PT1"] = 1023;
    doc["Sprache"] = 1;
    
    serializeJson(doc, Serial);
    Hasenradball
    @hasenradball
    It ist programed in the ESP8266
    Hasenradball
    @hasenradball
    The same Issue with the Dynamic Buffer.
    Is the Problem the char instead the String?
    Benoît Blanchon
    @bblanchon
    @hasenradball One of the major different between ArduinoJson 5 and 6 is that DynamicJsonBuffer automatically grows when full, whereas DynamicJsonDocument doesn't
    To fix your program, simply increase the capacity of the DynamicJsonDocument
    Use the ArduinoJson Assistant to compute the capacity
    Hasenradball
    @hasenradball
    @bblanchon
    Thank you for your help, i used the assistant to caclulate the doc size, but it does not match.
    Hasenradball
    @hasenradball
    Maybe is there some issue in the Assistant when caclulating the right buffer size? with the above example the assistant calculates jsonObjectSize(12) for Serialization but it seems to be to low.
    mars000
    @mars000
    image.png
    Hi - I'm using latest version for ArduinoJason 6.10.1 ... for some reason when I do a serailizeJsonPretty as per attached below it does not fully display the JSON to the serial...rather an incomplete version of the json. I don't know why -- any clues ?
    image.png
    this is the output int he serial:
    Hasenradball
    @hasenradball
    Please check your braces
    @mars000 your braces looks imcomplete.
    Hasenradball
    @hasenradball

    @bblanchon for this input the assistant calculates:

    {
      "version": "v23.1.1.2.3",
      "WLAN_USER_INPUT_Requested": true,
      "MAC": "DF:4F:22:11:0E:59",
      "Hostname": "123456789101112131415161718192021222324252627282930",
      "SSID": "12345678910111213141516171819202122232425262728293",
      "Password": "123456789101112131415161718192021222324252627282930",
      "Schwellwert": 1023,
      "Min": 255,
      "Max": 255,
      "ADC": 1023,
      "PT1": 1023,
      "Sprache": 1
    }

    JSON_OBJECT_SIZE(12) for Serialization but it is not enough.

    Hasenradball
    @hasenradball
    @bblanchon what does JSON_OBJECT_SIZE(12) mean in bytes?
    mars000
    @mars000
    @hasenradball the output is incomplete because that the error i'm reporting; as you can see from the output arduinojson successfully parses the file but fails to print it out on the screen fully for some reason
    Hasenradball
    @hasenradball
    Ok
    mars000
    @mars000
    @hasenradball I found the problem it seems. Everything renders ok when I reduce serial down to 115200 baud on my ESP32 but when I have it at 2,000,000 baud the serializeJsonPretty(doc, Serial); can't seem to keep up and the text is all garbled @bblanchon is this a known issue or something you have seen in the past [I'm using latest V6 library] ?
    Fernando
    @ferchinas

    Hello:
    I make a query out of topic.
    Anyone know any tool to programmatically minify .json files, which are in a folder on my pc, and paste them into arduino code variables?

    const char VarName[] = R "V0G0N (MINIFIED_JSON_FILE_HERE) V0G0N";

    I already tried to do it with Grunt but without success.
    Thank you

    Alexandr Zarubkin
    @me21
    Did you mean removing whitespaces and line breaks?
    Fernando
    @ferchinas
    @me21 Yes, that's what I mean, I have several json configuration files and I wanted to run some routine that takes spaces and line breaks to each one and inserts each one in each variable defined in a header file. To then compile and deploy the new firmware version.
    Alexandr Zarubkin
    @me21
    I think you can insert another file's contents with preprocessor #include directive
    As for transforming json, try jq: https://stedolan.github.io/jq/
    Fernando
    @ferchinas
    I'm writing the script in PowerShell and minifying with jq, @me21 Thank you very much !!!
    spencer1979
    @spencer1979
    Hi. Is it for nonarduino
    Nathan-ma
    @Nathan-ma
    Guys I need a quick help here!
    Im trying to pass a staticjsonobject as a function parameter with no success
    I’m just declaring a
    staticjsondocument<2048> doc both on my setup and on my function parameter
    It’s that how I was suppose to do?
    Alexandr Zarubkin
    @me21
    I'm not sure if it will avoid copying the data. Perhaps const reference instead of passing by value would work better
    Pratikm78
    @Pratikm78
    HI. How do i clear/destroy the entire json document?
    Hasenradball
    @hasenradball
    Hi benoit is there anything to consider when updating to the latest version v6?
    Benoît Blanchon
    @bblanchon
    @hasenradball , I wrote an article about it: https://arduinojson.org/2019/09/05/version-6-12-0/
    Hasenradball
    @hasenradball
    Thank you I will have a look :-)