AzureSphere/AzureSphereSampleDevice/main.c
static void AzureTimerEventHandler(EventLoopTimer *timer)
{
    if (ConsumeEventLoopTimerEvent(timer) != 0) {
        exitCode = ExitCode_AzureTimer_Consume;
        return;
    }

    // Check whether the device is connected to the internet.
    Networking_InterfaceConnectionStatus status;
    if (Networking_GetInterfaceConnectionStatus(networkInterface, &status) == 0) {
        if ((status & Networking_InterfaceConnectionStatus_ConnectedToInternet) &&
            (iotHubClientAuthenticationState == IoTHubClientAuthenticationState_NotAuthenticated)) {
            SetUpAzureIoTHubClient();
        }
    } else {
        if (errno != EAGAIN) {
            Log_Debug("ERROR: Networking_GetInterfaceConnectionStatus: %d (%s)\n", errno,
                      strerror(errno));
            exitCode = ExitCode_InterfaceConnectionStatus_Failed;
            return;
        }
    }

    if (iotHubClientAuthenticationState == IoTHubClientAuthenticationState_Authenticated) {
        telemetryCount++;
        if (telemetryCount == AzureIoTPollPeriodsPerTelemetry) {
            telemetryCount = 0;
            SendSimulatedTelemetry();
        }
    }

    if (iothubClientHandle != NULL) {
        IoTHubDeviceClient_LL_DoWork(iothubClientHandle);
    }
}
/// <summary>
///     Azure timer event:  Check connection status and send telemetry
/// </summary>

Azure timer event:  Check connection status and send telemetry

Azure timer event : Check connection status and send telemetry
static void AzureTimerEventHandler(EventLoopTimer *timer)
{
    if (ConsumeEventLoopTimerEvent(timer) != 0) {
        exitCode = ExitCode_AzureTimer_Consume;
        return;
    }
    Networking_InterfaceConnectionStatus status;
    if (Networking_GetInterfaceConnectionStatus(networkInterface, &status) == 0) {
        if ((status & Networking_InterfaceConnectionStatus_ConnectedToInternet) &&
            (iotHubClientAuthenticationState == IoTHubClientAuthenticationState_NotAuthenticated)) {
            SetUpAzureIoTHubClient();
        }
    } else {
        if (errno != EAGAIN) {
            Log_Debug("ERROR: Networking_GetInterfaceConnectionStatus: %d (%s)\n", errno,
                      strerror(errno));
            exitCode = ExitCode_InterfaceConnectionStatus_Failed;
            return;
        }
    }
    if (iotHubClientAuthenticationState == IoTHubClientAuthenticationState_Authenticated) {
        telemetryCount++;
        if (telemetryCount == AzureIoTPollPeriodsPerTelemetry) {
            telemetryCount = 0;
            SendSimulatedTelemetry();
        }
    }
    if (iothubClientHandle != NULL) {
        IoTHubDeviceClient_LL_DoWork(iothubClientHandle);
    }
}
static void AzureTimerEventHandler ( EventLoopTimer * timer ) { if ( ConsumeEventLoopTimerEvent ( timer ) != 0 ) { exitCode = ExitCode_AzureTimer_Consume ; return ; } Networking_InterfaceConnectionStatus status ; if ( Networking_GetInterfaceConnectionStatus ( networkInterface , & status ) == 0 ) { if ( ( status & Networking_InterfaceConnectionStatus_ConnectedToInternet ) && ( iotHubClientAuthenticationState == IoTHubClientAuthenticationState_NotAuthenticated ) ) { SetUpAzureIoTHubClient ( ) ; } } else { if ( errno != EAGAIN ) { Log_Debug ( " \n " , errno , strerror ( errno ) ) ; exitCode = ExitCode_InterfaceConnectionStatus_Failed ; return ; } } if ( iotHubClientAuthenticationState == IoTHubClientAuthenticationState_Authenticated ) { telemetryCount ++ ; if ( telemetryCount == AzureIoTPollPeriodsPerTelemetry ) { telemetryCount = 0 ; SendSimulatedTelemetry ( ) ; } } if ( iothubClientHandle != NULL ) { IoTHubDeviceClient_LL_DoWork ( iothubClientHandle ) ; } }
<summary>
Azure timer event:  Check connection status and send telemetry
</summary>
<summary > Azure timer event : Check connection status and send telemetry < / summary >
// Check whether the device is connected to the internet.