BW16 keepalive Issue

Hi,
我正在使用MQTT相關應用於BW16上,
然而在測試時,
keepalive為600s,
Publish間隔為10s,
理論上持續Publish下不應該觸發PINGREQ封包,
但每當過了600s,BW16仍然會發出一PINGREQ封包,並從而導致後續一筆封包的延遲,
如圖所示,在時間為653554034時觸發了PINGREQ,而後當653554044封包送出後,
653554054的封包便沒有正常傳出,後續直到下一筆653554064才同時出現,
不知道是否有人遇過這種問題?
還是我應該把keepalive設定為0關閉此功能呢
謝謝。

@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;
                _client->stop();
                return false;
            } else {
                this->buffer[0] = MQTTPINGREQ;
                this->buffer[1] = 0;
                _client->write(this->buffer,2);
                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

@daphwl
OK.
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.