Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[paho-dev] subscribe and publish using mqttpacket library in atmega328p

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);

Back to the top