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, Ispirata Srl, info@ispirata.com.
3  *
4  * SPDX-License-Identifier: LGPL-2.1+ OR Apache-2.0
5  */
6 
12 #ifndef _ASTARTE_DEVICE_H_
13 #define _ASTARTE_DEVICE_H_
14 
15 #include "astarte.h"
16 
17 #include <astarte_interface.h>
18 
19 #include <stdbool.h>
20 #include <stdint.h>
21 #include <stdlib.h>
22 
23 #define ASTARTE_INVALID_TIMESTAMP 0
24 
25 typedef struct astarte_device_t *astarte_device_handle_t;
26 
27 typedef struct
28 {
29  astarte_device_handle_t device;
30  const char *interface_name;
31  const char *path;
32  const void *bson_value;
33  int bson_value_type;
35 
36 typedef struct
37 {
38  astarte_device_handle_t device;
39  const char *interface_name;
40  const char *path;
42 
43 typedef void (*astarte_device_data_event_callback_t)(astarte_device_data_event_t *event);
44 
45 typedef struct
46 {
47  astarte_device_handle_t device;
48  int session_present;
50 
51 typedef void (*astarte_device_connection_event_callback_t)(
53 
54 typedef struct
55 {
56  astarte_device_handle_t device;
57  int session_present;
59 
60 typedef void (*astarte_device_disconnection_event_callback_t)(
62 
63 typedef void (*astarte_device_unset_event_callback_t)(astarte_device_unset_event_t *event);
64 
65 typedef struct
66 {
67  astarte_device_data_event_callback_t data_event_callback;
68  astarte_device_unset_event_callback_t unset_event_callback;
69  astarte_device_connection_event_callback_t connection_event_callback;
70  astarte_device_disconnection_event_callback_t disconnection_event_callback;
71  const char *hwid;
72  const char *credentials_secret;
73  const char *realm;
75 
76 #ifdef __cplusplus
77 extern "C" {
78 #endif
79 
112 astarte_device_handle_t astarte_device_init(astarte_device_config_t *cfg);
113 
120 void astarte_device_destroy(astarte_device_handle_t device);
121 
134  astarte_device_handle_t device, const astarte_interface_t *interface);
135 
143 astarte_err_t astarte_device_start(astarte_device_handle_t device);
144 
152 astarte_err_t astarte_device_stop(astarte_device_handle_t device);
153 
167 astarte_err_t astarte_device_stream_double(astarte_device_handle_t device,
168  const char *interface_name, const char *path, double value, int qos);
169 
187  const char *interface_name, const char *path, double value, uint64_t ts_epoch_millis, int qos);
188 
202 astarte_err_t astarte_device_stream_integer(astarte_device_handle_t device,
203  const char *interface_name, const char *path, int32_t value, int qos);
204 
222  const char *interface_name, const char *path, int32_t value, uint64_t ts_epoch_millis, int qos);
223 
237 astarte_err_t astarte_device_stream_longinteger(astarte_device_handle_t device,
238  const char *interface_name, const char *path, int64_t value, int qos);
239 
257  const char *interface_name, const char *path, int64_t value, uint64_t ts_epoch_millis, int qos);
258 
272 astarte_err_t astarte_device_stream_boolean(astarte_device_handle_t device,
273  const char *interface_name, const char *path, bool value, int qos);
274 
292  const char *interface_name, const char *path, bool value, uint64_t ts_epoch_millis, int qos);
293 
307 astarte_err_t astarte_device_stream_string(astarte_device_handle_t device,
308  const char *interface_name, const char *path, const char *value, int qos);
309 
327  const char *interface_name, const char *path, const char *value, uint64_t ts_epoch_millis,
328  int qos);
329 
344 astarte_err_t astarte_device_stream_binaryblob(astarte_device_handle_t device,
345  const char *interface_name, const char *path, void *value, size_t size, int qos);
346 
365  const char *interface_name, const char *path, void *value, size_t size,
366  uint64_t ts_epoch_millis, int qos);
367 
383 astarte_err_t astarte_device_stream_datetime(astarte_device_handle_t device,
384  const char *interface_name, const char *path, int64_t value, int qos);
385 
405  const char *interface_name, const char *path, int64_t value, uint64_t ts_epoch_millis, int qos);
406 
425  const char *interface_name, const char *path, const double *values, int count,
426  uint64_t ts_epoch_millis, int qos);
427 
442 static inline astarte_err_t astarte_device_stream_double_array(astarte_device_handle_t device,
443  const char *interface_name, const char *path, const double *values, int count,
444  uint64_t ts_epoch_millis, int qos)
445 {
447  device, interface_name, path, values, count, ASTARTE_INVALID_TIMESTAMP, qos);
448 }
449 
469  const char *interface_name, const char *path, const int32_t *values, int count,
470  uint64_t ts_epoch_millis, int qos);
471 
487 static inline astarte_err_t astarte_device_stream_integer_array(astarte_device_handle_t device,
488  const char *interface_name, const char *path, const int32_t *values, int count, int qos)
489 {
491  device, interface_name, path, values, count, ASTARTE_INVALID_TIMESTAMP, qos);
492 }
493 
513  const char *interface_name, const char *path, const int64_t *values, int count,
514  uint64_t ts_epoch_millis, int qos);
515 
531 static inline astarte_err_t astarte_device_stream_longinteger_array(astarte_device_handle_t device,
532  const char *interface_name, const char *path, const int64_t *values, int count, int qos)
533 {
535  device, interface_name, path, values, count, ASTARTE_INVALID_TIMESTAMP, qos);
536 }
537 
556  const char *interface_name, const char *path, const bool *values, int count,
557  uint64_t ts_epoch_millis, int qos);
558 
573 static inline astarte_err_t astarte_device_stream_boolean_array(astarte_device_handle_t device,
574  const char *interface_name, const char *path, const bool *values, int count, int qos)
575 {
577  device, interface_name, path, values, count, ASTARTE_INVALID_TIMESTAMP, qos);
578 }
579 
599  const char *interface_name, const char *path, const char *const *values, int count,
600  uint64_t ts_epoch_millis, int qos);
601 
619 static inline astarte_err_t astarte_device_stream_string_array(astarte_device_handle_t device,
620  const char *interface_name, const char *path, const char *const *values, int count, int qos)
621 {
623  device, interface_name, path, values, count, ASTARTE_INVALID_TIMESTAMP, qos);
624 }
625 
645  const char *interface_name, const char *path, const void *const *values, const int *sizes,
646  int count, uint64_t ts_epoch_millis, int qos);
647 
663 static inline astarte_err_t astarte_device_stream_binaryblob_array(astarte_device_handle_t device,
664  const char *interface_name, const char *path, const void *const *values, const int *sizes,
665  int count, int qos)
666 {
668  device, interface_name, path, values, sizes, count, ASTARTE_INVALID_TIMESTAMP, qos);
669 }
670 
691  const char *interface_name, const char *path, const int64_t *values, int count,
692  uint64_t ts_epoch_millis, int qos);
693 
710 static inline astarte_err_t astarte_device_stream_datetime_array(astarte_device_handle_t device,
711  const char *interface_name, const char *path, const int64_t *values, int count, int qos)
712 {
714  device, interface_name, path, values, count, ASTARTE_INVALID_TIMESTAMP, qos);
715 }
716 
741 astarte_err_t astarte_device_stream_aggregate(astarte_device_handle_t device,
742  const char *interface_name, const char *path_prefix, const void *bson_document, int qos);
743 
773  const char *interface_name, const char *path_prefix, const void *bson_document,
774  uint64_t ts_epoch_millis, int qos);
775 
789  astarte_device_handle_t device, const char *interface_name, const char *path, double value);
790 
804  astarte_device_handle_t device, const char *interface_name, const char *path, int32_t value);
805 
819  astarte_device_handle_t device, const char *interface_name, const char *path, int64_t value);
820 
834  astarte_device_handle_t device, const char *interface_name, const char *path, bool value);
835 
848 astarte_err_t astarte_device_set_string_property(astarte_device_handle_t device,
849  const char *interface_name, const char *path, const char *value);
850 
865  const char *interface_name, const char *path, void *value, size_t size);
866 
882  astarte_device_handle_t device, const char *interface_name, const char *path, int64_t value);
883 
897  astarte_device_handle_t device, const char *interface_name, const char *path);
898 
906 bool astarte_device_is_connected(astarte_device_handle_t device);
907 
916 char *astarte_device_get_encoded_id(astarte_device_handle_t device);
917 #ifdef __cplusplus
918 }
919 #endif
920 
921 #endif
Astarte types and defines.
astarte_err_t
Astarte return codes.
Definition: astarte.h:28
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:710
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:619
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:663
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:573
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:487
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:531
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:442
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_device.h:66
Definition: astarte_device.h:46
Definition: astarte_device.h:28
Definition: astarte_device.h:55
Definition: astarte_device.h:37
Astarte interface definition.
Definition: astarte_interface.h:40