BW16 keepalive Issue


@daphwl will assist you on this

@xidameng 目前還沒收到提供的幫助,謝謝您。

Hi @AlanWL,

Sorry for the late reply, I’m currently still doing the testing. Will get back to you when I have some results. Thank you.

Hi @daphwl ,

Did you find this problem in testing?
I hope there will be a solution to reslove it.
Thank you.

Hi @AlanWL,

After testing, i discovered that the AmebaClient will closed its connection at random intervals, but i didnt see the PINGREQ message. I’m still trying to do more testing to see exactly what cause the disconnection.
I have also tried setting keepalive() to 0, but the disconnection still occured.

Hi @daphwl ,

The closed issue is as mentioned in my previous article.
This part really needs to be resolved.
Please let me know if you have new test results, thanks.

Hi @AlanWL,

I was able to reproduce the PINGREQ packet issue.

In PubSubClient.cpp

        unsigned long t = millis();
        if ((t - lastInActivity > this->keepAlive*1000UL) || (t - lastOutActivity > this->keepAlive*1000UL)) {
            if (pingOutstanding) {
                this->_state = MQTT_CONNECTION_TIMEOUT;
                return false;
            } else {
                this->buffer[0] = MQTTPINGREQ;
                this->buffer[1] = 0;
                lastOutActivity = t;
                lastInActivity = t;
                pingOutstanding = true;

Since you are only publishing , this only update lastOutActivity. lastInActivity will only be updated if you receive a packet from the server, which will only happen if you publish with QOS1 or QOS2.

You can either change the publish QOS value or change the code to:

if ((t - lastInActivity > this->keepAlive*1000UL) && (t - lastOutActivity > this->keepAlive*1000UL))

Hi @daphwl ,
Thanks for your help, I’ll test this part again.
In addition, after modifying this part, will there still be problems of closed its connection?

1 Like

Yes have, still trying to find out what is causing the connection to closed

if there are new results, please let me know about this again.
Thank you very much.

Hi @daphwl ,
Here is my disconnect test result:
When I use mosquitto as MQTT Broker, the problem of random disconnection will occur.
And when I use SIoT1.3 as Broker, the random disconnection problem will not occur.