MQTT Delay between sending commands from adafruit io

Hey guys,
I am using an Arduino mega and a Sim 7000a modem, I am trying to send commands from adafruit io using MQTT while running other code from the Arduino, so for testing I am just running a counter that counts up to 1000 and resets and I want to be able to send commands to the modem to do stuff without it delaying my counter or stopping it. The problem I'm having is that whenever I send a command from adafruit io it halts my program that is already running and delays it and for the application I'll be using it for I cannot have the program halt at any time.I have been looking into the Adafruit_MQTT.h and cpp libraries used as I thought that would be the root of all my problems, I also tried removing any delays in the libraries as I thought it would help,but it only made it worse. Below I would attach my code, and both libraries I think could be causing the problem.

Adafruit_MQTT.cpp (23.3 KB)

Adafruit_MQTT.h (10.8 KB)

Adafruit_MQTT_FONA.h (4.25 KB)

testing_adafruitcommands.ino (8.33 KB)

What delays in milliseconds are you seeing?

What is this line trying to do?

while ((subscription = mqtt.readSubscription(5000))) {
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);

Using SoftwareSerial on a Mega (it has 4 hardware serial interfaces) is definitely a bad idea and might be responsible for some of the delays you're experiencing.

pylon:

SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);

Using SoftwareSerial on a Mega (it has 4 hardware serial interfaces) is definitely a bad idea and might be responsible for some of the delays you're experiencing.

What would you suggest I use??

mikb55:
What delays in milliseconds are you seeing?

What is this line trying to do?

while ((subscription = mqtt.readSubscription(5000))) {

This line is just how many seconds to wait for incoming subscription packets, I don't know if that makes any sense to you.

What would you suggest I use??

One of the three available hardware serial interfaces (Serial1, Serial2 or Serial3).