Any MQTT experts out there? Argon will not stay connected to MQTT on rPi

Hi All,

I need to troubleshoot MQTT on an Argon device. I’m using a local MQTT broker on a Raspberry Pi, that is working fine with other clients (on a Mac, an ESP32, and an iphone), but will not maintain communication with an Argon.

The other clients in the network will work for over 24 hours, no problem (which is long enough), but the Argon can’t receive or publish a message after just a few minutes (but it works fine up until the time that it doesn’t…).

The code is below:
I’d appreciate any help in understanding what I need to do to view logs, etc to try to understand why this unit doesn’t keep a connection when other devices do.

btw - I put in a Particle.disconnect() at the end of setup because the internet is intermittent, and I want that out of the equation.

The code is a slightly modified version of mqtttest.ino example from the library.

#include "MQTT.h"

void callback(char* topic, byte* payload, unsigned int length);

 * if want to use IP address,
 * byte server[] = { XXX,XXX,XXX,XXX };
 * MQTT client(server, 1883, callback);
 * want to use domain name,
 * exp) is Eclipse Open MQTT Broker:
 * MQTT client("", 1883, callback);
byte server[] = { 10,240,140,72 };
MQTT client(server, 1883, callback);

// recieve message
void callback(char* topic, byte* payload, unsigned int length) {
    char p[length + 1];
    memcpy(p, payload, length);
    p[length] = NULL;
    if (!strcmp(p, "RED"))
        RGB.color(255, 0, 0);
    else if (!strcmp(p, "GREEN"))
        RGB.color(0, 255, 0);
    else if (!strcmp(p, "BLUE"))
        RGB.color(0, 0, 255);
        RGB.color(255, 255, 255);

void setup() {
    // connect to the server

    // publish/subscribe
    if (client.isConnected()) {
        client.publish("sensorHeartbeat","hello world");

void loop() {
    if (client.isConnected())

You are checking for if (client.isConnected()) but don’t do anything when this fails.
The logical thing would be to reconnect when that’s the case tho’.

@ScruffR Yes, that’s true I’ve simplified to as close to the example as possible to minimize code causes of the issue. On my more developed firmware I reconnect at that point.

It seems that I may have a hardware issue on one of my Argons, when I put the same firmware on a different device, it’s been working substantially better, but that one device that I had been working with will not stay connected…

try this trick: MQTT Library and SEMI_AUTOMATIC - #25 by dreamER

for me it’s working like a charm :wink:

1 Like

@dreamER I’ll give it a try, thanks,