After updating the library this line started to fail
strcpy(customVar.name, mLastRedJsonObject["key"]);
where customVar is a struct where name field is
const char name[20];
Any idea why that is happening when reaching that line the esp8266 is resseting itself
Hi @mitko9000,
mLastRedJsonObject["key"] is probably null.
I bet that the DynamicJsonDocument is too small.
Unlike DynamicJsonBuffer, DynamicJsonDocument doesn't grow automatically; you need to pass the right capacity to the constructor.
BTW, your code would be much safer with:
strlcpy(customVar.name, mLastRedJsonObject["key"] | "", sizeof(customVar.name));
Best Regards,
Benoit
How can I calculate the size of the StaticJsonDocument<100> bytes I need for staticJsonDocument @bblanchon
To calculate the capacity of the JsonDocument, use the ArduinoJson Assitant.
@mitko9000, this is written virtually everywhere on the site, how did you miss it?
@bblanchon thanks for the feedback well my problem is resolved I had to move the StatisJsonDocument to public scope due to the fact I am reusing it, so this can be closed.
Maybe I missed it because I started using the library and reading the migration script but never actually visited the home page, never hurt to ask :D
Cool. Thanks for the update.