AWS IoT Device SDK C: Defender
AWS IoT Device Defender library
Return to main page ↑
AwsIotDefender_Start

Start the defender agent.

Parameters
[in]pStartInfoPointer of parameters of start function

Periodically, defender agent collects metrics and publish to specific AWS reserved MQTT topic.

Returns
Warning
This function is not thread safe.
Note
No need to manage the memory allocated for AwsIotDefenderCallbackInfo_t. This function save the information internally.

Example:

// assume valid IotMqttConnection_t is created and available.
const IotMqttConnection_t _mqttConnection;
// use AWS thing name as client identifier
const char * pClientIdentifier = "AwsThingName";
void logDefenderCallback( void * param1, AwsIotDefenderCallbackInfo_t * const pCallbackInfo )
{
{
// log info: metrics report accepted by defender service is a happy case
}
else
{
// log error: pCallbackInfo->eventType
}
if ( pCallbackInfo->pPayload != NULL )
{
// log info: pCallbackInfo->pPayload with length pCallbackInfo->payloadLength
}
if ( pCallbackInfo->pMetricsReport != NULL )
{
// log info: pCallbackInfo->pMetricsReport with length pCallbackInfo->metricsReportLength
}
}
void startDefender()
{
// define a simple callback function which simply logs
const AwsIotDefenderCallback_t callback = { .function = logDefenderCallback, .pCallbackContext = NULL };
// define parameters of AwsIotDefender_Start function
// Note: This example assumes MQTT connection is already established and metrics library is initialized.
const AwsIotDefenderStartInfo_t startInfo =
{
.pClientIdentifier = pClientIdentifier,
.clientIdentifierLength = strlen( pClientIdentifier ),
.mqttConnection = _mqttConnection,
.callback = callback
};
// specify two TCP connections metrics: total count and local port
if ( error == AWS_IOT_DEFENDER_SUCCESS )
{
// set metrics report period to 10 minutes (600 seconds)
error = AwsIotDefender_SetPeriod( 600 );
}
{
// start the defender
error = AwsIotDefender_Start( &startInfo );
}
if ( error != AWS_IOT_DEFENDER_SUCCESS )
{
const char * pError = AwsIotDefender_strerror( error );
// log error: pError
}
}
void stopDefender()
{
//stop the defender
}