示例#1
0
文件: kaa_demo.c 项目: xwiz/kaa
static void kaa_demo_add_log_record(void *context)
{
    if (log_record_counter++ >= KAA_DEMO_LOGS_TO_SEND) {
        kaa_client_stop((kaa_client_t *)context);
        return;
    }

    printf("Going to add %zuth log record\n", log_record_counter);

    kaa_user_log_record_t *log_record = kaa_logging_log_data_create();
    if (!log_record) {
        printf("Failed to create log record, error code %d\n", KAA_ERR_NOMEM);
        return;
    }

    log_record->level = ENUM_LEVEL_KAA_INFO;
    log_record->tag = kaa_string_move_create(KAA_DEMO_LOG_TAG, NULL);

    char log_message_buffer[32];
    snprintf(log_message_buffer, 32, KAA_DEMO_LOG_MESSAGE"%zu", log_record_counter);

    log_record->message = kaa_string_copy_create(log_message_buffer);

    kaa_error_t error_code = kaa_logging_add_record(kaa_client_get_context(kaa_client)->log_collector, log_record);
    if (error_code) {
        printf("Failed to add log record, error code %d\n", error_code);
    }

    log_record->destroy(log_record);
}
示例#2
0
void process(void *context)
{
    uint8 l = 0;
    if (SerialUSB.available()) {
        l = SerialUSB.read();
        if (l == 'S') {
            debug("\'S\' stop Kaa client\r\n");
            if (kaa_client)
                kaa_client_stop(kaa_client);
        }
    }

    if (light_blink_counter >= 0) {
        if ((millis() - light_blink_time) >= LIGHT_BLINK_TIME) {
            light_blink_counter++;
            light_blink_time = millis();
            if ((light_blink_counter % 2) == 0) {
                lightOn(true, true);
            } else {
                lightOff(true, true);
            }
        }
        if (light_blink_counter > LIGHT_BLINK_NUMBER) {
            lightOff(true, true);
            light_blink_counter = -1;
        }
    }

    readRFID();
}
示例#3
0
kaa_error_t kaa_demo_configuration_receiver(void *context, const kaa_root_configuration_t *configuration)
{
    (void) context;
    KAA_LOG_TRACE(kaa_client_get_context(kaa_client)->logger, KAA_ERR_NONE, "Received configuration data");
    kaa_demo_print_configuration_message(configuration);
    kaa_client_stop(kaa_client);
    return KAA_ERR_NONE;
}
示例#4
0
kaa_error_t kaa_demo_configuration_receiver(void *context,
                                            const kaa_root_configuration_t *configuration) {
    (void) context;
    demo_printf("Received configuration data\n");
    kaa_demo_print_configuration_message(configuration);
    kaa_client_stop(kaa_client);
    return KAA_ERR_NONE;
}
示例#5
0
kaa_error_t kaa_demo_configuration_receiver(void *context,
                                            const kaa_root_configuration_t *configuration)
{
    (void)context;
    
    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("- - -\n");
    printf("Endpoint ID %.*s\n", (int)endpoint_key_hash_length,
                endpoint_key_hash);

    printf("Configuration was succesfully edited:\n");
    kaa_demo_print_configuration_message(configuration);
    kaa_client_stop(kaa_client);
    return KAA_ERR_NONE;
}
示例#6
0
static void kaa_demo_add_log_record(void *context)
{
    (void) context;

    if (log_record_counter >= KAA_DEMO_LOGS_TO_SEND) {
        printf("All logs are sent, waiting for responce\n");
        if (log_successfully_sent_counter == KAA_DEMO_LOGS_TO_SEND) {
            printf("All logs successfully sent, stopping demo...\n");
            kaa_client_stop(context);
        }
        return;
    }

    printf("Going to add %zuth log record\n", log_record_counter);

    kaa_user_log_record_t *log_record = kaa_logging_log_data_create();
    if (!log_record) {
        printf("Failed to create log record, error code %d\n", KAA_ERR_NOMEM);
        return;
    }

    log_record->level = ENUM_LEVEL_KAA_INFO;
    log_record->tag = kaa_string_move_create(KAA_DEMO_LOG_TAG, NULL);

    char log_message_buffer[KAA_DEMO_LOG_BUF_SZ];
    snprintf(log_message_buffer, KAA_DEMO_LOG_BUF_SZ, KAA_DEMO_LOG_MESSAGE"%zu", log_record_counter);

    log_record->message = kaa_string_copy_create(log_message_buffer);

    kaa_log_record_info_t log_info;
    kaa_error_t error_code = kaa_logging_add_record(kaa_client_get_context(kaa_client)->log_collector, log_record, &log_info);
    if (error_code) {
        printf("Failed to add log record, error code %d\n", error_code);
    } else {
        printf("Log record: %u added to bucket %u\n", log_info.log_id, log_info.bucket_id);
    }

    log_record->destroy(log_record);
    log_record_counter++;
}
示例#7
0
static void kaa_demo_add_log_record(void *context)
{
    static size_t log_number = LOGS_TO_SEND_COUNT;

    kaa_logging_power_report_t *log_record = kaa_logging_power_report_create();
    if (!log_record) {
        printf("Failed to create log record, error code %d\n", KAA_ERR_NOMEM);
        return;
    }

    log_record->timestamp = time(NULL) * 1000; // expected in millis
    log_record->samples = kaa_list_create();

    size_t zone_id = 0;
    size_t panel_id = 0;
    for (zone_id = 0; zone_id < ZONE_COUNT; ++zone_id) {
        for (panel_id = 0; panel_id < PANEL_COUNT; ++panel_id) {
            kaa_logging_power_sample_t *sample = kaa_logging_power_sample_create();
            sample->zone_id = zone_id;
            sample->panel_id = panel_id;
            sample->power = get_random_double(MAX_PANEL_POWER);

            kaa_list_push_back(log_record->samples, sample);
        }
    }

    kaa_error_t error_code = kaa_logging_add_record(kaa_client_get_context((kaa_client_t *)context)->log_collector, log_record);
    if (error_code) {
        printf("Failed to add log record, error code %d\n", error_code);
    }

    log_record->destroy(log_record);

    if (!--log_number) {
        kaa_client_stop(kaa_client);
    }
}
示例#8
0
kaa_error_t kaa_on_attach_failed(void *context, user_verifier_error_code_t error_code, const char *reason) {
    log_info("Kaa Demo attach failed");
    kaa_client_stop(kaa_client);
    return KAA_ERR_NONE;
}