This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LAUNCHXL-CC3235S: parseJson() error - AWS sample_provisioning project

Part Number: LAUNCHXL-CC3235S

Hello,

I finally got my HTTPClient_Connect to work. I have a giant thread on getting that to work Here, however, it's likely not related to this problem.

I am now getting errors back from the parseJson() function. I have confirmed that my gateway API is working using postman. 
The buffer being passed into the function does appear to be the AWS Certificate used by my "thing". The length is 1192, which is less than the PROV_BUFFER_SIZE of my program.

Initially, I was parsing the JSON message with 5 tokens which was the default, but I had to increase this to 22. Now, it will pass the initial if(jsmn_parse()) line.

However, I cannot find a way to pass the second test, which is to succeed findToken() . When I dive into this function, the function fails because none of the Tokens are "objects". They are all of the type "Primative".

I've read about primatives, but I don't understand why all of the characters are being read as primatives. They are not NULL or BOOL, so I don't understand why the characters are being interpreted this way. Of course, I just read a little bit about them, so my understanding is far from comprehensive.


Now, I noticed that the tokens are going from Here->There, i.e. 0 to 10, but they all have a size of 0. I would expected 0->10 to have a size of 10. Something is wrong here, and it is preventing me from parsing my 'thing' AWS certificate.

Would someone mind lending a hand?

Thank you

  • Can you provide the json template that you are using and and the json buffer (hide/replace sensitive content) you are trying to parse?

  • Kobi,

    Thank you for your response. I don't know how I would find my JSON template. The JSON message is my Thing Certificate from AWS Core. I have confirmed that my device is being provisioned and the buffer containing the JSON response does match my certificate.

    The provisioning function is receiving the Body Response properly it seems. I tried researching JSON templates that AWS core would use, but I'm not sure how I did not find anything.

    The issue is that my parser returns null. Initially my parseJson() returned -1 because the findToken() function returned NULL. findToken() checks to see if token->type is OBJECT. Initially, all the token types were PRIMATIVE. I forced the types to be OBJECTS to satisfy it, but then it checks to see if token size is 0. Even if I comment that out, the size determines my iterations in the following loop.  Something fundamentally is flawed with this process, and the struct(s) are not being updated or satisfied in some way.

    I have uploaded one of my deactivated certs. It will be available for 7 days. Nothing is sensitive. Everything is purely for testing purposes.

    I am happy to do some digging or work on JSON template types, but I am not in a position to educate myself on how to answer your question properly. Thank you for any advice.

    Tom

  • You must create a template (Json_createTemplate) in order for the parser to work.

  • Thank you, this is very valuable. There’s nothing about this requirement in the project notes, so I did not know. 

    Would you care to point me to some documentation that I can reference to use the code you are talking about?

    Thank you. 

  • see <SDK_INSTALL_DIR>/docs/tiutils/html/group__ti__utils__json__JSON.html and the Json example in the SDK.

  • Thank you. 

    I resolved my issue. In Step 2 of the AWS Provisioning Project Guide, there are two potential AWS Lambdas that provision a device when given the csr. One of them returns a json.dump containing the Thing Certificate AND endpoint while the other simply returns the Thing certificate as a regular string. I am using the less complicated of the two (the iotcore provisioning method), so the POST Response Body is just the string, not a JSON payload.

    I will contact the main contributor of the CloudFormation / AWS via GitHub and ask them to modify the Lambda I'm using to match what is expected. I could use AWS CLI to find the endpoint manually, but I plan to mass produce these units, so it would be nice to automate it as expected.

    I appreciate your help. Hopefully this is my last ticket for AWS Provisioning project.