Updating and Browsing State

A thing can upload its state to Thing Interaction Framework. You can browse the uploaded state.

In this guide, we will explain how to upload a state from a thing and how to browse the uploaded state on the developer portal.

Uploading state

Uploading the state can take place at a regular interval. The state is to be generated in the JSON format based on a trait registered in Registering Thing Capability. See State Registration and Retrieval for the overview.

The SDK creates a task (thread) for updating states and call the state updater from this task at the regular intervals. The interval is to be set upon the initialization.

The state uploading timing is solely controlled by the SDK. You cannot explicitly update the state from the thing program.

Depending on the logic of the callback function, you may need to implement some exclusive control. See here for more discussion on the task control.

Callback functions for state uploading

Prototypes of the state uploader callback functions are as follows:

  • Callback function for setting upload size

    This is a callback function for notifying the size of the data to be uploaded. This function should return the size of JSON to upload.

    typedef size_t (*TIO_CB_SIZE)(void* userdata);
    
  • Callback function for setting upload data

    This is a callback function for passing the upload data to the SDK. The function should set the data in the buffer and return the size of data. The data size should be less than the size.

    This callback will be executed multiple times in one data uploading; if you are uploading big data, pass the data by chunks. When all data is passed, return 0 to end the data passing.

    typedef size_t (*TIO_CB_READ)(char *buffer, size_t size, void *userdata);
    

Start state uploading

To start the state uploading, execute tio_updater_start method while setting the two callback functions mentioned earlier and use data (e.g., updater_cb_*_ctx in the sample code) in its arguments. The task for uploading the data will be created and executed.

You need kii_author_t for this execution. Get the value from the instance that you've used for onboarding. In this example, we are getting the value from the tio_handler_t instance. If you've onboard with the tio_updater_t instance, use the tio_updater_get_author method instead.

const kii_author_t* author = tio_handler_get_author(&handler);

tio_updater_start(
        &updater,
        author,
        updater_cb_size,
        &updater_cb_size_ctx,
        updater_cb_read,
        &updater_cb_read_ctx);

For more information on each callback function, see sample codes for your environments stored in ebisu/tio.

Browsing state

You can browse the state on the Thing Console of the developer portal.

See Manage States for how to use the console.