Google Cloud IoT device SDK for embedded C  1.0.2

The Cloud IoT device SDK for embedded C is a library of source files for securely connecting to and communicating with Cloud IoT Core. The SDK is designed for embedded IoT devices, so the SDK:

  • Communicates over MQTT v3.1.1 with TLS.
  • Publishes and subscribes asychronously.
  • Abstracts hardware-specific drivers and routines in the Board Support Package.
  • Runs on single, non-blocking thread and operates a thread-safe event queue.

Installing the SDK

To use the SDK:

  1. Download the latest version.

    git clone --recurse-submodules
  2. Include the main library files in the client application.

    #include <iotc.h>
    #include <iotc_error.h>
    #include <iotc_jwt.h>

Function summary

The following tables list the functions you can use to communicate over MQTT.

Configuring the SDK

Function Description
iotc_initialize() Initializes the time and random number libraries in the BSP.
iotc_shutdown() Shuts down the SDK and frees all resources created during initialization.
iotc_get_heap_usage() Gets the amount of heap memory allocated to the SDK.
iotc_get_network_timeout() Gets the connection timeout.
iotc_get_state_string() Gets the state message associated with a numeric code.
iotc_set_fs_functions() Sets the file operations to the custom file management functions in the BSP.
iotc_set_maximum_heap_usage() Sets the maximum heap memory that the SDK can use.
iotc_set_network_timeout() Sets the connection timeout.

Defining and managing connection contexts

Function Description
iotc_create_context() Creates a connection context.
iotc_delete_context() Deletes and frees the provided context.
iotc_is_context_connected() Checks if a context is connected to an MQTT broker.

Creating and managing MQTT connections

Function Description
iotc_connect() Connects to Cloud IoT Core.
iotc_connect_to() Connects to a custom MQTT broker endpoint.
iotc_create_iotcore_jwt() Creates a JSON Web Token for authenticating to Cloud IoT Core.
iotc_shutdown_connection() Disconnects asynchronously from an MQTT broker.

Sending and receiving messages

Function Description
iotc_publish() Publishes a message to an MQTT topic.
iotc_publish_data() Publishes binary data to an MQTT topic.
iotc_subscribe() Subscribes to an MQTT topic.

Scheduling functions

Function Description
iotc_schedule_timed_task() Invokes a callback after an interval.
iotc_cancel_timed_task() Removes a scheduled task from the internal event system.
iotc_events_process_blocking() Invokes the event processing loop and executes the event engine as the main application process.
iotc_events_process_tick() Invokes the event processing loop on RTOS or non-OS devices that must yield for standard tick operations.
iotc_events_stop() Shuts down the event engine.

Board Support Package

The SDK depends on hardware-specific drivers and routines to implement MQTT with TLS. Embedded systems rely on unique hardware, so the SDK abstracts these dependencies in the Board Support Package (BSP).

The SDK has a turn-key POSIX BSP, so the SDK builds natively on POSIX platforms. You can customize the BSP to port the SDK to non-POSIX platforms.

Example MQTT clients

The repository has example client applications for connecting: