Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [mosquitto-dev] Client connect disconnect repeatly

Hi,

There are some my functions:

Init:


int protocol_version = 3;
mosquitto_lib_init();

mosq = mosquitto_new(CLIENT_ID, true, NULL);
if(mosq)
    {
        //mosquitto_log_callback_set(mosq, VR_(my_log_callback));
        mosquitto_will_set(mosq, PUBLISH_RES_TOPIC, strlen("client disconnect"),
                            (char*)"client disconnect", QOS1, false);

        mosquitto_connect_callback_set(mosq, VR_(mosquitto_connect_callback));
        mosquitto_message_callback_set(mosq, VR_(mosquitto_message_callback));
        mosquitto_disconnect_callback_set(mosq, VR_(mosquitto_disconnect_callback));
        mosquitto_subscribe_callback_set(mosq, VR_(mosquitto_subscribe_callback));

        mosquitto_tls_set(mosq, ROOT_CA_FILENAME,
                                ROOT_CA,
                                CERTIFICATE_FILENAME,
                                PRIVATE_KEY_FILENAME,
                                NULL);
        mosquitto_opts_set(mosq, MOSQ_OPT_PROTOCOL_VERSION, &protocol_version);

        //mosquitto_message_retry_set(mosq, 3);
        //mosquitto_reconnect_delay_set(mosq, 1, 5, false);

        int rc = pthread_create(&thread_mosquitto, NULL, (void *) &VR_(mosquitto_main_thread), NULL);
        if (rc != 0)
        {
            SLOGI("Can not create thread");
        }
        pthread_detach(thread_mosquitto);
    }
    else
    {
        SLOGE("FAILED TO CREATE MOSQUITTO\n");
        return -1;
    }

In mosquitto main thread:
void VR_(mosquitto_main_thread)(void)
{

    mosquitto_connect(mosq, mqtt_address, MQTT_PORT, 60);
    mosquitto_loop_start(mosq);
}

In mosquitto_connect_callback
        pthread_t test_thread;
        pthread_create(&test_thread, NULL, (void *)&
test_thread_cb, NULL);
        pthread_detach(
test_thread);
        mosquitto_subscribe(mosq, NULL, SUBSCRIBE_REQ_TOPIC, QOS1);
        mosquitto_subscribe(mosq, NULL, SUBSCRIBE_CONTROL_TOPIC, QOS1);
        mosquitto_subscribe(mosq, NULL, SUBSCRIBE_TEST1_TOPIC, QOS1);
        mosquitto_subscribe(mosq, NULL, SUBSCRIBE_TEST2_TOPIC, QOS1);



Thanks
Tuan Nguyen

On Mon, Mar 6, 2017 at 3:48 PM, ನಾಗೇಶ್ ಸುಬ್ರಹ್ಮಣ್ಯ (Nagesh S) <nageshblore@xxxxxxxxx> wrote:
Can you show your client code, please? 

On 6 Mar 2017 13:47, "Tuấn Nguyễn Hoàng" <hoangtuan180991@xxxxxxxxx> wrote:
Hi Nagesh,

No, that is only one client. My client disconnect immediately after connected, then wait a little, it connected then disconnect immediately. Finally, after some waiting, It could connect to cloud.

I am try to test with more publish (QoS1) actions  when it disconnected, then the number time of connection and disconnection increase, I need wait more before it can connect to cloud.

Thanks

Tuan Nguyen

On Mon, Mar 6, 2017 at 2:45 PM, ನಾಗೇಶ್ ಸುಬ್ರಹ್ಮಣ್ಯ (Nagesh S) <nageshblore@xxxxxxxxx> wrote:
Is there another client trying to connect with the same client identifier?

Regards,
Nagesh

On Mon, Mar 6, 2017 at 12:46 PM, Tuấn Nguyễn Hoàng <hoangtuan180991@xxxxxxxxx> wrote:
Hi there,

I am using mosquitto-1.4.9 to implement an application.
When my client is disconnected, I tried to publish some messages to broker by using QOS1 (all message and topic are using QOS1). 

When my network is turned back, my client is connected, then disconnected immediately, wait a minute, It's connected and disconnected again. 

I tested and found that the repeat time depend on the number messages I sent when client is disconnected.

Anyone could help me to explain what's wrong?

Thanks

Tuan Nguyen

_______________________________________________
mosquitto-dev mailing list
mosquitto-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/mosquitto-dev


_______________________________________________
mosquitto-dev mailing list
mosquitto-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/mosquitto-dev


_______________________________________________
mosquitto-dev mailing list
mosquitto-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/mosquitto-dev


_______________________________________________
mosquitto-dev mailing list
mosquitto-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/mosquitto-dev


Back to the top