Google Cloud IoT Device SDK for Embedded C API
iotc.h
Go to the documentation of this file.
1 /* Copyright 2018-2019 Google LLC
2  *
3  * This is part of the Google Cloud IoT Device SDK for Embedded C,
4  * it is licensed under the BSD 3-Clause license; you may not use this file
5  * except in compliance with the License.
6  *
7  * You may obtain a copy of the License at:
8  * https://opensource.org/licenses/BSD-3-Clause
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __IOTC_H__
18 #define __IOTC_H__
19 
20 #include <stdint.h>
21 #include <stdlib.h>
22 
23 #include <iotc_connection_data.h>
24 #include <iotc_mqtt.h>
25 #include <iotc_time.h>
26 #include <iotc_types.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
79 /* -----------------------------------------------------------------------
80  * MAIN LIBRARY FUNCTIONS
81  * ----------------------------------------------------------------------- */
82 
90 
108 extern iotc_state_t iotc_shutdown();
109 
124 
149 
164 extern uint8_t iotc_is_context_connected(iotc_context_handle_t context_handle);
165 
185 extern void iotc_events_process_blocking();
186 
220 
229 extern void iotc_events_stop();
230 
279  const char* username, const char* password,
280  const char* client_id,
281  uint16_t connection_timeout,
282  uint16_t keepalive_timeout,
283  iotc_user_callback_t* client_callback);
284 
298  const char* host, uint16_t port,
299  const char* username, const char* password,
300  const char* client_id,
301  uint16_t connection_timeout,
302  uint16_t keepalive_timeout,
303  iotc_user_callback_t* client_callback);
304 
305 /*
306  * @detailed Using the provided context, this function requests that a message
307  * be delivered to the IoT Core service on the given topic. This requires that a
308  * connection has already been established to the IoT Core service via a call
309  * to iotc_connect or iot_connect_to.
310  *
311  * The callback function should have the following signature:
312  * void foo( iotc_context_handle_t in_context_handle
313  * , void* user_data
314  * , iotc_state_t state )
315  *
316  * where the callback parameters are:
317  * - in_context_handle is context handle that you provided to iotc_publish.
318  * - user_data is the value that the application passed in the user_data
319  * parameter of the publish call (below.) This can be used for you attach
320  * any sort support data or relevant data that would help identify the message.
321  * - state should be IOTC_STATE_OK if the publication succeded, or a non ok
322  * value if the publish failed.
323  *
324  * please return IOTC_STATE_OK for these callbacks.
325  *
326  * @param [in] iotc_h a context handle created by invoking iotc_create_context.
327  * @param [in] topic a string based topic name that you have created for
328  * messaging via the IoT Core webservice.
329  * @param [in] msg the payload to send to the IoT Core service.
330  * @param [in] qos Quality of Service MQTT level. 0, 1, or 2. Please see MQTT
331  * specification or iotc_mqtt_qos_e in iotc_mqtt_message.h for constant values.
332  * Note: Currently Google Cloud IoT Core does not support QoS 2.
333  * @param [in] callback Optional callback function that will be called upon
334  * successful or unsuccessful msg delivery. This may be NULL.
335  * @param [in] user_data Optional abstract data that will be passed to callback
336  * when the publication completes. This may be NULL.
337  *
338  * @see iotc_create_context
339  * @see iotc_publish_data
340  *
341  * @retval IOTC_STATE_OK If the publication request was formatted
342  * correctly and has be queued for publication.
343  * @retval IOTC_OUT_OF_MEMORY If the platform did not have enough free memory
344  * to fulfill the request.
345  * @retval IOTC_INTERNAL_ERROR If an unforseen and unrecoverable error has
346  * occurred.
347  * @retval IOTC_BACKOFF_TERMINAL If backoff has been applied.
348  */
350  const char* topic, const char* msg,
351  const iotc_mqtt_qos_t qos,
352  iotc_user_callback_t* callback,
353  void* user_data);
354 
379  const char* topic, const uint8_t* data,
380  size_t data_len,
381  const iotc_mqtt_qos_t qos,
382  iotc_user_callback_t* callback,
383  void* user_data);
384 
438  const char* topic, const iotc_mqtt_qos_t qos,
440  void* user_data);
441 
458 
502  const iotc_time_t seconds_from_now, const uint8_t repeats_forever,
503  void* data);
504 
516 void iotc_cancel_timed_task(iotc_timed_task_handle_t timed_task_handle);
517 
518 /*-----------------------------------------------------------------------
519  * HELPER FUNCTIONS
520  * ---------------------------------------------------------------------- */
521 
539 extern void iotc_set_network_timeout(uint32_t timeout);
540 
549 extern uint32_t iotc_get_network_timeout(void);
550 
576 iotc_state_t iotc_set_maximum_heap_usage(const size_t max_bytes);
577 
595 iotc_state_t iotc_get_heap_usage(size_t* const heap_usage);
596 
601 extern const uint16_t iotc_major;
602 
607 extern const uint16_t iotc_minor;
608 
612 extern const uint16_t iotc_revision;
613 
619 extern const char iotc_cilent_version_str[];
620 
621 #ifdef IOTC_EXPOSE_FS
622 #include "iotc_fs_api.h"
623 
628 iotc_state_t iotc_set_fs_functions(const iotc_fs_functions_t fs_functions);
629 
630 #endif /* IOTC_EXPOSE_FS */
631 
632 #ifdef __cplusplus
633 }
634 #endif
635 
636 #endif /* __IOTC_H__ */
void() iotc_user_task_callback_t(const iotc_context_handle_t context_handle, const iotc_timed_task_handle_t timed_task_handle, void *user_data)
Definition: iotc_types.h:57
iotc_state_t iotc_events_process_tick()
Invokes the IOTC Client Event Processing loop.
iotc_state_t iotc_initialize()
Required before use of the IoTC Client library.
iotc_state_t iotc_shutdown()
Signals the IoTC Client library to cleanup any internal memory.
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)
Schedule a task for timed execution Using the provided context, this function adds a task to the int...
iotc_state_t iotc_get_heap_usage(size_t *const heap_usage)
Fetches the IoTC Client&#39;s current amount of heap usage This function is part of an optional configur...
const uint16_t iotc_revision
Contains the revsion number of the IoTC Client library.
uint8_t iotc_is_context_connected(iotc_context_handle_t context_handle)
Used to determine the state of a IoTC Client context&#39;s connection to the remote service.
long iotc_time_t
Definition: iotc_time.h:31
const uint16_t iotc_major
Contains the major version number of the IoTC Client library.
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)
const char iotc_cilent_version_str[]
String representation of the Major.Minor.Revision version of the IoTC Client library.
void iotc_set_network_timeout(uint32_t timeout)
Timeout value that&#39;s passed to the networking implementation This function configures how long a soc...
void iotc_events_process_blocking()
Invokes the IoTC Client Event Processing loop.
iotc_context_handle_t iotc_create_context()
Creates a connection context for subscriptions and publications This should by invoked following a s...
void() iotc_user_callback_t(iotc_context_handle_t in_context_handle, void *data, iotc_state_t state)
Definition: iotc_types.h:79
iotc_state_t
Definition: iotc_error.h:30
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)
Opens a MQTT connection to a custom service endpoint using the provided context, host and port...
void iotc_events_stop()
Causes the IoTC Client event loop to exit.
void() iotc_user_subscription_callback_t(iotc_context_handle_t in_context_handle, iotc_sub_call_type_t call_type, const iotc_sub_call_params_t *const params, iotc_state_t state, void *user_data)
Definition: iotc_types.h:154
enum iotc_mqtt_qos_e iotc_mqtt_qos_t
const uint16_t iotc_minor
Contains the minor version number of the IoTC Client library.
int32_t iotc_timed_task_handle_t
Definition: iotc_types.h:43
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)
Opens a connection to the Google Cloud IoT Core service using the provided context.
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 the Google Cloud IoT service on the given topic.
iotc_state_t iotc_delete_context(iotc_context_handle_t context_handle)
Frees the provided connection context This should by invoked to free up memory when your applicaiton...
iotc_state_t iotc_shutdown_connection(iotc_context_handle_t iotc_h)
Closes the connection associated with the provide context.
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 notifications if a message from the Google Cloud IoT Core service is posted to the give...
int32_t iotc_context_handle_t
Definition: iotc_types.h:37
uint32_t iotc_get_network_timeout(void)
Returns the timeout value for socket connections.
iotc_state_t iotc_set_maximum_heap_usage(const size_t max_bytes)
Sets Maximum Amount of Heap Allocated Memory the IoTC Client may use.
void iotc_cancel_timed_task(iotc_timed_task_handle_t timed_task_handle)
Cancel a timed task This function cancels the timed execution of the task specified by the given han...