AWS Topic Subscription issue

naitik
Posts: 19
Joined: Thu Apr 22, 2021 2:04 pm

AWS Topic Subscription issue

Postby naitik » Tue May 11, 2021 7:57 am

Hello,
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);
The Serial Monitor Shows String of Subscription topic Correctly even when i print the String with function esp_log_buffer_hex() I see Correct set of characters but this approach does not work when i pass this string in aws_iot_mqtt_subscribe() Funciton.

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.

Who is online

Users browsing this forum: No registered users and 118 guests