Handle webhook chunks. How to know end?

I have a call into openweathermap for sun rise and sun set, … my issue is to get all of this data, my return data is sometimes bigger than 512 bytes. I tried setting chunking to false, to get 520 bytes down, but setting that flag seems to shut it off, ie the callback is not called. My data is json and is variable in length. How do I know when it is done? Today, I say if strlen is 512 then add it to a buffer and wait for another callback. it works mostly but what if the data is exactly 512? Do I really need to parse the data for the ending (200)… Or is there a way to know another chunk is coming?

If you disable chunking, make sure your on-device subscription event prefix does not end with a slash. Because there are no chunk numbers, the event name will just be the response topic name.

There is no way to know that you've reached the last chunk. However, if the data is JSON, you can tell becuse the data will be valid JSON, and that's the recommended way to handle it.

Also note that response chunks may arrive out of order, so make sure you account for that as well.

Thanks. Seems like a hack but makes sense, run a JSON parser, let if fail and now you know it not the last pack; unless the JSON is corrupt, then you are stuck. So, set a timer, to work around a parsing error…