示例#1
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;
}
示例#2
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;
}
示例#3
0
void checkFencingPosition(rfid_t rfid)
{
    kaa_context_t *kaa_context = kaa_client_get_context(kaa_client);
    const kaa_root_configuration_t *configuration = kaa_configuration_manager_get_configuration(kaa_context->configuration_manager);

    if (configuration) {
        int new_zone_id = UNKNOWN_GEOFENCING_ZONE_ID;

        kaa_list_node_t *zones_it = kaa_list_begin(configuration->zones);
        while (zones_it && (new_zone_id == UNKNOWN_GEOFENCING_ZONE_ID)) {
            kaa_configuration_geo_fencing_zone_t *zone = (kaa_configuration_geo_fencing_zone_t *)kaa_list_get_data(zones_it);
            kaa_list_node_t *zone_tag_it = kaa_list_begin(zone->tags);

            while (zone_tag_it && (new_zone_id == UNKNOWN_GEOFENCING_ZONE_ID)) {
                int64_t *tag = (int64_t *)kaa_list_get_data(zone_tag_it);
                if (*tag == rfid) {
                    new_zone_id = zone->id;
                }

                zone_tag_it = kaa_list_next(zone_tag_it);
            }
            zones_it = kaa_list_next(zones_it);
        }

        notifyOfNewFencingZone(new_zone_id);
    } else {
        debug("Skip check fencing position: configuration is null\r\n");
    }
}
示例#4
0
static void kaa_demo_add_log_record(void *context)
{
    static size_t log_record_counter = 0;

    float humidity = 0.0;
    float temperature = 0.0;

    if (dht11_read_val(DHT11_PIN, &humidity, &temperature) != 0) {
        printf("Failed to read data from sensor\n");
        return;
    }

    ++log_record_counter;

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

    log_record->sensor_id = kaa_string_copy_create("Sensor 1");
    log_record->region = kaa_string_copy_create("Region 1");
    log_record->model = kaa_string_copy_create("DHT11");
    log_record->value = temperature;

    printf("Going to add %zuth log record: { id: '%s', region: '%s', model: '%s', val: %g }\n"
            , log_record_counter, log_record->sensor_id->data, log_record->region->data, log_record->model->data, log_record->value);

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

    log_record->destroy(log_record);
}
示例#5
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);
}
示例#6
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;
}
示例#7
0
文件: kaa_demo.c 项目: xwiz/kaa
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;
}
示例#8
0
void kaa_on_switch_request(void *context, kaa_fan_event_class_family_switch_request_t *event, kaa_endpoint_id_p source) {
    log_info("SwitchRequest event received!");
    kaa_fan_event_class_family_fan_status_update_t *response = kaa_fan_event_class_family_fan_status_update_create();

    changeFanState(event->status);

    response->status = current_status;
    kaa_event_manager_send_kaa_fan_event_class_family_fan_status_update(kaa_client_get_context(kaa_client)->event_manager, response, source);

    response->destroy(response); // Destroying event that was successfully sent

    event->destroy(event);
}
示例#9
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;
}
示例#10
0
void notifyOfNewFencingZone(int zone_id)
{
    if (current_zone_id != zone_id) {
        current_zone_id = zone_id;

        debug("New zone detected, id=%d\r\n", current_zone_id);

        kaa_geo_fencing_event_class_family_geo_fencing_position_t position;
        switch (zone_id) {
        case ENUM_GEO_FENCING_ZONE_ID_HOME:
            position = ENUM_GEO_FENCING_POSITION_HOME;
            break;
        case ENUM_GEO_FENCING_ZONE_ID_NEAR:
            position = ENUM_GEO_FENCING_POSITION_NEAR;
            break;
        case UNKNOWN_GEOFENCING_ZONE_ID:
            position = ENUM_GEO_FENCING_POSITION_AWAY;
            break;
        default:
            debug("Unknown zone");
            return;
        }

        kaa_geo_fencing_event_class_family_geo_fencing_position_update_t *position_update =
                          kaa_geo_fencing_event_class_family_geo_fencing_position_update_create();
        if (position_update) {
            position_update->position = position;

            kaa_context_t *kaa_context = kaa_client_get_context(kaa_client);

            kaa_error_t error = kaa_event_manager_send_kaa_geo_fencing_event_class_family_geo_fencing_position_update(
                                                                        kaa_context->event_manager, position_update, NULL);
            if (error) {
                debug("Failed to send 'Position Update' event, code %d\r\n", error);
            }

            position_update->destroy(position_update);
        } else {
            debug("Failed to allocate position update event\r\n");
        }
    }
}
示例#11
0
void setup()
{
    pinMode(CH_PD, OUTPUT);
    pinMode(ESP8266_RST, OUTPUT);
    pinMode(BOARD_BUTTON_PIN, INPUT);
    pinMode(BOARD_LED_PIN, OUTPUT);
    pinMode(LEFT_LIGHT, OUTPUT);
    pinMode(RIGHT_LIGHT, OUTPUT);

    light_blink_counter = -1;
    systick_enable();

    esp8266_serial_init(&esp8266_serial, ESP_SERIAL, ESP_SERIAL_BAUD);
    if (!esp8266_serial) {
        debug("Serial Initialization failed, no memory\r\n");
        return;
    }

    RFID_READER.begin(RFID_BAUD_RATE);

    kaa_client_props_t props;
    props.serial = esp8266_serial;
    props.wifi_ssid = SSID;
    props.wifi_pswd = PWD;
    bool need_deallocation;
    ext_get_endpoint_public_key(&props.kaa_public_key, &props.kaa_public_key_length, &need_deallocation);
    kaa_error_t error = kaa_client_create(&kaa_client, &props);
    if (error) {
        debug("Failed to init Kaa client, error code %d\r\n", error);
        return;
    }

    error = kaa_user_manager_default_attach_to_user(kaa_client_get_context(kaa_client)->user_manager
                                                  , KAA_USER_ID
                                                  , KAA_USER_ACCESS_TOKEN);
    if (error) {
        debug("Failed to attach to user '%s', error code %d\r\n", KAA_USER_ID, error);
        return;
    }


}
示例#12
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++;
}
示例#13
0
void sendRFIDLog(rfid_t rfid)
{
    light_blink_time = millis();
    lightOn(true, true);
    light_blink_counter = 0;
    kaa_context_t *kaa_context = kaa_client_get_context(kaa_client);

    kaa_user_log_record_t *log_record = kaa_logging_rfid_log_create();
    if (log_record) {
        log_record->tag = rfid;

        kaa_error_t error = kaa_logging_add_record(kaa_context->log_collector, log_record);
        if (error) {
            debug("Failed to add log record, code %d\r\n", error);
        } else {
            debug("Log record sent\r\n");
        }
        log_record->destroy(log_record);
    } else {
        debug("Failed to allocate log record\r\n");
    }
}
示例#14
0
void kaa_on_device_info_request(void *context
                              , kaa_device_event_class_family_device_info_request_t *event
                              , kaa_endpoint_id_p source)
{
    log_info("DeviceInfoRequest event received!");

    kaa_device_event_class_family_device_info_response_t *response =
            kaa_device_event_class_family_device_info_response_create();
    kaa_device_event_class_family_device_info_t *info = kaa_device_event_class_family_device_info_create();

    info->name = kaa_string_copy_create(device_name);
    info->model = kaa_string_copy_create(device_model);

    response->device_info = info;

    kaa_event_manager_send_kaa_device_event_class_family_device_info_response(kaa_client_get_context(kaa_client)->event_manager, response,
    source);

    log_info("DeviceInfoResponse sent!");
    response->destroy(response);

    event->destroy(event);
}
示例#15
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);
    }
}
示例#16
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;
}
示例#17
0
static void APP_main()
{
   ip_connected = false;
   kaa_started = false;

   kaa_error_t kaa_error = KAA_ERR_NONE;
   { //Used to limit kaa_props visibility, it creates on stack and release once is used
       kaa_client_props_t kaa_props;
       kaa_props.max_update_time = 2;
       kaa_error = kaa_client_create(&kaa_client, &kaa_props);
       if (kaa_error) {
           sndc_printf("Error %d initializing Kaa client \n",kaa_error);
           return;
       }
   }

   kaa_list_t *zones = kaa_list_create();
   int i = 0;
   for(; i < LIGHT_ZONES_COUNT; ++i) {
       sndc_io_setMode(light_zones[i], IO_MODE_OUTPUT);
       sndc_io_write(light_zones[i], LIGHT_OFF);
       int32_t *zone_id = (int32_t *) KAA_MALLOC(sizeof(int32_t));
       *zone_id = i;
       kaa_list_push_front(zones, zone_id);
   }
   kaa_profile_street_lights_profile_t *profile = kaa_profile_street_lights_profile_create();
   profile->light_zones = zones;
   kaa_profile_manager_update_profile(kaa_client_get_context(kaa_client)->profile_manager, profile);
   profile->destroy(profile);

   /**
    * Configuration example, below is how to configure and read default configuration values
    */
   kaa_configuration_root_receiver_t receiver = { NULL, &kaa_on_configuration_updated };
   kaa_error = kaa_configuration_manager_set_root_receiver(kaa_client_get_context(kaa_client)->configuration_manager, &receiver);
   sndc_printf("Configuration setting done. %d\n", kaa_error);
   //sndc_thrd_delay(TRACE_DELAY * SNDC_MILLISECOND);
   const kaa_root_configuration_t *root_config = kaa_configuration_manager_get_configuration(kaa_client_get_context(kaa_client)->configuration_manager);
   kaa_on_configuration_updated(NULL, root_config);

   //set SW2 button as key input
   //sndc_io_ctrl(BUTTON,
   //             IO_PIN_FUNC_PULL_UP,
   //             IO_PIN_DRIVE_DEFAULT,
   //             IO_PIN_SLEW_RATE_DEFAULT);
   //sndc_io_setMode(BUTTON, IO_MODE_KEY);

   //sndc_device_config = sndc_config_get();

   /* clean all profiles */
   //sndc_profile_eraseAll();
   //sndc_printf("Press SW2 to start test. \n");

   start_client();

   //infinite thread loop, button press is monitored by system events
   while(1)
   {

      if (ip_connected && !kaa_started) {
          kaa_client_start(kaa_client, NULL, NULL, 0);
          kaa_started = true;
      }
      //thread sleep for 500 ms
      sndc_thrd_delay(500 * SNDC_MILLISECOND);
   }
}
示例#18
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;
}
示例#19
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;
}
示例#20
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;
}
示例#21
0
static void kaa_device_info_request(void *context
                           , kaa_remote_control_ecf_device_info_request_t *event
                           , kaa_endpoint_id_p source)
{
    (void)context;
    (void)source;

    demo_printf("Device info request received\r\n");
    kaa_remote_control_ecf_device_info_response_t *response = kaa_remote_control_ecf_device_info_response_create();

    response->device_name = kaa_string_copy_create(TARGET_DEVICE_NAME);
    response->model       = kaa_string_copy_create(TARGET_MODEL_NAME);
    response->gpio_status = kaa_list_create();
    for (int i = 0; i < target_gpio_led_get_count(); ++i) {
        gpio_port_t *gpio_led = target_get_gpio_port( i );
        if (gpio_led) {
            kaa_remote_control_ecf_gpio_status_t *gio_status = kaa_remote_control_ecf_gpio_status_create();
            gio_status->id = i;
            gio_status->status = gpio_led->state;
            gio_status->type = kaa_string_copy_create( gpio_led->id );
            kaa_list_push_back(response->gpio_status, (void*)gio_status);
        }
    }
    kaa_error_t err = kaa_event_manager_send_kaa_remote_control_ecf_device_info_response(kaa_client_get_context(kaa_client)->event_manager, response, NULL);

    response->destroy(response); // Destroying event that was successfully sent
    event->destroy(event);
}