Beispiel #1
0
kaa_error_t kaa_client_create(kaa_client_t **client, kaa_client_props_t *props) {
    (void)props;
    KAA_RETURN_IF_NIL(client, KAA_ERR_BADPARAM);

    kaa_client_t *self = (kaa_client_t*)KAA_CALLOC(1, sizeof(kaa_client_t));
    KAA_RETURN_IF_NIL(self, KAA_ERR_NOMEM);
    kaa_error_t error_code = kaa_init(&self->context);

    if(error_code) {
        printf("Error initialising kaa_context\n");
        kaa_client_destroy(self);
        return error_code;
    }

    self->operate = true;

#ifndef KAA_DISABLE_FEATURE_LOGGING
    error_code = kaa_log_collector_init(self);
    if (error_code) {
        KAA_LOG_ERROR(self->context->logger, error_code, "Failed to init Kaa log collector, error %d", error_code);
        kaa_client_destroy(self);
        return error_code;
    }
#endif

    KAA_LOG_INFO(self->context->logger,KAA_ERR_NONE, "Kaa client initiallized");
    *client = self;
    return error_code;
}
Beispiel #2
0
kaa_error_t kaa_client_create(kaa_client_t **kaa_client, kaa_client_props_t *props)
{
    KAA_RETURN_IF_NIL2(kaa_client, props, KAA_ERR_BADPARAM);

    kaa_error_t error_code = KAA_ERR_NONE;

    kaa_client_t *self = calloc(1, sizeof(kaa_client_t));
    KAA_RETURN_IF_NIL(self, KAA_ERR_NOMEM);

    esp8266_error_t esp8266_error = esp8266_create(&self->controler, props->serial, DEFAULT_ESP8266_CONTROLER_BUFFER_SIZE);
    if (esp8266_error) {
        debug("Error during esp8266 creation %d\n", esp8266_error);
        kaa_client_destroy(self);
        return KAA_ERR_BADDATA;
    }

    esp8266_error = esp8266_tcp_register_receive_callback(self->controler, esp8266_tcp_receive_fn, (void *)self);
    if (esp8266_error) {
        debug("Error during esp8266 registering receive callback %d\n", esp8266_error);
        kaa_client_destroy(self);
        return KAA_ERR_BADDATA;
    }

    error_code = kaa_init_security_stuff(props->kaa_public_key, props->kaa_public_key_length);
    if (error_code) {
        debug("Error generate SHA1 diges form Public Key, error %d", error_code);
        kaa_client_destroy(self);
        return error_code;
    }

    error_code = kaa_init(&self->kaa_context);
    if (error_code) {
        debug("Error during Kaa context creation %d\n", error_code);
        kaa_client_destroy(self);
        return error_code;
    }

    KAA_LOG_INFO(self->kaa_context->logger, KAA_ERR_NONE, "Kaa framework initialized.");

    self->wifi_ssid = props->wifi_ssid;
    self->wifi_pswd = props->wifi_pswd;
    self->operate = true;
    self->blink_timeout = 500;

    error_code = kaa_log_collector_init(self);
    if (error_code) {
        KAA_LOG_ERROR(self->kaa_context->logger, error_code, "Failed to init Kaa log collector %d", error_code);
        kaa_client_destroy(self);
        return error_code;
    }

    KAA_LOG_INFO(self->kaa_context->logger, KAA_ERR_NONE, "Kaa log collector initialized.");

    *kaa_client = self;

    return error_code;
}
Beispiel #3
0
int main(/*int argc, char* argv[] */)
{   

    printf("\r\nConfiguration demo started\n");

    /**
     * Initialize Kaa client.
     */
      
    kaa_error_t error_code = kaa_client_create(&kaa_client, NULL);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed create Kaa client");
    

    kaa_configuration_root_receiver_t receiver = { NULL, &kaa_demo_configuration_receiver };
    error_code = kaa_configuration_manager_set_root_receiver(kaa_client_get_context(kaa_client)->configuration_manager, &receiver);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to add configuration receiver");

    kaa_demo_print_configuration_message(kaa_configuration_manager_get_configuration(kaa_client_get_context(kaa_client)->configuration_manager));

    /**
     * Start Kaa client main loop.
     */
    error_code = kaa_client_start(kaa_client, NULL, NULL, 0);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to start Kaa main loop");

    /**
     * Destroy Kaa client.
     */
    kaa_client_destroy(kaa_client);

    printf("Configuration demo stopped\n");
    return error_code;
}
Beispiel #4
0
int main(/*int argc, char *argv[]*/)
{
    printf("Cassandra data analytics demo started\n");

    if (wiringPiSetup() == -1) {
        printf("Failed to initialize Pi wiring\n");
        exit(1);
    }

    kaa_client_t *kaa_client = NULL;

    void *log_storage_context         = NULL;
    void *log_upload_strategy_context = NULL;

    /**
     * Initialize Kaa client.
     */
    kaa_error_t error_code = kaa_client_create(&kaa_client, NULL);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed create Kaa client");

    /**
     * Configure Kaa data collection module.
     */
    error_code = ext_unlimited_log_storage_create(&log_storage_context, kaa_client_get_context(kaa_client)->logger);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to create unlimited log storage");

    error_code = ext_log_upload_strategy_create(kaa_client_get_context(kaa_client), &log_upload_strategy_context, KAA_LOG_UPLOAD_VOLUME_STRATEGY);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to create log upload strategy");

    error_code = ext_log_upload_strategy_set_threshold_count(log_upload_strategy_context, KAA_DEMO_UPLOAD_COUNT_THRESHOLD);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to set threshold log record count");

    kaa_log_bucket_constraints_t bucket_sizes = {
        .max_bucket_size = MAX_LOG_BUCKET_SIZE,
        .max_bucket_log_count = MAX_LOG_COUNT,
    };

    error_code = kaa_logging_init(kaa_client_get_context(kaa_client)->log_collector
                                , log_storage_context
                                , log_upload_strategy_context
                                , &bucket_sizes);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to init Kaa log collector");

    /**
     * Start Kaa client main loop.
     */
    error_code = kaa_client_start(kaa_client, &kaa_demo_add_log_record, (void *)kaa_client, KAA_DEMO_LOG_GENERATION_FREQUENCY);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to start Kaa main loop");

    /**
     * Destroy Kaa client.
     */
    kaa_client_destroy(kaa_client);

    printf("Cassandra data analytics demo stopped\n");

    return error_code;
}
Beispiel #5
0
int main(/*int argc, char *argv[]*/) {
    /**
     * Initialise a board
     */
    int ret = target_initialise();
    if (ret < 0) {
        /* If console is failed to initialise, you will not see this message */
        demo_printf("Failed to initialise a target\n");
        return 1;
    }

    demo_printf("Configuration demo started\n");

    /**
     * Initialize Kaa client.
     */
    kaa_error_t error_code = kaa_client_create(&kaa_client, NULL);
    if (error_code) {
        demo_printf("Failed create Kaa client\n");
        return 2;
    }

    kaa_configuration_root_receiver_t receiver = {
            NULL,
            &kaa_demo_configuration_receiver
    };

    error_code = kaa_configuration_manager_set_root_receiver(
            kaa_client_get_context(kaa_client)->configuration_manager,
            &receiver);

    if (error_code) {
        demo_printf("Failed to add configuration receiver\n");
        return 3;
    }

    kaa_demo_print_configuration_message(
            kaa_configuration_manager_get_configuration(
                    kaa_client_get_context(kaa_client)->configuration_manager));

    /**
     * Start Kaa client main loop.
     */
    error_code = kaa_client_start(kaa_client, NULL, NULL, 0);
    if(error_code) {
        demo_printf("Failed to start Kaa main loop\n");
        return 4;
    }

    /**
     * Destroy Kaa client.
     */
    kaa_client_destroy(kaa_client);

    demo_printf("Configuration demo stopped\n");
    return 0;
}
Beispiel #6
0
int main(/*int argc, char *argv[]*/)
{
    printf("Data collection demo started\n");
    kaa_log_bucket_constraints_t bucket_sizes = {
        .max_bucket_size       = KAA_DEMO_BUCKET_SIZE,
        .max_bucket_log_count  = KAA_DEMO_LOGS_IN_BUCKET,
    };

    /**
     * Initialize Kaa client.
     */
    kaa_error_t error_code = kaa_client_create(&kaa_client, NULL);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed create Kaa client");

    error_code = ext_limited_log_storage_create(&log_storage_context, kaa_client_get_context(kaa_client)->logger, KAA_DEMO_LOG_STORAGE_SIZE, KAA_DEMO_LOGS_TO_KEEP);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to create limited log storage");

    error_code = ext_log_upload_strategy_create(kaa_client_get_context(kaa_client), &log_upload_strategy_context, KAA_LOG_UPLOAD_VOLUME_STRATEGY);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to create log upload strategy");

    error_code = ext_log_upload_strategy_set_threshold_count(log_upload_strategy_context, KAA_DEMO_UPLOAD_COUNT_THRESHOLD);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to set threshold log record count");

    error_code = kaa_logging_init(kaa_client_get_context(kaa_client)->log_collector
                                , log_storage_context
                                , log_upload_strategy_context
                                , &bucket_sizes);

    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to init Kaa log collector");

    error_code = kaa_logging_set_listeners(kaa_client_get_context(kaa_client)->log_collector,
                                           &log_listener);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to add log listeners");

    /**
     * Start Kaa client main loop.
     */
    error_code = kaa_client_start(kaa_client, &kaa_demo_add_log_record, (void *)kaa_client, KAA_DEMO_LOG_GENERATION_FREQUENCY);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to start Kaa main loop");

    /**
     * Destroy Kaa client.
     */
    kaa_client_destroy(kaa_client);

    printf("Data collection demo stopped\n");

    return error_code;
}
Beispiel #7
0
int main(/*int argc, char *argv[]*/)
{
    printf("Data collection demo started\n");

    /**
     * Initialize Kaa client.
     */
    kaa_error_t error_code = kaa_client_create(&kaa_client, NULL);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed create Kaa client");

    error_code = ext_unlimited_log_storage_create(&log_storage_context, kaa_client_get_context(kaa_client)->logger);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to create unlimited log storage");

    error_code = ext_log_upload_strategy_by_volume_create(&log_upload_strategy_context
                                                        , kaa_client_get_context(kaa_client)->channel_manager
                                                        , kaa_client_get_context(kaa_client)->bootstrap_manager);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to create log upload strategy");

    error_code = ext_log_upload_strategy_by_volume_set_threshold_count(log_upload_strategy_context
                                                                     , KAA_DEMO_UPLOAD_COUNT_THRESHOLD);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to set threshold log record count");

    error_code = kaa_logging_init(kaa_client_get_context(kaa_client)->log_collector
                                , log_storage_context
                                , log_upload_strategy_context);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to init Kaa log collector");

    /**
     * Start Kaa client main loop.
     */
    error_code = kaa_client_start(kaa_client, &kaa_demo_add_log_record, (void *)kaa_client, KAA_DEMO_LOG_GENERATION_FREQUENCY);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to start Kaa main loop");

    /**
     * Destroy Kaa client.
     */
    kaa_client_destroy(kaa_client);

    printf("Data collection demo stopped\n");

    return error_code;
}
Beispiel #8
0
int main(/*int argc, char *argv[]*/)
{
#ifdef CC32XX
    BoardInit();
    wlan_configure();
    sl_Start(0, 0, 0);
    wlan_connect("<SSID>", "<PASSWORD>", SL_SEC_TYPE_WPA_WPA2);//Into <SSID> and <PASSWORD> put your access point name and password
#endif
    DEMO_LOG("Configuration demo started");

    /**
     * Initialize Kaa client.
     */
    kaa_error_t error_code = kaa_client_create(&kaa_client, NULL);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed create Kaa client");

    kaa_configuration_root_receiver_t receiver = { NULL, &kaa_demo_configuration_receiver };
    error_code = kaa_configuration_manager_set_root_receiver(kaa_client_get_context(kaa_client)->configuration_manager, &receiver);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to add configuration receiver");

    kaa_demo_print_configuration_message(kaa_configuration_manager_get_configuration(kaa_client_get_context(kaa_client)->configuration_manager));

    /**
     * Start Kaa client main loop.
     */
    error_code = kaa_client_start(kaa_client, NULL, NULL, 0);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to start Kaa main loop");

    /**
     * Destroy Kaa client.
     */
    kaa_client_destroy(kaa_client);

    DEMO_LOG("Configuration demo stopped");
    return error_code;
}
Beispiel #9
0
int main(int argc, char *argv[])
{   
    if (argc != 5) {
        printf("Please, input + or - for audio, video and vibro supporting and directory for key storage. (Need 4 arguments)\n");
        exit(1);
    }
    
    mkdir(argv[4], 0777);
    chdir(argv[4]);

    /**
     * Initialize Kaa client.
     */
    kaa_error_t error_code = kaa_client_create(&kaa_client, NULL);
    if (error_code) {
        printf("Failed create Kaa client, error code %d\n", error_code);
        return EXIT_FAILURE;
    }
    
    kaa_profile_t *profile = kaa_profile_pager_client_profile_create();
    if (!profile) {
        printf("Failed to create profile\n");
        kaa_client_destroy(kaa_client);
        return EXIT_FAILURE;
    }
    
    const uint8_t *endpoint_key_hash = NULL;
    size_t endpoint_key_hash_length = 0;

    ext_get_sha1_base64_public(&endpoint_key_hash, &endpoint_key_hash_length);

    if (access(KAA_CONFIGURATION_STORAGE, F_OK) != -1) {
        printf("Waiting for new configuration for\n");
        printf("Endpoint ID %.*s\n", (int)endpoint_key_hash_length, endpoint_key_hash);
    }

    printf("- - -\n");
    printf("Endpoint ID %.*s\n", (int)endpoint_key_hash_length,
                endpoint_key_hash);


    profile->audio_support = set_client_parameter(argv[1]);
    profile->video_support = set_client_parameter(argv[2]);
    profile->vibro_support = set_client_parameter(argv[3]);

    printf("Profiling body (have audio-, video-, vibro-support):\n");
    printf("%s - %s - %s\n", profile->audio_support ? "true" : "false",
        profile->video_support ? "true" : "false",
        profile->vibro_support ? "true" : "false");

    error_code = kaa_profile_manager_update_profile(kaa_client_get_context(kaa_client)->profile_manager, profile);
    if (error_code) {
        printf("Failed to update profile, error code %d", error_code);
        kaa_client_destroy(kaa_client);
        return EXIT_FAILURE;
    }

    kaa_configuration_root_receiver_t receiver = {
        NULL,
        &kaa_demo_configuration_receiver,
    };

    error_code = kaa_configuration_manager_set_root_receiver(
        kaa_client_get_context(kaa_client)->configuration_manager,
        &receiver);
    if (error_code) {
        printf("Failed to add configuration receiver\n");
        kaa_client_destroy(kaa_client);
        return EXIT_FAILURE;
    }
    printf("Default configuration:\n");
    kaa_demo_print_configuration_message(
        kaa_configuration_manager_get_configuration(
            kaa_client_get_context(kaa_client)->configuration_manager));

    /**
     * Start Kaa client main loop.
     */
    error_code = kaa_client_start(kaa_client, NULL, NULL, 0);
    if (error_code) {
        printf("Failed to start Kaa main loop, error code %d\n", error_code);
        kaa_client_destroy(kaa_client);
        return EXIT_FAILURE;
    }
    
    /**
     * Destroy Kaa client.
     */
    kaa_client_destroy(kaa_client);

    return EXIT_SUCCESS;
}
Beispiel #10
0
int main(/*int argc, char *argv[]*/)
{
    log_info("Fan demo started");
    
    initFan(true);

    /**
     * Initialize Kaa client.
     */
    kaa_error_t error_code = kaa_client_create(&kaa_client, NULL);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed create Kaa client");

    kaa_attachment_status_listeners_t listeners = { NULL
                                                  , &kaa_on_attached
                                                  , &kaa_on_detached
                                                  , &kaa_on_attach_success
                                                  , &kaa_on_attach_failed };

    error_code = kaa_user_manager_set_attachment_listeners(kaa_client_get_context(kaa_client)->user_manager, &listeners);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to set user attach status listener");

    error_code = kaa_profile_manager_set_endpoint_access_token(kaa_client_get_context(kaa_client)->profile_manager
                                                                                    , KAA_ENDPOINT_ACCESS_TOKEN);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to set endpoint access token");

    error_code = kaa_event_manager_set_kaa_device_event_class_family_device_info_request_listener(
                        kaa_client_get_context(kaa_client)->event_manager, &kaa_on_device_info_request, NULL);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to set device info request listener");

    error_code = kaa_event_manager_set_kaa_fan_event_class_family_switch_request_listener(
                        kaa_client_get_context(kaa_client)->event_manager, &kaa_on_switch_request, NULL);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to set switch request listener");

    error_code = kaa_event_manager_set_kaa_device_event_class_family_device_change_name_request_listener(
                        kaa_client_get_context(kaa_client)->event_manager, &kaa_on_device_change_name_request, NULL);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to set device change name request listener");

    error_code = kaa_event_manager_set_kaa_device_event_class_family_device_status_subscription_request_listener(
                        kaa_client_get_context(kaa_client)->event_manager, &kaa_on_device_status_subscription_request, NULL);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to set device status subscription request listener");

    error_code = kaa_user_manager_default_attach_to_user(kaa_client_get_context(kaa_client)->user_manager
                                                                              , KAA_USER_ID
                                                                              , KAA_USER_ACCESS_TOKEN);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to attach to user");

    /**
     * Start Kaa client main loop.
     */
    error_code = kaa_client_start(kaa_client, NULL, NULL, 0);
    KAA_DEMO_RETURN_IF_ERROR(error_code, "Failed to start Kaa main loop");

    /**
     * Destroy Kaa client.
     */
    kaa_client_destroy(kaa_client);
    initFan(false);

    log_info("Fan demo stopped");

    return error_code;
}
Beispiel #11
0
kaa_error_t kaa_client_create(kaa_client_t **kaa_client, kaa_client_props_t *props)
{
    KAA_RETURN_IF_NIL2(kaa_client, props, KAA_ERR_BADPARAM);

    kaa_error_t error_code = KAA_ERR_NONE;

    error_code = kaa_init_security_stuff();
    KAA_RETURN_IF_ERR(error_code);

    kaa_client_t *self = sndc_mem_calloc(1,sizeof(kaa_client_t));
    KAA_RETURN_IF_NIL(self,KAA_ERR_NOMEM);

    self->thread_name = sndc_mem_strdup("Kaa-Client-Thread");
    self->operate = true;
    self->max_update_time = props->max_update_time;

    print_mem_stat(self);
    sndc_printf("Initializing Kaa SDK...\n");
    sndc_thrd_delay(TRACE_DELAY * SNDC_MILLISECOND);

    error_code = kaa_init(&self->kaa_context);
    if (error_code) {
        sndc_printf("Error during Kaa context creation %d\n", error_code);
        sndc_thrd_delay(TRACE_DELAY * SNDC_MILLISECOND);
        goto error;
    }

    KAA_LOG_INFO(self->kaa_context->logger, KAA_ERR_NONE, "Kaa framework initialized.");

    print_mem_stat(self);
    error_code = kaa_log_collector_init(self);
    if (error_code) {
        sndc_printf("Failed to init Kaa log collector %d\n", error_code);
        sndc_thrd_delay(TRACE_DELAY * SNDC_MILLISECOND);
        goto error;
    }

    KAA_LOG_INFO(self->kaa_context->logger, KAA_ERR_NONE, "Kaa log collector initialized.");

    *kaa_client = self;

    /* initialize semaphore */
    sndc_sem_init(&self->start_semophore, 0);
    sndc_sem_init(&self->logging_semophore, 0);

    int status = sndc_thrd_create(
            self->thread_name,
            thread_run_fn,
            (uintptr_t)self,
            SNDC_THRD_PRIORITY_DEFAULT,
            THREAD_STACKSIZE_DMR_START); //Defined 4K-8 bytes of stack

    switch (status) {
        case 0:

            break;
        case -EINVAL:
            error_code = KAA_ERR_BADPARAM;
            break;
        case -ENOMEM:
            error_code = KAA_ERR_NOMEM;
            break;
        default:
            error_code = KAA_ERR_BADDATA;
            break;
    }

    return error_code;

error:

    sndc_printf("Kaa initialization failed. error_code %d\n", error_code);
    sndc_thrd_delay(TRACE_DELAY * SNDC_MILLISECOND);
    kaa_client_destroy(self);

    return error_code;
}
Beispiel #12
0
int main(void)
{
    int rc = target_initialize();
    if (rc < 0) {
        return 1;
    }

    target_gpio_led_init();

    demo_printf("GPIO demo started\r\n");

    /**
     * Initialize Kaa client.
     */
    kaa_error_t error_code = kaa_client_create(&kaa_client, NULL);
    if (error_code) {
        demo_printf("Failed to create client context: %i\r\n", error_code);
        return 2;
    }

    error_code = kaa_profile_manager_set_endpoint_access_token(kaa_client_get_context(kaa_client)->profile_manager,
        DEMO_ACCESS_TOKEN);

    if (error_code) {
        demo_printf("Failed to set access token: %i\r\n", error_code);
        return 3;
    }

    error_code = kaa_event_manager_set_kaa_remote_control_ecf_device_info_request_listener(kaa_client_get_context(kaa_client)->event_manager,
            kaa_device_info_request,
            NULL);
    if (error_code) {
        demo_printf("Unable to set remote control listener: %i\r\n", error_code);
        return 4;
    }

    error_code = kaa_event_manager_set_kaa_remote_control_ecf_gpio_toggle_request_listener(kaa_client_get_context(kaa_client)->event_manager,
            kaa_GPIOToggle_info_request,
            NULL);
    if (error_code) {
        demo_printf("Unable to set GPIO listener: %i\r\n", error_code);
        return 5;
    }

    demo_printf("ACCESS_TOKEN :%s\r\n", DEMO_ACCESS_TOKEN);

    /**
     * Start Kaa client main loop.
     */
    error_code = kaa_client_start(kaa_client, kaa_external_process_fn, NULL, 0);
    if (error_code) {
        demo_printf("Unable to start Kaa client: %i\r\n", error_code);
        return 6;
    }

    /**
     * Destroy Kaa client.
     */
    kaa_client_destroy(kaa_client);

    demo_printf("GPIO demo stopped\r\n");

    return error_code;
}
Beispiel #13
0
int main(/*int argc, char *argv[]*/) {
    /**
     * Initialise a board
     */
    int ret = target_initialize();
    if (ret < 0) {
        /* If console is failed to initialise, you will not see this message */
        demo_printf("Failed to initialise a target\r\n");
        return EXIT_FAILURE;
    }

    demo_printf("Configuration demo started\r\n");

    /**
     * Initialize Kaa client.
     */
    kaa_error_t error_code = kaa_client_create(&kaa_client, NULL);
    if (error_code) {
        demo_printf("Failed create Kaa client\r\n");
        return EXIT_FAILURE;
    }

    /*
     * Set the handler for configuration updates.
     */
    kaa_configuration_root_receiver_t receiver = {
            NULL,
            &kaa_demo_configuration_receiver
    };

    error_code = kaa_configuration_manager_set_root_receiver(
            kaa_client_get_context(kaa_client)->configuration_manager,
            &receiver);

    if (error_code) {
        demo_printf("Failed to add configuration receiver\r\n");
        return EXIT_FAILURE;
    }

    /*
     * Display default configuration.
     */
    kaa_demo_print_configuration_message(
            kaa_configuration_manager_get_configuration(
                    kaa_client_get_context(kaa_client)->configuration_manager));

    /*
     * Obtain and display endpoint ID (represented by the EP key hash).
     */
    const uint8_t *endpoint_key_hash = NULL;
    size_t endpoint_key_hash_length = 0;

    ext_get_sha1_base64_public(&endpoint_key_hash, &endpoint_key_hash_length);

    printf("Endpoint ID: %.*s\r\n", (int)endpoint_key_hash_length,
            endpoint_key_hash);

    /**
     * Start Kaa client main loop.
     */
    error_code = kaa_client_start(kaa_client, NULL, NULL, 0);
    if(error_code) {
        demo_printf("Failed to start Kaa main loop\r\n");
        return EXIT_FAILURE;
    }

    /**
     * Destroy Kaa client.
     */
    kaa_client_destroy(kaa_client);

    return EXIT_SUCCESS;
}