Astarte Device SDK ESP32
ESP32 device SDK for the Astarte platform
Loading...
Searching...
No Matches
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
26typedef struct astarte_device *astarte_device_handle_t;
27
28typedef 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;
38 void *user_data;
40
41typedef struct
42{
43 astarte_device_handle_t device;
44 const char *interface_name;
45 const char *path;
46 void *user_data;
48
49typedef void (*astarte_device_data_event_callback_t)(astarte_device_data_event_t *event);
50
51typedef struct
52{
53 astarte_device_handle_t device;
54 int session_present;
55 void *user_data;
57
58typedef void (*astarte_device_connection_event_callback_t)(
60
61typedef struct
62{
63 astarte_device_handle_t device;
64 int session_present;
65 void *user_data;
67
68typedef void (*astarte_device_disconnection_event_callback_t)(
70
71typedef void (*astarte_device_unset_event_callback_t)(astarte_device_unset_event_t *event);
72
73typedef struct
74{
75 astarte_device_data_event_callback_t data_event_callback;
76 astarte_device_unset_event_callback_t unset_event_callback;
77 astarte_device_connection_event_callback_t connection_event_callback;
78 astarte_device_disconnection_event_callback_t disconnection_event_callback;
79 void *callbacks_user_data;
80 const char *hwid;
81 const char *credentials_secret;
82 const char *realm;
84
85#ifdef __cplusplus
86extern "C" {
87#endif
88
121astarte_device_handle_t astarte_device_init(astarte_device_config_t *cfg);
122
129void astarte_device_destroy(astarte_device_handle_t device);
130
143 astarte_device_handle_t device, const astarte_interface_t *interface);
144
152astarte_err_t astarte_device_start(astarte_device_handle_t device);
153
161astarte_err_t astarte_device_stop(astarte_device_handle_t device);
162
176astarte_err_t astarte_device_stream_double(astarte_device_handle_t device,
177 const char *interface_name, const char *path, double value, int qos);
178
196 const char *interface_name, const char *path, double value, uint64_t ts_epoch_millis, int qos);
197
211astarte_err_t astarte_device_stream_integer(astarte_device_handle_t device,
212 const char *interface_name, const char *path, int32_t value, int qos);
213
231 const char *interface_name, const char *path, int32_t value, uint64_t ts_epoch_millis, int qos);
232
247 const char *interface_name, const char *path, int64_t value, int qos);
248
266 const char *interface_name, const char *path, int64_t value, uint64_t ts_epoch_millis, int qos);
267
281astarte_err_t astarte_device_stream_boolean(astarte_device_handle_t device,
282 const char *interface_name, const char *path, bool value, int qos);
283
301 const char *interface_name, const char *path, bool value, uint64_t ts_epoch_millis, int qos);
302
316astarte_err_t astarte_device_stream_string(astarte_device_handle_t device,
317 const char *interface_name, const char *path, const char *value, int qos);
318
336 const char *interface_name, const char *path, const char *value, uint64_t ts_epoch_millis,
337 int qos);
338
353astarte_err_t astarte_device_stream_binaryblob(astarte_device_handle_t device,
354 const char *interface_name, const char *path, void *value, size_t size, int qos);
355
374 const char *interface_name, const char *path, void *value, size_t size,
375 uint64_t ts_epoch_millis, int qos);
376
392astarte_err_t astarte_device_stream_datetime(astarte_device_handle_t device,
393 const char *interface_name, const char *path, int64_t value, int qos);
394
414 const char *interface_name, const char *path, int64_t value, uint64_t ts_epoch_millis, int qos);
415
434 const char *interface_name, const char *path, const double *values, int count,
435 uint64_t ts_epoch_millis, int qos);
436
451static inline astarte_err_t astarte_device_stream_double_array(astarte_device_handle_t device,
452 const char *interface_name, const char *path, const double *values, int count,
453 uint64_t ts_epoch_millis, int qos)
454{
456 device, interface_name, path, values, count, ASTARTE_INVALID_TIMESTAMP, qos);
457}
458
478 const char *interface_name, const char *path, const int32_t *values, int count,
479 uint64_t ts_epoch_millis, int qos);
480
496static inline astarte_err_t astarte_device_stream_integer_array(astarte_device_handle_t device,
497 const char *interface_name, const char *path, const int32_t *values, int count, int qos)
498{
500 device, interface_name, path, values, count, ASTARTE_INVALID_TIMESTAMP, qos);
501}
502
522 const char *interface_name, const char *path, const int64_t *values, int count,
523 uint64_t ts_epoch_millis, int qos);
524
540static inline astarte_err_t astarte_device_stream_longinteger_array(astarte_device_handle_t device,
541 const char *interface_name, const char *path, const int64_t *values, int count, int qos)
542{
544 device, interface_name, path, values, count, ASTARTE_INVALID_TIMESTAMP, qos);
545}
546
565 const char *interface_name, const char *path, const bool *values, int count,
566 uint64_t ts_epoch_millis, int qos);
567
582static inline astarte_err_t astarte_device_stream_boolean_array(astarte_device_handle_t device,
583 const char *interface_name, const char *path, const bool *values, int count, int qos)
584{
586 device, interface_name, path, values, count, ASTARTE_INVALID_TIMESTAMP, qos);
587}
588
608 const char *interface_name, const char *path, const char *const *values, int count,
609 uint64_t ts_epoch_millis, int qos);
610
628static inline astarte_err_t astarte_device_stream_string_array(astarte_device_handle_t device,
629 const char *interface_name, const char *path, const char *const *values, int count, int qos)
630{
632 device, interface_name, path, values, count, ASTARTE_INVALID_TIMESTAMP, qos);
633}
634
654 const char *interface_name, const char *path, const void *const *values, const int *sizes,
655 int count, uint64_t ts_epoch_millis, int qos);
656
672static inline astarte_err_t astarte_device_stream_binaryblob_array(astarte_device_handle_t device,
673 const char *interface_name, const char *path, const void *const *values, const int *sizes,
674 int count, int qos)
675{
677 device, interface_name, path, values, sizes, count, ASTARTE_INVALID_TIMESTAMP, qos);
678}
679
700 const char *interface_name, const char *path, const int64_t *values, int count,
701 uint64_t ts_epoch_millis, int qos);
702
719static inline astarte_err_t astarte_device_stream_datetime_array(astarte_device_handle_t device,
720 const char *interface_name, const char *path, const int64_t *values, int count, int qos)
721{
723 device, interface_name, path, values, count, ASTARTE_INVALID_TIMESTAMP, qos);
724}
725
753astarte_err_t astarte_device_stream_aggregate(astarte_device_handle_t device,
754 const char *interface_name, const char *path_prefix, const void *bson_document, int qos);
755
788 const char *interface_name, const char *path_prefix, const void *bson_document,
789 uint64_t ts_epoch_millis, int qos);
790
804 astarte_device_handle_t device, const char *interface_name, const char *path, double value);
805
819 astarte_device_handle_t device, const char *interface_name, const char *path, int32_t value);
820
834 astarte_device_handle_t device, const char *interface_name, const char *path, int64_t value);
835
849 astarte_device_handle_t device, const char *interface_name, const char *path, bool value);
850
864 const char *interface_name, const char *path, const char *value);
865
880 const char *interface_name, const char *path, void *value, size_t size);
881
897 astarte_device_handle_t device, const char *interface_name, const char *path, int64_t value);
898
912 astarte_device_handle_t device, const char *interface_name, const char *path);
913
921bool astarte_device_is_connected(astarte_device_handle_t device);
922
931char *astarte_device_get_encoded_id(astarte_device_handle_t device);
932#ifdef __cplusplus
933}
934#endif
935
936#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:719
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:628
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:672
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.
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_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:582
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:496
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:540
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:451
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:74
Definition astarte_device.h:52
Definition astarte_device.h:29
Definition astarte_device.h:62
Definition astarte_device.h:42
Astarte interface definition.
Definition astarte_interface.h:40