I’ve started to use Amazon FreeRTOS with the nxp OM40007 platform and have successfully followed the tutorial and got the echo demo to work.
I’m now trying to develop my own very simple examples to be more familiar with the libraries.
I’ve created a topic, and got my device to subscribe to it. I am sending a message from the AWS web console, and I want my device to receive it.
Topic name: dw/receive_answer
Message: “test”
When I look at the pxPublishParameters structure to retrieve the topic name, the value is wrong, it corresponds to the topic name appended to my message. See below for detail :
configPRINTF(("TOPIC CLIENT : ‘%s’\r
", echoTOPIC_NAME)); // Name of my topic
-> TOPIC CLIENT : ‘dw/receive_answer’
The pxPublishParameters structure fields pucTopic and pvData are not NULL terminated so you can’t use configPRINTF to display them.
When you do, it will continue past the end of the string and continue to print characters until ‘\0’ is encountered.
That pointed us to a bug in one of our examples, below, where we are making a similar mistake. We’re working on a fix. Thank you for drawing this to our attention.
In aws_hello_world.c, line 377
/* Don’t expect the callback to be invoked for any other topics. */
configASSERT( strcmp( ( const char * ) pxPublishParameters->pucTopic, ( const char * ) echoTOPIC_NAME ) == 0 );
The length of the topic is available in the same structure in usTopicLength and ulDataLength.
A better way of handling this would be:
/* Don’t expect the callback to be invoked for any other topics. */
configASSERT( strncmp( ( const char * ) pxPublishParameters->pucTopic, ( const char * ) echoTOPIC_NAME, pxPublishParameters->usTopicLength ) == 0 );
To be able to printf, the best way would be to copy the string in a buffer using strncpy