I am trying to implement an MQTT subscription client in a microcontroller using the eclipse paho mqttPacket library.
The mcu resets in the middle while receiving subscribed topics.
I am running a infinite loop delayed by 1 sec for publishing using python script, and for subscription I could get only 15 or 17 messages and the mcu resets.
I am using atmega328p. The mcu code is below
while(1){
rc = transport_getdata(buf);
if(rc == 0){ }
else if(rc < 0){
softuart_puts("closed");
goto stop;
}
else{
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]);
}
}
_delay_ms(1000);
}
stop: while(1);
The python script I am using to publish
publish.single(topic="test/relay", payload="sheep", qos=0, retain=False, hostname="128.199.179.240", port=1883, client_id="", keepalive=60, will=None, tls=None, auth={'username': 'XXXXX', 'password': 'XXXXX'}, protocol=mqtt.MQTTv311)