代码如下:#include#include#include#include#include#include#include#include
代码如下:#include #include #include #include #include #include #include #include #include #include #include #include #include static int32_t sample_period;static time_t last_sample_time;extern kaa_error_t ext_unlimited_log_storage_create(void **log_storage_context_p, kaa_logger_t *logger);/* Retrieves current temperature. */static int32_t get_temperature_sample(void){ /* For the sake of example, random data is used */ return rand() % 10 + 25;}/* Periodically called by Kaa SDK. */static void example_callback(void *context){ time_t current_time = time(NULL); /* Respect sample period */ if (difftime(current_time, last_sample_time) >= sample_period) { int32_t temperature = get_temperature_sample(); printf("Sampled temperature: %i\n", temperature); last_sample_time = current_time; kaa_user_log_record_t *log_record = kaa_logging_data_collection_create(); log_record->temperature = temperature; kaa_logging_add_record(kaa_client_get_context(context)->log_collector, log_record, NULL); }}/* Receives new configuration data. */static kaa_error_t on_configuration_updated(void *context, const kaa_root_configuration_t *conf){ (void) context; printf("Received configuration data. New sample period: %i seconds\n", conf->sample_period); sample_period = conf->sample_period; return KAA_ERR_NONE;}int main(void){ /* Init random generator used to generate temperature */ srand(time(NULL)); /* Prepare Kaa client. */ kaa_client_t *kaa_client = NULL; kaa_error_t error = kaa_client_create(&kaa_client, NULL); if (error) {//部分省略报错命令如下:
展开