AWS IoT Over-the-air Update v3.4.1
Client library for AWS IoT OTA
OTA_Init

OTA Agent initialization function.

OtaErr_t OTA_Init( const OtaAppBuffer_t * pOtaBuffer,
const OtaInterfaces_t * pOtaInterfaces,
const uint8_t * pThingName,
OtaAppCallback_t OtaAppCallback );
void(* OtaAppCallback_t)(OtaJobEvent_t eEvent, void *pData)
OTA update complete callback function typedef.
Definition: ota.h:288
OtaErr_t
The OTA API return status. OTA agent error codes are in the upper 8 bits of the 32 bit OTA error word...
Definition: ota.h:80
OtaErr_t OTA_Init(const OtaAppBuffer_t *pOtaBuffer, const OtaInterfaces_t *pOtaInterfaces, const uint8_t *pThingName, OtaAppCallback_t OtaAppCallback)
OTA Agent initialization function.
Definition: ota.c:3236
OTA Application Buffer size information.
Definition: ota.h:316
OTA Interface for referencing different components.
Definition: ota.h:302

Initialize the OTA engine by starting the OTA Agent ("OTA Task") in the system. This function must be called with the connection client context before calling OTA_CheckForUpdate. Only one OTA Agent may exist.

Parameters
[in]pOtaBufferBuffers used by the agent to store different params.
[in]pOtaInterfacesA pointer to the OS context.
[in]pThingNameA pointer to a C string holding the Thing name.
[in]OtaAppCallbackStatic callback function for when an OTA job is complete. This function will have input of the state of the OTA image after download and during self-test.
Returns
OtaErr_t The state of the OTA Agent upon return from the OtaState_t enum. If the agent was successfully initialized and ready to operate, the state will be OtaAgentStateReady. Otherwise, it will be one of the other OtaState_t enum values.

Example

// Application callback when the OTA agent has completed the job
// or is in self test mode. For example see [demos](https://github.com/aws/aws-iot-device-sdk-embedded-C/tree/main/demos/ota)
void otaAppCallback( OtaJobEvent_t event,
const void * pData );
// Optional: User buffer to pass down to the OTA Agent. These
// buffers are assumed to be initialized previously, example:
// uint8_t updateFilePath[ OTA_MAX_FILE_PATH_SIZE ];
OtaAppBuffer_t otaBuffer =
{
.pUpdateFilePath = updateFilePath,
.updateFilePathsize = OTA_MAX_FILE_PATH_SIZE,
.pCertFilePath = certFilePath,
.certFilePathSize = OTA_MAX_FILE_PATH_SIZE,
.pDecodeMemory = decodeMem,
.decodeMemorySize = otaconfigFILE_BLOCK_SIZE,
.pFileBitmap = bitmap,
.fileBitmapSize = OTA_MAX_BLOCK_BITMAP_SIZE,
.pUrl = updateUrl,
.urlSize = OTA_MAX_URL_SIZE,
.pAuthScheme = authScheme,
.authSchemeSize = OTA_MAX_AUTH_SCHEME_SIZE
};
// OTA interface context required for library interface functions
// The functions set by these interfaces are assumed to be defined
// For more information see [demos](https://github.com/aws/aws-iot-device-sdk-embedded-C/tree/main/demos/ota)
OtaInterfaces_t pOtaInterfaces =
{
// Initialize OTA library OS Interface.
.os.event.init = Posix_OtaInitEvent;
.os.event.send = Posix_OtaSendEvent;
...
// Initialize the OTA library MQTT Interface.
.mqtt.subscribe = mqttSubscribe;
.mqtt.publish = mqttPublish;
.mqtt.unsubscribe = mqttUnsubscribe;
// Initialize the OTA library HTTP Interface.
.http.init = httpInit;
.http.request = httpRequest;
.http.deinit = httpDeinit;
// Initialize the OTA library PAL Interface.
.pal.getPlatformImageState = otaPal_GetPlatformImageState;
.pal.setPlatformImageState = otaPal_SetPlatformImageState;
}
// OTA library error status.
// Unique client identifier
char * pClientIdentifier = "uniqueClientID";
otaErr = OTA_Init( &otaBuffer,
&otaInterfaces,
( const uint8_t * ) pClientIdentifier,
otaAppCallback ) ) != OtaErrNone )
if( otaErr == OtaErrNone )
{
// Do something with the OTA agent.
}
#define OTA_MAX_BLOCK_BITMAP_SIZE
Max allowed number of bytes to track all blocks of an OTA file. Adjust block size if more range is ne...
Definition: ota_private.h:66
OtaJobEvent_t
OTA Job callback events.
Definition: ota.h:167
@ OtaErrNone
No error occurred during the operation.
Definition: ota.h:81
uint8_t * pUpdateFilePath
Path to store the files.
Definition: ota.h:317
OtaInitEvent_t init
Initialization event.
Definition: ota_os_interface.h:265
OtaOSInterface_t os
OS interface to store event, timers and memory operations.
Definition: ota.h:303
OtaEventInterface_t event
OTA Event interface.
Definition: ota_os_interface.h:309