Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[mosquitto-dev] Receiving a disconnection (1) when connecting to broker

Hello,


I am using the mosquittopp library and I'm getting some strange disconnections that is returning the error code 1.  Looking at the mosquitto.h file, it looks as this is a No Memory error, which does not make sense.  Looking at the memory usage of my application and the mosquitto service there does not appear to be any issue (my application is using 1.2% of the memory, and mosquitto is using 0.4%).


I was wondering if there is any more documentation on what typically causes this error?


Here is how I'm creating an instance... I'm passing in NULL as the _id in order to have the library use a random client id.

local_server = new mqtt(NULL, "localhost", 1883, 10);


// Constructor

mqtt::mqtt(char *_id, QString _host, int _port, int _keepalive) : mosquittopp(_id)
{
    // Initialization for mosquitto
    mosqpp::lib_init();

    // Basic configuration setup for mqtt class
    this->keepalive = _keepalive;
    this->id = _id;
    this->port = _port;
    this->host = _host;

    this->reconnect_delay_set(5, 30, true);

    // Non blocking connection to broker request
    connect_async(host.toStdString().c_str(), port, keepalive);

    // Start thread managing connection / publish / subscribe
    loop_start();
}

Here is my on_disconnection code:
void mqtt::on_disconnect(int rc)
{
    qDebug() << ">> mqtt - disconnection(" << rc << ")" << host;
    emit disconnected();
}


I'm seeing disconnects happen every 20 seconds or so.  But sometimes it works without any problems and I'm having a hard time tracking down the root cause.

myapp.service - Run the /usr/bin/myapp.sh script

   Loaded: loaded (/etc/systemd/system/myapp.service; disabled; vendor preset:

   Active: active (running) since Wed 2016-11-23 20:44:00 UTC; 11min ago

Main PID: 1331 (myapp)

   CGroup: /system.slice/myapp.service

           └─1331 /opt/myapp/bin/myapp

 

Nov 23 20:52:16 ubuntu myapp[1331]: >> mqtt - connected with server "localhost"

Nov 23 20:53:42 ubuntu myapp[1331]: >> mqtt - disconnection( 1 ) "localhost"

Nov 23 20:53:42 ubuntu myapp[1331]: >> mqtt - disconnection( 1 ) "localhost"

Nov 23 20:53:52 ubuntu myapp[1331]: >> mqtt - disconnection( 1 ) "localhost"

Nov 23 20:54:12 ubuntu myapp[1331]: >> mqtt - disconnection( 1 ) "localhost"

Nov 23 20:54:32 ubuntu myapp[1331]: >> mqtt - disconnection( 1 ) "localhost"

Nov 23 20:54:52 ubuntu myapp[1331]: >> mqtt - disconnection( 1 ) "localhost"

Nov 23 20:55:12 ubuntu myapp[1331]: >> mqtt - disconnection( 1 ) "localhost"

Nov 23 20:55:22 ubuntu myapp[1331]: >> mqtt - connected with server "localhost"

lines 1-17/17 (END)


Does anyone have any insight to why this may be happening?  Is there something I'm doing wrong in my code?  Let me know if you need to see more of the code.  Thanks!


Back to the top