Hi,
the first thing I would do is check the return length from
MQTTSerialize_publish(). If it's negative, then there has been a
failure - one case of which would be that the buffer field would
overflow (payload + topic is too long).
Ian
On 06/29/2016 05:53 PM, Kenosys
Embedded Solutions wrote:
Hi,
I am trying to subscribe and publish messages using
atmega328p. I am using pub0sub1.c sample from the mqttpacket
library. Everytime i run this code, i see 2 or 3 messages
published and subscribed and then the microcontroller hangs or
resets. I have added my code snippet below.
while(1){
rc = transport_getdata(buf);
if(rc > 0){
flen=buf[1]-48;
paylen=buf[3]-48;
for(i=4;i<14;i++){
softuart_putchar(buf[i]);
}
for(i=14;i<rc;i++){
softuart_putchar(buf[i]);
}
}
else if(rc < 0){
softuart_puts("closed");
goto stop;
}
else{
len = MQTTSerialize_publish(buf, buflen,
0, 0, 0, 0, topicString, (unsigned char*)payload, payloadlen);
send_tcp(buf,len);
transport_getdata(buf);
}
_delay_ms(1000);
}
stop: while(1);
_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/paho-dev
--
Ian Craggs
icraggs@xxxxxxxxxx IBM United Kingdom
Paho Project Lead; Committer on Mosquitto
|