Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

feat/ota_resume #1907

Merged
merged 15 commits into from
May 11, 2020
Merged

feat/ota_resume #1907

merged 15 commits into from
May 11, 2020

Conversation

pvyawaha
Copy link
Contributor

OTA Suspend and Resume Feature

Description

This is a draft pull request not for merging.

Checklist:

  • I have tested my changes. No regression in existing tests.
  • My code is Linted.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@pvyawaha pvyawaha closed this Apr 15, 2020
@pvyawaha pvyawaha reopened this Apr 15, 2020
Remove OTA demo specific conditional macros used in the demo.
Remove dependency on network manager APIs.
Remove dependency on aws_iot_demo_network.c
Add MQTT disconnect reason logs in the disconnect callback.
Update doxygen and other comments.
Copy link
Contributor

@gkwicker gkwicker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments


#define myappONE_SECOND_DELAY_IN_TICKS pdMS_TO_TICKS( 1000UL )
/**
* @brief Timeout for MQTT connection, if the MQTT connection is not establihsed within
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spelling: established

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing this, Thank you for pointing it out.

* @brief Timeout for MQTT connection, if the MQTT connection is not establihsed within
* this time, the connect function returns #IOT_MQTT_TIMEOUT
*/
#define OTA_DEMO_CONNECTION_TIMEOUT ( 2000UL )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What units is this in? If it is milliseconds, please rename to OTA_DEMO_CONNECTION_TIMEOUT_MS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must have the ms , changing it to OTA_DEMO_CONNECTION_TIMEOUT_MS

* by the MQTT 3.1.1 spec) is 23 characters. Add 1 to include the length of the NULL
* terminator.
*/
#define OTA_DEMO_CLIENT_IDENTIFIER_MAX_LENGTH ( 24 )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be available in an MQTT header file somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not defined in MQTT library , the MQTT demo has its definition similar to what we are doing here.

}

static BaseType_t prxCreateNetworkConnection( void )
/**
* @brief Delay before retrying network connection upto a maximum interval.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spelling: up to

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing this to up to , thanks.

}
}
} while( ulRetriesLeft-- > 0 );
intervalTicks = pdMS_TO_TICKS( retryInterval * 1000 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we would add some jitter here.

Copy link
Contributor Author

@pvyawaha pvyawaha Apr 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding jitter in commit 50e1814 using rand so devices will initiate reconnection anywhere within the interval window.

if( xMqttInitStatus != IOT_MQTT_SUCCESS )
{
xRet = EXIT_FAILURE;
while( ( ( eState = OTA_GetAgentState() ) != eOTA_AgentState_Stopped ) && networkConnected )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is networkConnected set to pdFALSE? I notice it's not declared volatile. If some other task is setting it, some compilers might optimize this test away.

Copy link
Contributor Author

@pvyawaha pvyawaha May 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_networkConnected is set false in disconnect callback, fixed in dec8c99

* @brief The maximum time interval that is permitted to elapse between the point at
* which the MQTT client finishes transmitting one control Packet and the point it starts
* sending the next.In the absence of control packet a PINGREQ is sent. The broker must
* disconnect a client that does not send a a message or a PINGREQ packet in one and a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correction send a message

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks , fixing this.

* @brief The delay used in the main OTA Demo task loop to periodically output the OTA
* statistics like number of packets received, dropped, processed and queued per connection.
*/
#define OTA_DEMO_ONE_SECOND_DELAY pdMS_TO_TICKS( 1000UL )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be made in seconds as well for easy configuration and understanding by user

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this in 0ac73bd

Also renamed it to make sense if the value is changed from 1 sec.

/* Connect to one of the network type.*/
xRet = xMqttDemoCreateNetworkConnection( &xConnection, otaDemoNETWORK_TYPES );
#endif
configPRINTF( ( "Retrying network connection in %d Secs ", retryInterval ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest using IotLog for logging.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to IotLog in commit ea768f3

( void ) awsIotMqttMode;
( void ) pIdentifier;
( void ) pNetworkServerInfo;
retryInterval = OTA_DEMO_CONN_RETRY_BASE_INTERVAL_SECONDS;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should retry interval be reset back to OTA_DEMO_CONN_RETRY_BASE_INTERVAL_SECONDS once a successful connection is made.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it can be reset to base time interval, making a change to address this.

xConnectInfo.clientIdentifierLength = ( uint16_t ) strlen( clientcredentialIOT_THING_NAME );
xConnectInfo.pClientIdentifier = clientcredentialIOT_THING_NAME;
/* Suspend OTA agent.*/
OTA_Suspend();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be called from main OTA demo for(;;) loop before tearing down MQTT connection. Otherwise it can cause race condition if MQTT connection is deleted but OTA agent is still active.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is moved in the OTA Demo loop in commit c567abe

}

/* Try to close the MQTT connection. */
if( ( mqttConnection != NULL ) && networkConnected )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Teardown mqtt connection resources in network disconnected case as well ? , by calling IotMqtt_Disconnect( mqttConnection, true);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit dec8c99

@pvyawaha pvyawaha requested a review from dcgaws May 8, 2020 20:48
@pvyawaha pvyawaha requested a review from dan4thewin May 8, 2020 21:24
ravibhagavandas
ravibhagavandas previously approved these changes May 8, 2020
@pvyawaha pvyawaha removed the request for review from dan4thewin May 11, 2020 01:43
@pvyawaha pvyawaha marked this pull request as ready for review May 11, 2020 17:12
Copy link
Contributor

@gkwicker gkwicker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small thing, see comments.

{
/* Wait forever for OTA traffic but allow other tasks to run and output statistics only once per second. */
vTaskDelay( OTA_DEMO_ONE_SECOND_DELAY );
IotClock_SleepMs( OTA_DEMO_TASK_DELAY * 1000 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be named OTA_DEMO_TASK_DELAY_SECONDS. If a #define value is in units (time/distance/mass/etc.), include the unit in the name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in 1815858

@pvyawaha pvyawaha merged commit cbf360f into master May 11, 2020
@pvyawaha pvyawaha deleted the prasad/OTA_Suspend_Resume branch May 11, 2020 18:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants