salkaleidoscope wrote on January 08, 2020:
Hi,
I have been trying to integrate OTA update capability into my application running on an ESP32-Wrover-Devkit by creating a freertos task dedicated to checking for updates. I am using amazon freertos as a component and linking in the dependencies I need for our app.
I am having a hard time telling what type of initialization I need to be doing to be able to use the OTA update demo code. I am trying to integrate it into our project where in our main function we call IotSdk_Init() , connect to wifi, then connect to greengrass core. But it seems that the code in the OTA updates demo relies on parameters that are passed in assuming one is using the demo framework. I initially got errors involving pNetworkInterface and pNetworkCredentialInfo. So I tried to populate these variables with the following code
#include "iot_network_manager_private.h"
static void App_OTACompleteCallback( OTA_JobEvent_t eEvent );
/* Variable used to indicate the connected network. */
static uint32_t demoConnectedNetwork = AWSIOT_NETWORK_TYPE_NONE;
/**
* @brief Structure which holds the context for an MQTT connection within Demo.
*/
static MqttConnectionContext_t xConnection =
{
.pvNetworkConnection = NULL,
.ulNetworkType = AWSIOT_NETWORK_TYPE_NONE,
.xNetworkInfo = IOT_MQTT_NETWORK_INFO_INITIALIZER,
.xMqttConnection = IOT_MQTT_CONNECTION_INITIALIZER,
.xDisconnectCallback = prvNetworkDisconnectCallback
};
static const char * pcStateStr[ eOTA_AgentState_All ] =
{
"Init",
"Ready",
"RequestingJob",
"WaitingForJob",
"CreatingFile",
"RequestingFileBlock",
"WaitingForFileBlock",
"ClosingFile",
"ShuttingDown",
"Stopped"
};
void ota_updates_task(void *pvParameters)
{
IotMqttConnectInfo_t xConnectInfo = { .cleanSession = true };
OTA_State_t eState;
OTA_ConnectionContext_t xOTAConnectionCtx = { 0 };
IotNetworkInterface_t *pNetworkInterface = AwsIotNetworkManager_GetNetworkInterface( demoConnectedNetwork );
void* pNetworkCredentialInfo = AwsIotNetworkManager_GetCredentials( demoConnectedNetwork );
for(;;)
{
configPRINTF( ( "Connecting to broker...\r
" ) );
memset( &xConnectInfo, 0, sizeof( xConnectInfo ) );
if( xConnection.ulNetworkType == AWSIOT_NETWORK_TYPE_BLE )
{
xConnectInfo.awsIotMqttMode = false;
xConnectInfo.keepAliveSeconds = 0;
}
else
{
xConnectInfo.awsIotMqttMode = true;
xConnectInfo.keepAliveSeconds = otaDemoKEEPALIVE_SECONDS;
}
xConnectInfo.cleanSession = true;
xConnectInfo.clientIdentifierLength = ( uint16_t ) strlen( clientcredentialIOT_THING_NAME );
xConnectInfo.pClientIdentifier = clientcredentialIOT_THING_NAME;
/* Connect to the broker. */
if( IotMqtt_Connect( &( xConnection.xNetworkInfo ),
&xConnectInfo,
otaDemoCONN_TIMEOUT_MS, &( xConnection.xMqttConnection ) ) == IOT_MQTT_SUCCESS )
{
configPRINTF( ( "Connected to broker.\r
" ) );
xOTAConnectionCtx.pvControlClient = xConnection.xMqttConnection;
xOTAConnectionCtx.pxNetworkInterface = ( void * ) pNetworkInterface;
xOTAConnectionCtx.pvNetworkCredentials = pNetworkCredentialInfo;
OTA_AgentInit( ( void * ) ( &xOTAConnectionCtx ), ( const uint8_t * ) ( clientcredentialIOT_THING_NAME ), App_OTACompleteCallback, ( TickType_t ) ~0 );
while( ( eState = OTA_GetAgentState() ) != eOTA_AgentState_Stopped )
{
/* Wait forever for OTA traffic but allow other tasks to run and output statistics only once per second. */
vTaskDelay( myappONE_SECOND_DELAY_IN_TICKS );
configPRINTF( ( "State: %s Received: %u Queued: %u Processed: %u Dropped: %u\r
", pcStateStr[ eState ],
OTA_GetPacketsReceived(), OTA_GetPacketsQueued(), OTA_GetPacketsProcessed(), OTA_GetPacketsDropped() ) );
}
IotMqtt_Disconnect( xConnection.xMqttConnection, false );
}
else
{
configPRINTF( ( "ERROR: MQTT_AGENT_Connect() Failed.\r
" ) );
}
#if defined( CONFIG_OTA_UPDATE_DEMO_ENABLED )
vMqttDemoDeleteNetworkConnection( &xConnection );
#endif
/* After failure to connect or a disconnect, wait an arbitrary one second before retry. */
vTaskDelay( myappONE_SECOND_DELAY_IN_TICKS );
}
}
I get exception:
Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC : 0x400d13f1 PS : 0x00060030 A0 : 0x800d82b8 A1 : 0x3ffd4e40
0x400d13f1: AwsIotNetworkManager_GetNetworkInterface at \build/../amazon-freertos/demos/network_manager/aws_iot_network_manager.c:938
Do I need to initialize this aws network manager before using the OTA demo example code?