This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Issue in publishing and receiving more than one character using MQTT

Hello everyone,

I have been using nrf52 IoT SDK for MQTT implementation. Everything works fine as long as I am publishing or receiving only one character i.e.

param.message.payload.bin_strlen = 1;

inside app_mqtt_publish. When I try to change to

param.message.payload.p_bin_str = (uint8_t *)&ascii_msg,

param.message.payload.bin_strlen = 25;

where ascii_msg is uint8_t, I get the following issues. I am trying to publish a string "HELLO" and I am receiving it as "ON �J���" on the other end. It seems like only the last character is published along with " �J���". Can anyone please tell me where else do I need to make changes apart from string length to make it work? Similar issue happens when I try to receive something on a subscribed topic. I get garbage data instead of the actual one. Thanks for the help.

UPDATE : I was able to rectify the issue by changing the function definition having character pointer argument like this:

app_mqtt_publish(char * led_state). Now the only issue remaining is that I am getting garbage data when I want to receive a string instead of one character on the subscribed topics. Any help is appreciated.

Related