HTTP client Buffer size possible overflow

Hey,
I am having trouble using HttpClient library. I have set the buffer size to char buffer[15360]. I am requesting JSON objects which are roughly 4000 to 5000 chars long which then I will parse. after calling the http request 2-3 times the buffer seems to fill up as the httpclient gets stuck and eventually makes the controller unresponsive (i reset the controller after). Is there a way to clear the buffer everytime the request is called? I have seen a 2015 post about a similar issue which seems to have resolved it.

Side Question: Should i be using HTTPCLIENT for such big strings or should i use webhooks?

Kind Regards

I don’t know enough about the memory management in HttpClient library to tell you if what you are doing is feasible. Is your char buffer declared as global? It should be else the stack will be limited for anything else.

How are you parsing the JSON though? I can recommend @rickkas7’s JSON parser as it is pretty efficient in memory. If you are using ArduinoJSON library, I know that it forces you to declare a local variable every time you parse which can cause problems. The rickkas7’s library uses the existing, global, char buffer and just keeps track of the JSON elements within.

THanks for the reply. I played around with the some possibilities. I found that the buffer is actually Clearing. The problem is arising with the JSON parser i am using. I am using rickkas7 one (the one u highlighted). maybe my implementation of its is wrong.

Further Clarification:
my project requires me to use "get" function to retrieve info from api and then parse into ids which i use to call other get functions. I was supposedly having trouble with buffer after i had all the IDS. But when i used the get request with ID i put in normally it worked fine.

So it might be the Parser. But idk. I am using the dynamic parser from rick’s library. Got any tips on that?

If you are making multiple calls, do you have multiple char buffers in play at the same time? Either for JSON parsing or the HttpClient results?

No only 1 char buffer. All the calls including the one with IDs is written in JSON

It definitely sounds like a problem with the use of the buffers or memory in some way… do you want to post some code or share the project if using Web IDE?

are u suggesting that you need to use two different buffers for two different calls? I am unable to post code as this is being used for a company

I was thinking that instantiating multiple, large buffers for making HTTP requests AND then using a memory-inefficient JSON parser would leave too little memory available on the stack. You are already using @rickkas7’s JSON parser so that’s a good thing. Perhaps @ScruffR can suggest something more.

I am using the particle freemem function to see my memory available. It seems to have enough around 28000 bytes after the first api call. the second api is around 4000 bytes.

if this helps

  1. using HTTPClient to get a request. Result: String of ids with their associated names.

  2. parsing the info to get the ids

  3. user selects a specific id

  4. using that id to call a new http request

  5. parses the info and displays that id’s info.

problems seems to arrise around stage 4. where the request path and host name are correct but when i call a http.get(request,response, headers);
the p1 get stuck and after 20 second it restarts.

I think i found the culprit. line 270. when the .substring method is used , it only prints about 766 chars of data . when i print the raw_response, it gives the full result.