I am developing application with ESP IDF where I am also using the Aws IOT Embedded C SDK. The problem is that I wrote few lines to form String of the MQTT Subscribe topic based of client ID. I do following operation to construct string of Subscription Topic:
Code: Select all
ret_data ret;
char clientid[16];
//this returns Client ID from flash
ret = get_topic();
//Copy Client ID value From ret data package to clientid string.
strncpy(clientid, ret.string, ret.len);
//Print Data and properties of clientid string after data is copied
printf("client ID from Flash : %s \n", clientid);
printf("client id Len : %d\n",ret.len);
//Append string "/sub" in Clientid string.
strncat(clientid,"/sub", strlen(clientid));
//print it After concatenation is done
printf("client ID After Concat : %s \n", clientid);
//assign to const Char string
char* stopic = clientid;
printf("%s\n",stopic);
//pass it to the subscribe function
rc = aws_iot_mqtt_subscribe(&awsclient, stopic, strlen(stopic), QOS0, iot_subscribe_callback_handler, NULL);
When I assign Value directly to ClientId like "test/sub" It works but when I do operations on string as described above esp32 doesn't print data when i send it from AWS Console on that evaluated topic.
Can anyone please give explanation that why it can happen.
Thanks.