Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PING message interval is not handled properly #287

Closed
ademyankov opened this issue Jun 1, 2024 · 5 comments
Closed

PING message interval is not handled properly #287

ademyankov opened this issue Jun 1, 2024 · 5 comments

Comments

@ademyankov
Copy link

It looks like there is a bug in the line core_mqtt.c:1383

        if( ( timeElapsed != 0U ) && ( timeElapsed >= PACKET_RX_TIMEOUT_MS ) )

By default PACKET_RX_TIMEOUT_MS is 30 seconds but PING message is sent every time the Loop function is invoked because timeElapsed is always equal to now when pContext->lastPacketRxTime is 0

The fix I did is this one but I am not sure how it might effect other parts of the code:

        static uint32_t calculateElapsedTime( uint32_t later, uint32_t start )
        {
            return start ? later - start : 0;
        }

I haven't checked other conditions related to invoking MQTT_Ping( pContext );

@paulbartell
Copy link
Contributor

@ademyankov Thanks for pointing this out. I'll get it over to our coreMQTT experts.

@Pooja-Toshniwal
Copy link

Which version of coreMQTT are you using? @ademyankov

@ademyankov
Copy link
Author

@Pooja-Toshniwal v2.1.1

@Pooja-Toshniwal
Copy link

After investigating, it appears that the problem you encountered with unnecessary MQTT_Ping invocations is present in the older version (2.1.1) of the FreeRTOS coreMQTT library. This issue has been resolved in the newer version (2.2.0) by introducing an additional condition check that updates the lastPacketRxTime whenever an incoming packet is handled (except for CONNACK). By updating lastPacketRxTime when an incoming packet is received, the library ensures that the elapsed time calculation is correct, even in cases where no packet has been received initially. This change resolves the issue of unnecessary MQTT_Ping invocations whenlastPacketRxTime is zero.
This condition has been added-
if( status == MQTTSuccess ) { pContext->lastPacketRxTime = pContext->getTime(); }

if( status == MQTTSuccess )

I suggest updating to the latest version of the library ( v2.2.0) and testing it to confirm its functionality. If you still encounter any issues, please let us know. @ademyankov

@ademyankov
Copy link
Author

@Pooja-Toshniwal yes, I've just checked v2.2.0 and it works as excpected. Thank you for investigating the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants