Mqtt publish to thingspeak without arduino library

This sketch will mqtt publish to thingspeak using the SARA built-in mqtt AT commands. All AT commands are sent in a fashion that allows the main loop to do other things while the response is received. Each AT command is sent with a timeout. If more than 20 timeouts happen in a row, the modem is hard reset.

I am using the latest version firmware on the SARA R4, so I am not sure if this would work with the older versions...

I have found that the modem can lock up in low signal environments when trying to establish the mqtt connection...

//Code removed, transitioned to http post. 

I have abandoned Mqtt in favor of using TLS sockets and HTTP post to update thingspeak. I have found the ublox built-in Mqtt commands lacking and unstable.

Thanks for sharing your findings with MQTT on the modem. I'm having problems with the Arduino library but guess I'll continue trying to get it to work. By the way thanks for the detailed instructions for updating the firmware in the firmware update topic. Even this old man was able to easily do the update.