|
Google Cloud IoT device SDK for embedded C
1.0.2
|
Go to the source code of this file.
Variables | |
| const uint16_t | iotc_major |
| const uint16_t | iotc_minor |
| const uint16_t | iotc_revision |
| const char | iotc_cilent_version_str [] |
Connects to and communicates with Cloud IoT Core.
Definition in file iotc.h.
| void iotc_cancel_timed_task | ( | iotc_timed_task_handle_t | timed_task_handle | ) |
Removes a scheduled task from the internal event system.
| [in] | timed_task_handle | A unique ID for the scheduled task. |
| iotc_state_t iotc_connect | ( | iotc_context_handle_t | iotc_h, |
| const char * | username, | ||
| const char * | password, | ||
| const char * | client_id, | ||
| uint16_t | connection_timeout, | ||
| uint16_t | keepalive_timeout, | ||
| iotc_user_callback_t * | client_callback | ||
| ) |
Connects to Cloud IoT Core.
| [in] | iotc_h | A context handle. |
| [in] | username | The MQTT username. Cloud IoT Core ignores this parameter, but some platforms will not send the password field unless the username field is specified. For best results, supply an arbitrary username like "unused" or "ignored." |
| [in] | password | The MQTT password. Cloud IoT Core requires a JWT. |
| [in] | client_id | The MQTT client ID. Cloud IoT Core requires a device path. |
| [in] | connection_timeout | The number of seconds to wait for an MQTT CONNACK response before closing the socket. If 0, the TCP timeout is used. |
| [in] | keepalive_timeout | The number of seconds the broker will wait for the client application to send a PINGREQ message. The PINGREQ is automatically sent at the specified interval, so you don't need to write the PINGREQ message contents. |
| [in] | (Optional) | client_callback The callback function. Invoked when the client connects to or is disconnected from the MQTT broker. |
| iotc_state_t iotc_connect_to | ( | iotc_context_handle_t | iotc_h, |
| const char * | host, | ||
| uint16_t | port, | ||
| const char * | username, | ||
| const char * | password, | ||
| const char * | client_id, | ||
| uint16_t | connection_timeout, | ||
| uint16_t | keepalive_timeout, | ||
| iotc_user_callback_t * | client_callback | ||
| ) |
Connects to a custom MQTT broker endpoint.
Performs the same operations as iotc_connect() but you can configure the endpoint.
| [in] | host | The address at which the client connects. |
| [in] | port | The port of the host on which to connect. |
| [in] | iotc_h | A context handle. |
| [in] | username | The MQTT username. Some platforms will not send the password field unless the username field is specified. |
| [in] | password | The MQTT password. |
| [in] | client_id | The MQTT client ID. |
| [in] | connection_timeout | The number of seconds to wait for an MQTT CONNACK response before closing the socket. If 0, the TCP timeout is used. |
| [in] | keepalive_timeout | The number of seconds the broker will wait for the client application to send a PINGREQ message. The PINGREQ is automatically sent at the specified interval, so you don't need to write the PINGREQ message contents. |
| [in] | (Optional) | client_callback The callback function. Invoked when the client connects to or is disconnected from the MQTT broker. |
| iotc_context_handle_t iotc_create_context | ( | ) |
Creates a connection context. If this function fails, it returns the opposite of the numeric error code.
Before running this function, call iotc_initialize().
| iotc_state_t iotc_delete_context | ( | iotc_context_handle_t | context_handle | ) |
Frees the provided context.
If iotc_events_process_blocking() invokes the event engine, the client application must free the context after iotc_events_process_blocking() returns. The application must free the context on the event loop tick after the disconnection event (not in the disconnection callback itself).
| [in] | context_handle | The context handle to free. |
| void iotc_events_process_blocking | ( | ) |
Invokes the event processing loop and executes event engine as the main application process. This function processes events on platforms with main application loops that can block indefinitely. For other platforms, call iotc_events_process_tick().
You can call this function anytime but it returns only after calling iotc_events_stop().
The event engine won't process events when the IoT device SDK is in the IOTC_EVENT_PROCESS_STOPPED state. If the function returns IOTC_EVENT_PROCESS_STOPPED, shutdown and reinitialize the IoT device SDK to process events again.
| iotc_state_t iotc_events_process_tick | ( | ) |
Invokes the event processing loop on RTOS or non-OS devices that must yield for standard tick operations.
The event engine won't process events when the IoT device SDK is in the IOTC_EVENT_PROCESS_STOPPED state. If the function returns IOTC_EVENT_PROCESS_STOPPED, shutdown and reinitialize the IoT device SDK to process events again.
| void iotc_events_stop | ( | ) |
Shuts down the event engine.
| iotc_state_t iotc_get_heap_usage | ( | size_t *const | heap_usage | ) |
Gets the amount of heap memory allocated to the SDK.
This function is part of the memory limiter. If no heap memory is allocated, this function runs but returns IOTC_INVALID_PARAMETER.
| uint32_t iotc_get_network_timeout | ( | void | ) |
Gets the connection timeout.
| iotc_state_t iotc_initialize | ( | ) |
Initializes the time and random number libraries in the BSP. You must call this function before you create a new connection context.
| uint8_t iotc_is_context_connected | ( | iotc_context_handle_t | context_handle | ) |
Checks if a context is connected to Cloud IoT Core.
| [in] | context_handle | The handle for which to determine the connection. |
| 1 | The context is connected to Cloud IoT Core. |
| 0 | The context is invalid or the connection is either uninitialized, connecting, closing, or closed. |
| iotc_state_t iotc_publish | ( | iotc_context_handle_t | iotc_h, |
| const char * | topic, | ||
| const char * | msg, | ||
| const iotc_mqtt_qos_t | qos, | ||
| iotc_user_callback_t * | callback, | ||
| void * | user_data | ||
| ) |
Publishes a message to an MQTT topic.
| [in] | iotc_h | A context handle. |
| [in] | topic | The MQTT topic. |
| [in] | msg | The payload of the message. |
| [in] | qos | The Quality of Service (QoS) level. Can be 0 or 1. QoS level 2 isn't supported. |
| [in] | callback | (Optional) The callback function. Invoked after a message is successfully or unsuccessfully delivered. |
| [in] | (Optional) | callback The callback function. Invoked when the client connects to or is disconnected from the MQTT broker. |
| [in] | user_data | (Optional) Abstract data passed to the callback function. |
| iotc_state_t iotc_publish_data | ( | iotc_context_handle_t | iotc_h, |
| const char * | topic, | ||
| const uint8_t * | data, | ||
| size_t | data_len, | ||
| const iotc_mqtt_qos_t | qos, | ||
| iotc_user_callback_t * | callback, | ||
| void * | user_data | ||
| ) |
Publishes binary data to an MQTT topic.
Performs the same operations as iotc_publish() but the payload can contain bytes with zero values.
| [in] | iotc_h | A context handle. |
| [in] | topic | The MQTT topic. |
| [in] | data | A pointer to a buffer with the message payload. |
| [in] | data_len | The size, in bytes, of the message. |
| [in] | qos | The Quality of Service (QoS) level. Can be 0 or 1. QoS level 2 isn't supported. |
| [in] | callback | (Optional) The callback function. Invoked after a message is successfully or unsuccessfully delivered. |
| [in] | user_data | (Optional) Abstract data passed to the callback function. |
| iotc_timed_task_handle_t iotc_schedule_timed_task | ( | iotc_context_handle_t | iotc_h, |
| iotc_user_task_callback_t * | callback, | ||
| const iotc_time_t | seconds_from_now, | ||
| const uint8_t | repeats_forever, | ||
| void * | data | ||
| ) |
Returns a unique ID for the scheduled task and invokes a callback after an interval.
This is a non-blocking function until the callback is invoked. If the callback returns an error, the ID is the opposite of the numeric error code.
| [in] | iotc_h | A context handle. |
| [in] | iotc_user_task_callback_t | The function invoked after an interval. |
| [in] | seconds_from_now | The number of seconds to wait before invoking the callback. |
| [in] | repeats_forever | If the repeats_forever parameter is set to 0, the callback is executed only once. Otherwise, the callback is repeatedly executed at seconds_from_now intervals. |
| [in] | data | (Optional) A pointer that will be passed to the callback function's user_data parameter. |
| iotc_state_t iotc_set_fs_functions | ( | const iotc_fs_functions_t | fs_functions | ) |
Sets the file operations to the custom file management functions in the BSP.
| iotc_state_t iotc_set_maximum_heap_usage | ( | const size_t | max_bytes | ) |
Sets the maximum heap memory that the SDK can use.
This function is part of the memory limiter.
| [in] | max_bytes | The maximum amount of heap memory, in bytes, that the IoT device SDK can use during standard execution. |
| void iotc_set_network_timeout | ( | uint32_t | timeout | ) |
Sets the connection timeout.
Only new connections observe this timeout.
Note: The IoT device SDK periodically creates network traffic per MQTT specifications.
| [in] | timeout | The number of seconds sockets remain open when data isn't passing through them. When the socket initializes, this parameter is passed to the implemented networking layer to automatically keep connections open. |
| iotc_state_t iotc_shutdown | ( | ) |
Shuts down the IoT device SDK and frees all resources created during initialization. Free all contexts before calling this function.
| iotc_state_t iotc_shutdown_connection | ( | iotc_context_handle_t | iotc_h | ) |
Disconnects asynchronously from an MQTT broker.
After disconnecting, the disconnection status code is passed to the iotc_connect() callback. You may reuse disconnected contexts until iotc_events_stop() returns; you don't need to destroy and recreate contexts.
| [in] | iotc_h | A context handle. |
| iotc_state_t iotc_subscribe | ( | iotc_context_handle_t | iotc_h, |
| const char * | topic, | ||
| const iotc_mqtt_qos_t | qos, | ||
| iotc_user_subscription_callback_t * | callback, | ||
| void * | user_data | ||
| ) |
Subscribes to an MQTT topic.
| [in] | iotc_h | A context handle. |
| [in] | topic | The MQTT topic. |
| [in] | qos | The Quality of Service (QoS) level. Can be 0, 1, or 2. |
| [in] | callback | The callback invoked after a message is published to the MQTT topic. |
| [in] | user_data | (Optional) A pointer that to the callback function's user_data parameter. |
| const char iotc_cilent_version_str[] |
The SDK "{@link ::iotc_major major}.{@link ::iotc_minor minor}.{@link ::iotc_revision revision}" version string.
| const uint16_t iotc_major |
The SDK major version number.
| const uint16_t iotc_minor |
The SDK minor version number.
| const uint16_t iotc_revision |
The SDK revision number.