espressif / esp-aws-iot

AWS IoT SDK for ESP32 based chipsets
Apache License 2.0
266 stars 157 forks source link

Failed in parse JSON in shadow (CA-131) #49

Closed j-izaguirre closed 3 years ago

j-izaguirre commented 3 years ago

Hi,

I am trying to receive a shadow with the following in aws:

{ "desired": { "action": "on", "config": { "pages": [ { "buttons": [ { "functionality": 0, "color": "gray", "brightness": 7 }, { "functionality": 0, "color": "red", "brightness": 7 }, { "functionality": 0, "color": "blue", "brightness": 7 }, { "functionality": 0, "color": "magenta", "brightness": 7 }, { "functionality": 0, "color": "lime", "brightness": 7 }, { "functionality": 0, "color": "yellow", "brightness": 7 }, { "functionality": 0, "color": "cyan", "brightness": 7 }, { "functionality": 0, "color": "white", "brightness": 7 } ] } ] } }, "reported": { "connected": true, "version": { "mayor": 0, "minor": 0, "patch": 2, "tag": "dev" } }, "delta": { "action": "on", "config": { "pages": [ { "buttons": [ { "functionality": 0, "color": "gray", "brightness": 7 }, { "functionality": 0, "color": "red", "brightness": 7 }, { "functionality": 0, "color": "blue", "brightness": 7 }, { "functionality": 0, "color": "magenta", "brightness": 7 }, { "functionality": 0, "color": "lime", "brightness": 7 }, { "functionality": 0, "color": "yellow", "brightness": 7 }, { "functionality": 0, "color": "cyan", "brightness": 7 }, { "functionality": 0, "color": "white", "brightness": 7 } ] } ] } } }

but the app show warn with the message: aws_iot: Failed to parse JSON: -1 aws_iot: Received JSON is not valid

looking through the code, find that the warining message is send from the file aws_iot_shadow_json.c in the function isJsonValidAndParse() when you try to parse json doc with jsmn.

I printed the json doc received when the warning occurred and the message received was:

{"version":839,"timestamp":1618073884,"state":{"action":"on","config":{"pages":[{"buttons":[{"functionality":0,"color":"gray","brightness":7},{"functionality":0,"color":"red","brightness":7},{"functionality":0,"color":"blue","brightness":7},{"functionality":0,"color":"magenta","brightness":7},{"functionality":0,"color":"lime","brightness":7},{"functionality":0,"color":"yellow","brightness":7},{"functionality":0,"color":"cyan","brightness":7},{"functionality":0,"color":"white","brightness":7}]}]}},"metadata":{"action":{"timestamp":1618071704},"config":{"pages":[{"buttons":[{"functionality":{"timestamp":1618071721},"color":{"timestamp":1618071721},"brightness":{"timestamp":1618071721}},{"functionality":{"timestamp":1618071721},"color":{"timestamp":1618071721},"brightness":{"timestamp":1618071721}},{"functionality":{"timestamp":1618071721},"color":{"timestamp":1618071721},"brightness":{"timestamp":1618071721}},{"functionality":{"timestamp":1618071721},"color":{"timestamp":1618071721},"brightness":{"timestamp":1618071721}},{"functionality":{"timestamp":1618071721},"color":{"timestamp":1618071721},"brightness":{"timestamp":1618071721}},{"functionality":{"timestamp":1618071721},"color":{"timestamp":1618071721},"brightness":{"timestamp":1618071721}},{"functionality":{"timestamp":1618071721},"color":{"timestamp":1618071721},"brightness":{"timestamp":1618071721}},{"functionality":{"timestamp":1618071721},"color":{"timestamp":1618071721},"brightness":{"timestamp":1618071721}}]}]}},"clientToken":"ThingFab01-0"}

I dont know why the parse json failed? i checked the json and everything looks fine.

Any idea what the problem may be?

Thanks.

j-izaguirre commented 3 years ago

The problem was the Maximum Expected JSON tokens value, in Thing Shadow config, Increase this value solve the problem. Thanks anyway.