EDIT: SOLVED. Put client.connect() in setup and have it called just once instead of every time.
I'm working on a wireless sensor node that sends data to a ethernet connected gateway arduino. This gateway Arduino sends MQTT messages to a MQTT broker (Mosquitto). As I'm monitoring MQTT messages, I'm seeing long delays between when sendMQTT = 1 and when the MQTT messages are actually posted. It's because on many (most?) of the loop, client.connect() is returning false. So many loops go by before the microcontroller actually sends the MQTT message even though the data arrived as much as 15 seconds ago.
I'm not sure why this is happening. I'm don't have an understanding of what client.connect() is actually doing though. The ethernet sheild connects to the router via static IP address, as far as I know, there's not too much traffic on the network to confuse things.
Maybe someone with more knowledge of this library can shed some light on things?
sendMQTT = 1;
haveData = false;
} // end if haveData
if (sendMQTT == 1)
dtostrf (SensorNode.var2_float, 4, 1, buff_message);
sendMQTT = 0;
}//end if sendMQTT
if ((millis() - keepalivetime)>15000)
keepalivetime = millis();
} // end of loop