Problems connecting arduino with MQTT server

Hi Everyone

We are building a robot that has an Arduino DUE which can power it on or off.

The DUE is connected to an ENC28J60-H ethernet microcontroller that is connected to a Cradlepoint. We are using UIPEthernet library for Ethernet.

The Cradlepoint connects to an MQTT server hosted via AWS on shiftr.io (https://shiftr.io/)

We are using a MQTT client library for the arduino to connect to the MQTT server and back, the PubSubClient library

It is documented in the github page of this library that it is not compatible with the ENC28J60 series microcontrollers.

However, we are able to connect to the MQTT library and talk to it via a Slack channel connected to the AWS MQTT server. The problem is however stability. The connection breaks suddenly and sometimes the messages sent to the arduino via the slack channel breaks it. Most importantly, when I use the String library of Arduino, it causes "Invalid Topic" error on the Shiftr.io dashboard. Even when I use C arrays, the same problem occurs. It is very difficult to know why it is happening. The internet connection via Cradlepoint is working fine.

Sometimes, adding Serial.println() statements makes it work, sometimes removing unrelated code makes the arduino stop working.

Did anybody face string related issues with pubsubclient library or even on Arduino Due? I also used the arduino MQTT client library (GitHub - 256dpi/arduino-mqtt: MQTT library for Arduino) but it does not apparently work with the Due or the ethernet library.

If anybody could provide pointers to why I am facing instability issues, that would be of big help. I have no way of diagnosing why this is happening except think of memory issues but the Due has lots of memory. Thanks.