Astarte Device SDK ESP32
ESP32 device SDK for the Astarte platform
astarte_device.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2018-2023, SECO Mind Srl
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later OR Apache-2.0
5  */
6 
12 #ifndef _ASTARTE_DEVICE_H_
13 #define _ASTARTE_DEVICE_H_
14 
15 #include "astarte.h"
16 
18 #include "astarte_interface.h"
19 
20 #include <stdbool.h>
21 #include <stdint.h>
22 #include <stdlib.h>
23 
24 #define ASTARTE_INVALID_TIMESTAMP 0
25 
26 typedef struct astarte_device *astarte_device_handle_t;
27 
28 typedef struct
29 {
30  astarte_device_handle_t device;
31  const char *interface_name;
32  const char *path;
33  const void *bson_value __attribute__((
34  deprecated("Please use bson_element with the functions from astarte_bson_deserializer.h")));
35  int bson_value_type __attribute__((
36  deprecated("Please use bson_element with the functions from astarte_bson_deserializer.h")));
37  astarte_bson_element_t bson_element;
39 
40 typedef struct
41 {
42  astarte_device_handle_t device;
43  const char *interface_name;
44  const char *path;
46 
47 typedef void (*astarte_device_data_event_callback_t)(astarte_device_data_event_t *event);
48 
49 typedef struct
50 {
51  astarte_device_handle_t device;
52  int session_present;
54 
55 typedef void (*astarte_device_connection_event_callback_t)(
57 
58 typedef struct
59 {
60  astarte_device_handle_t device;
61  int session_present;
63 
64 typedef void (*astarte_device_disconnection_event_callback_t)(
66 
67 typedef void (*astarte_device_unset_event_callback_t)(astarte_device_unset_event_t *event);
68 
69 typedef struct
70 {
71  astarte_device_data_event_callback_t data_event_callback;
72  astarte_device_unset_event_callback_t unset_event_callback;
73  astarte_device_connection_event_callback_t connection_event_callback;
74  astarte_device_disconnection_event_callback_t disconnection_event_callback;
75  const char *hwid;
76  const char *credentials_secret;
77  const char *realm;
79 
80 #ifdef __cplusplus
81 extern "C" {
82 #endif
83 
116 astarte_device_handle_t astarte_device_init(astarte_device_config_t *cfg);
117 
124 void astarte_device_destroy(astarte_device_handle_t device);
125 
138  astarte_device_handle_t device, const astarte_interface_t *interface);
139 
147 astarte_err_t astarte_device_start(astarte_device_handle_t device);
148 
156 astarte_err_t astarte_device_stop(astarte_device_handle_t device);
157 
171 astarte_err_t astarte_device_stream_double(astarte_device_handle_t device,
172  const char *interface_name, const char *path, double value, int qos);
173 
191  const char *interface_name, const char *path, double value, uint64_t ts_epoch_millis, int qos);
192 
206 astarte_err_t astarte_device_stream_integer(astarte_device_handle_t device,
207  const char *interface_name, const char *path, int32_t value, int qos);
208 
226  const char *interface_name, const char *path, int32_t value, uint64_t ts_epoch_millis, int qos);
227 
241 astarte_err_t astarte_device_stream_longinteger(astarte_device_handle_t device,
242  const char *interface_name, const char *path, int64_t value, int qos);
243 
261  const char *interface_name, const char *path, int64_t value, uint64_t ts_epoch_millis, int qos);
262 
276 astarte_err_t astarte_device_stream_boolean(astarte_device_handle_t device,
277  const char *interface_name, const char *path, bool value, int qos);
278 
296  const char *interface_name, const char *path, bool value, uint64_t ts_epoch_millis, int qos);
297 
311 astarte_err_t astarte_device_stream_string(astarte_device_handle_t device,
312  const char *interface_name, const char *path, const char *value, int qos);
313 
331  const char *interface_name, const char *path, const char *value, uint64_t ts_epoch_millis,
332  int qos);
333 
348 astarte_err_t astarte_device_stream_binaryblob(astarte_device_handle_t device,
349  const char *interface_name, const char *path, void *value, size_t size, int qos);
350 
369  const char *interface_name, const char *path, void *value, size_t size,
370  uint64_t ts_epoch_millis, int qos);
371 
387 astarte_err_t astarte_device_stream_datetime(astarte_device_handle_t device,
388  const char *interface_name, const char *path, int64_t value, int qos);
389 
409  const char *interface_name, const char *path, int64_t value, uint64_t ts_epoch_millis, int qos);
410 
429  const char *interface_name, const char *path, const double *values, int count,
430  uint64_t ts_epoch_millis, int qos);
431 
446 static inline astarte_err_t astarte_device_stream_double_array(astarte_device_handle_t device,
447  const char *interface_name, const char *path, const double *values, int count,
448  uint64_t ts_epoch_millis, int qos)
449 {
451  device, interface_name, path, values, count, ASTARTE_INVALID_TIMESTAMP, qos);
452 }
453 
473  const char *interface_name, const char *path, const int32_t *values, int count,
474  uint64_t ts_epoch_millis, int qos);
475 
491 static inline astarte_err_t astarte_device_stream_integer_array(astarte_device_handle_t device,
492  const char *interface_name, const char *path, const int32_t *values, int count, int qos)
493 {
495  device, interface_name, path, values, count, ASTARTE_INVALID_TIMESTAMP, qos);
496 }
497 
517  const char *interface_name, const char *path, const int64_t *values, int count,
518  uint64_t ts_epoch_millis, int qos);
519 
535 static inline astarte_err_t astarte_device_stream_longinteger_array(astarte_device_handle_t device,
536  const char *interface_name, const char *path, const int64_t *values, int count, int qos)
537 {
539  device, interface_name, path, values, count, ASTARTE_INVALID_TIMESTAMP, qos);
540 }
541 
560  const char *interface_name, const char *path, const bool *values, int count,
561  uint64_t ts_epoch_millis, int qos);
562 
577 static inline astarte_err_t astarte_device_stream_boolean_array(astarte_device_handle_t device,
578  const char *interface_name, const char *path, const bool *values, int count, int qos)
579 {
581  device, interface_name, path, values, count, ASTARTE_INVALID_TIMESTAMP, qos);
582 }
583 
603  const char *interface_name, const char *path, const char *const *values, int count,
604  uint64_t ts_epoch_millis, int qos);
605 
623 static inline astarte_err_t astarte_device_stream_string_array(astarte_device_handle_t device,
624  const char *interface_name, const char *path, const char *const *values, int count, int qos)
625 {
627  device, interface_name, path, values, count, ASTARTE_INVALID_TIMESTAMP, qos);
628 }
629 
649  const char *interface_name, const char *path, const void *const *values, const int *sizes,
650  int count, uint64_t ts_epoch_millis, int qos);
651 
667 static inline astarte_err_t astarte_device_stream_binaryblob_array(astarte_device_handle_t device,
668  const char *interface_name, const char *path, const void *const *values, const int *sizes,
669  int count, int qos)
670 {
672  device, interface_name, path, values, sizes, count, ASTARTE_INVALID_TIMESTAMP, qos);
673 }
674 
695  const char *interface_name, const char *path, const int64_t *values, int count,
696  uint64_t ts_epoch_millis, int qos);
697 
714 static inline astarte_err_t astarte_device_stream_datetime_array(astarte_device_handle_t device,
715  const char *interface_name, const char *path, const int64_t *values, int count, int qos)
716 {
718  device, interface_name, path, values, count, ASTARTE_INVALID_TIMESTAMP, qos);
719 }
720 
748 astarte_err_t astarte_device_stream_aggregate(astarte_device_handle_t device,
749  const char *interface_name, const char *path_prefix, const void *bson_document, int qos);
750 
783  const char *interface_name, const char *path_prefix, const void *bson_document,
784  uint64_t ts_epoch_millis, int qos);
785 
799  astarte_device_handle_t device, const char *interface_name, const char *path, double value);
800 
814  astarte_device_handle_t device, const char *interface_name, const char *path, int32_t value);
815 
829  astarte_device_handle_t device, const char *interface_name, const char *path, int64_t value);
830 
844  astarte_device_handle_t device, const char *interface_name, const char *path, bool value);
845 
858 astarte_err_t astarte_device_set_string_property(astarte_device_handle_t device,
859  const char *interface_name, const char *path, const char *value);
860 
875  const char *interface_name, const char *path, void *value, size_t size);
876 
892  astarte_device_handle_t device, const char *interface_name, const char *path, int64_t value);
893 
907  astarte_device_handle_t device, const char *interface_name, const char *path);
908 
916 bool astarte_device_is_connected(astarte_device_handle_t device);
917 
926 char *astarte_device_get_encoded_id(astarte_device_handle_t device);
927 #ifdef __cplusplus
928 }
929 #endif
930 
931 #endif
Astarte types and defines.
astarte_err_t
Astarte return codes.
Definition: astarte.h:28
Astarte BSON deserialization functions.
astarte_err_t astarte_device_stream_double_with_timestamp(astarte_device_handle_t device, const char *interface_name, const char *path, double value, uint64_t ts_epoch_millis, int qos)
send a double value on a datastream endpoint with an explicit timestamp.
astarte_err_t astarte_device_set_datetime_property(astarte_device_handle_t device, const char *interface_name, const char *path, int64_t value)
send a datetime value on a properties endpoint.
astarte_err_t astarte_device_stream_longinteger_with_timestamp(astarte_device_handle_t device, const char *interface_name, const char *path, int64_t value, uint64_t ts_epoch_millis, int qos)
send a 64 bit integer value on a datastream endpoint with an explicit timestamp.
astarte_err_t astarte_device_stream_double_array_with_timestamp(astarte_device_handle_t device, const char *interface_name, const char *path, const double *values, int count, uint64_t ts_epoch_millis, int qos)
send a double array value on a datastream endpoint with an explicit timestamp.
astarte_err_t astarte_device_stream_double(astarte_device_handle_t device, const char *interface_name, const char *path, double value, int qos)
send a double value on a datastream endpoint.
astarte_err_t astarte_device_set_boolean_property(astarte_device_handle_t device, const char *interface_name, const char *path, bool value)
send a boolean value on a properties endpoint.
static astarte_err_t astarte_device_stream_datetime_array(astarte_device_handle_t device, const char *interface_name, const char *path, const int64_t *values, int count, int qos)
send a datetime value on a datastream endpoint.
Definition: astarte_device.h:714
astarte_err_t astarte_device_stop(astarte_device_handle_t device)
stop Astarte device.
astarte_err_t astarte_device_stream_string_with_timestamp(astarte_device_handle_t device, const char *interface_name, const char *path, const char *value, uint64_t ts_epoch_millis, int qos)
send a UTF8 encoded string on a datastream endpoint with an explicit timestamp.
astarte_err_t astarte_device_add_interface(astarte_device_handle_t device, const astarte_interface_t *interface)
add an interface to the device.
bool astarte_device_is_connected(astarte_device_handle_t device)
check if the device is connected.
astarte_err_t astarte_device_stream_integer_with_timestamp(astarte_device_handle_t device, const char *interface_name, const char *path, int32_t value, uint64_t ts_epoch_millis, int qos)
send a 32 bit integer value on a datastream endpoint with an explicit timestamp.
astarte_err_t astarte_device_stream_datetime(astarte_device_handle_t device, const char *interface_name, const char *path, int64_t value, int qos)
send a datetime value on a datastream endpoint.
astarte_err_t astarte_device_start(astarte_device_handle_t device)
start Astarte device.
astarte_err_t astarte_device_stream_datetime_array_with_timestamp(astarte_device_handle_t device, const char *interface_name, const char *path, const int64_t *values, int count, uint64_t ts_epoch_millis, int qos)
send a datetime value on a datastream endpoint with an explicit timestamp.
astarte_err_t astarte_device_set_longinteger_property(astarte_device_handle_t device, const char *interface_name, const char *path, int64_t value)
send a 64 bit integer value on a properties endpoint.
static astarte_err_t astarte_device_stream_string_array(astarte_device_handle_t device, const char *interface_name, const char *path, const char *const *values, int count, int qos)
send a string array value on a datastream endpoint.
Definition: astarte_device.h:623
static astarte_err_t astarte_device_stream_binaryblob_array(astarte_device_handle_t device, const char *interface_name, const char *path, const void *const *values, const int *sizes, int count, int qos)
send a binary blob array value on a datastream endpoint with an explicit timestamp.
Definition: astarte_device.h:667
astarte_device_handle_t astarte_device_init(astarte_device_config_t *cfg)
initialize Astarte device.
void astarte_device_destroy(astarte_device_handle_t device)
destroy Astarte device.
astarte_err_t astarte_device_set_double_property(astarte_device_handle_t device, const char *interface_name, const char *path, double value)
send a double value on a properties endpoint.
astarte_err_t astarte_device_set_binaryblob_property(astarte_device_handle_t device, const char *interface_name, const char *path, void *value, size_t size)
send a binary value on a properties endpoint.
astarte_err_t astarte_device_stream_datetime_with_timestamp(astarte_device_handle_t device, const char *interface_name, const char *path, int64_t value, uint64_t ts_epoch_millis, int qos)
send a datetime value on a datastream endpoint with an explicit timestamp.
astarte_err_t astarte_device_stream_binaryblob_array_with_timestamp(astarte_device_handle_t device, const char *interface_name, const char *path, const void *const *values, const int *sizes, int count, uint64_t ts_epoch_millis, int qos)
send a binary blob array value on a datastream endpoint with an explicit timestamp.
astarte_err_t astarte_device_unset_path(astarte_device_handle_t device, const char *interface_name, const char *path)
unset a path belonging to a properties interface.
astarte_err_t astarte_device_stream_integer(astarte_device_handle_t device, const char *interface_name, const char *path, int32_t value, int qos)
send a 32 bit integer value on a datastream endpoint.
astarte_err_t astarte_device_stream_boolean_array_with_timestamp(astarte_device_handle_t device, const char *interface_name, const char *path, const bool *values, int count, uint64_t ts_epoch_millis, int qos)
send a boolean array value on a datastream endpoint with an explicit timestamp.
astarte_err_t astarte_device_stream_string(astarte_device_handle_t device, const char *interface_name, const char *path, const char *value, int qos)
send a UTF8 encoded string on a datastream endpoint.
astarte_err_t astarte_device_stream_binaryblob_with_timestamp(astarte_device_handle_t device, const char *interface_name, const char *path, void *value, size_t size, uint64_t ts_epoch_millis, int qos)
send a binary value on a datastream endpoint with an explicit timestamp.
astarte_err_t astarte_device_stream_string_array_with_timestamp(astarte_device_handle_t device, const char *interface_name, const char *path, const char *const *values, int count, uint64_t ts_epoch_millis, int qos)
send a string array value on a datastream endpoint with an explicit timestamp.
astarte_err_t astarte_device_stream_integer_array_with_timestamp(astarte_device_handle_t device, const char *interface_name, const char *path, const int32_t *values, int count, uint64_t ts_epoch_millis, int qos)
send a 32 bit integer array value on a datastream endpoint with an explicit timestamp.
astarte_err_t astarte_device_stream_longinteger_array_with_timestamp(astarte_device_handle_t device, const char *interface_name, const char *path, const int64_t *values, int count, uint64_t ts_epoch_millis, int qos)
send a 64 bit integer array value on a datastream endpoint with an explicit timestamp.
static astarte_err_t astarte_device_stream_boolean_array(astarte_device_handle_t device, const char *interface_name, const char *path, const bool *values, int count, int qos)
send a boolean array value on a datastream endpoint.
Definition: astarte_device.h:577
astarte_err_t astarte_device_stream_boolean_with_timestamp(astarte_device_handle_t device, const char *interface_name, const char *path, bool value, uint64_t ts_epoch_millis, int qos)
send a boolean value on a datastream endpoint with an explicit timestamp.
astarte_err_t astarte_device_stream_longinteger(astarte_device_handle_t device, const char *interface_name, const char *path, int64_t value, int qos)
send a 64 bit integer value on a datastream endpoint.
astarte_err_t astarte_device_stream_aggregate(astarte_device_handle_t device, const char *interface_name, const char *path_prefix, const void *bson_document, int qos)
send an aggregate value on a datastream endpoint of an interface with object aggregation.
astarte_err_t astarte_device_set_string_property(astarte_device_handle_t device, const char *interface_name, const char *path, const char *value)
send a UTF8 encoded string on a properties endpoint.
static astarte_err_t astarte_device_stream_integer_array(astarte_device_handle_t device, const char *interface_name, const char *path, const int32_t *values, int count, int qos)
send a 32 bit integer array value on a datastream endpoint.
Definition: astarte_device.h:491
astarte_err_t astarte_device_stream_binaryblob(astarte_device_handle_t device, const char *interface_name, const char *path, void *value, size_t size, int qos)
send a binary value on a datastream endpoint.
astarte_err_t astarte_device_set_integer_property(astarte_device_handle_t device, const char *interface_name, const char *path, int32_t value)
send a 32 bit integer value on a properties endpoint.
static astarte_err_t astarte_device_stream_longinteger_array(astarte_device_handle_t device, const char *interface_name, const char *path, const int64_t *values, int count, int qos)
send a 64 bit integer array value on a datastream endpoint.
Definition: astarte_device.h:535
astarte_err_t astarte_device_stream_aggregate_with_timestamp(astarte_device_handle_t device, const char *interface_name, const char *path_prefix, const void *bson_document, uint64_t ts_epoch_millis, int qos)
send an aggregate value on a datastream endpoint of an interface with object aggregation with an expl...
static astarte_err_t astarte_device_stream_double_array(astarte_device_handle_t device, const char *interface_name, const char *path, const double *values, int count, uint64_t ts_epoch_millis, int qos)
send a double array value on a datastream endpoint.
Definition: astarte_device.h:446
char * astarte_device_get_encoded_id(astarte_device_handle_t device)
Get the encoded hardware ID of the device.
astarte_err_t astarte_device_stream_boolean(astarte_device_handle_t device, const char *interface_name, const char *path, bool value, int qos)
send a boolean value on a datastream endpoint.
Astarte interface functions.
Definition: astarte_bson_deserializer.h:36
Definition: astarte_device.h:70
Definition: astarte_device.h:50
Definition: astarte_device.h:29
Definition: astarte_device.h:59
Definition: astarte_device.h:41
Astarte interface definition.
Definition: astarte_interface.h:40