ThingsBoard Client SDK 0.16.0
Client SDK to connect with ThingsBoard IoT Platform from IoT devices (Arduino, Espressif, etc.)
Loading...
Searching...
No Matches
Configuration.h
Go to the documentation of this file.
1#ifndef Configuration_h
2#define Configuration_h
3
4// Include sdkconfig file it it exists to allow overwriting of some defines with the configuration entered in the Espressif IDF menuconfig.
5// Only available when compiling for Espressif IDF, but allows to more easily change some configurations with a GUI instead of code.
6# ifdef __has_include
7# if __has_include(<sdkconfig.h>)
8# include <sdkconfig.h>
9# endif
10# endif
11
12// Include the internal version of the ESP IDF contained in the esp_idf_version file, if it exists, to allow checking for supported ESP IDF version.
13# ifdef __has_include
14# if __has_include(<esp_idf_version.h>)
15# include <esp_idf_version.h>
16# endif
17# endif
18
19// Enabled the usage of int64_t and double values with ArduinoJson. Making the JsonVariant store double and int64_t instead of float and int32_t.
20// See https://arduinojson.org/v6/api/config/use_long_long/ for more information. Use double is now enabled by default since ArduinoJson 6.19.4
21// and use long long as well, if the board is 32 bits. However because this library supports non 32-bit boards we still have to override the defines to ensure
22// both settings are actually enabled. See https://arduinojson.org/news/2022/01/08/arduinojson-6-19-0/#default-configuration for more information.
23#define ARDUINOJSON_USE_LONG_LONG 1
24#define ARDUINOJSON_USE_DOUBLE 1
25
26// Enable the usage of the C++ STL library, depending on if needed STL base functionality is supported.
27// This allows to use the C++ STL functionality in multiple places, where otherwise less efficient custom fallback implementation would be required:
28// - std::vector instead of custom Container class
29// - std::string instead of Arduino String class
30// - std::function instead of custom Functor class
31# ifndef THINGSBOARD_ENABLE_STL
32# ifdef __has_include
33# if __has_include(<string>) && __has_include(<functional>) && __has_include(<vector>) && __has_include(<iterator>)
34# define THINGSBOARD_ENABLE_STL 1
35# else
36# define THINGSBOARD_ENABLE_STL 0
37# endif
38# else
39# ifdef ARDUINO
40# define THINGSBOARD_ENABLE_STL 0
41# else
42# define THINGSBOARD_ENABLE_STL 1
43# endif
44# endif
45# endif
46
47// Use advanced STL features if they are supported by the compiler (std::ranges::view, compile time if expressions, ...).
48// Currently only the case for ESP IDF when using a major version following 5 and when using Arduino following major version 3.
49// Allows to improve performance, because to filter arrays or vectors we do not have to make copies of them anymore.
50# ifndef THINGSBOARD_ENABLE_CXX20
51# if THINGSBOARD_ENABLE_STL && __cplusplus >= 202002L
52# define THINGSBOARD_ENABLE_CXX20 1
53# else
54# define THINGSBOARD_ENABLE_CXX20 0
55# endif
56# endif
57
58// Use the esp_timer header internally for handling timeouts and callbacks, as long as the header exists, because it is more efficient than the Arduino Ticker implementation.
59// That is because we can stop the timer without having to delete it, removing the need to create a new timer to restart it, instead it can simply be stopped and started again.
60// Only exists following major version 3 minor version 0 on ESP32 (https://github.com/espressif/esp-idf/releases/tag/v3.0-rc1)and major version 3 minor version 1 on ESP8266 (https://github.com/espressif/ESP8266_RTOS_SDK/releases/tag/v3.1-rc1)
61# ifndef THINGSBOARD_USE_ESP_TIMER
62# ifdef __has_include
63# if __has_include(<esp_timer.h>)
64# define THINGSBOARD_USE_ESP_TIMER 1
65# else
66# define THINGSBOARD_USE_ESP_TIMER 0
67# endif
68# else
69# define THINGSBOARD_USE_ESP_TIMER 0
70# endif
71# endif
72
73// Use the mqtt_client header internally for handling the sending and receiving of MQTT data, as long as the header exists,
74// to allow users that do have the needed component to use the Espressif_MQTT_Client instead of only the Arduino_MQTT_Client.
75// Only exists following major version 3 minor version 2 on ESP32 (https://github.com/espressif/esp-idf/releases/tag/v3.2) and major version 3 minor version 4 on ESP8266 (https://github.com/espressif/ESP8266_RTOS_SDK/releases/tag/v3.4).
76# ifndef THINGSBOARD_USE_ESP_MQTT
77# ifdef __has_include
78# if __has_include(<mqtt_client.h>)
79# define THINGSBOARD_USE_ESP_MQTT 1
80# else
81# define THINGSBOARD_USE_ESP_MQTT 0
82# endif
83# else
84# define THINGSBOARD_USE_ESP_MQTT 0
85# endif
86# endif
87
88// Use the mbed_tls header internally for handling the creation of hashes from binary data, as long as the header exists,
89// because if it is already included we do not need to rely on and incude external lbiraries like Seeed_mbedtls.h, which implements the same features.
90// Only exists following major version 0 minor version 9 on ESP32 (https://github.com/espressif/esp-idf/releases/v0.9) and major version 3 minor version 3 on ESP8266 (https://github.com/espressif/ESP8266_RTOS_SDK/releases/tag/v3.3-rc1).
91# ifndef THINGSBOARD_USE_MBED_TLS
92# ifdef __has_include
93# if __has_include(<mbedtls/md.h>)
94# define THINGSBOARD_USE_MBED_TLS 1
95# else
96# define THINGSBOARD_USE_MBED_TLS 0
97# endif
98# else
99# define THINGSBOARD_USE_MBED_TLS 0
100# endif
101# endif
102
103// Use the esp_ota_ops header internally for handling the writing of ota update data, as long as the header exists,
104// to allow users that do have the needed component to use the Espressif_Updater instead of only the Arduino_ESP32_Updater.
105// Only exists following major version 1 minor version 0 on ESP32 (https://github.com/espressif/esp-idf/releases/v0.9) and major version 3 minor version 0 on ESP8266 (https://github.com/espressif/ESP8266_RTOS_SDK/releases/tag/v3.0-rc1).
106// Additionally, for all the expected API calls to be implemented atleast major version 2 minor version 1 on ESP32 and major version 3 minor version 0 on ESP8266 is required.
107# ifndef THINGSBOARD_USE_ESP_PARTITION
108# ifdef __has_include
109# if __has_include(<esp_ota_ops.h>) && (!defined(ESP32) || ((ESP_IDF_VERSION_MAJOR == 2 && ESP_IDF_VERSION_MINOR >= 1) || ESP_IDF_VERSION_MAJOR > 2)) && (!defined(ESP8266) || ESP_IDF_VERSION_MAJOR >= 3)
110# define THINGSBOARD_USE_ESP_PARTITION 1
111# else
112# define THINGSBOARD_USE_ESP_PARTITION 0
113# endif
114# else
115# define THINGSBOARD_USE_ESP_PARTITION 0
116# endif
117# endif
118
119// Enables the ThingsBoard class to be fully dynamic instead of requiring template arguments to statically allocate memory.
120// If enabled the program might be slightly slower and all the memory will be placed onto the heap instead of the stack.
121// See https://arduinojson.org/v6/api/dynamicjsondocument/ for the main difference in the underlying code.
122// Can also optionally be configured via the ESP-IDF menuconfig, if that is the done the value is set to the value entered in the menuconfig,
123// if the value is manually overriden tough with a #define before including ThingsBoard then the hardcoded value takes precendence.
124# ifndef THINGSBOARD_ENABLE_DYNAMIC
125# define THINGSBOARD_ENABLE_DYNAMIC CONFIG_THINGSBOARD_ENABLE_DYNAMIC
126# endif
127
128// Enables the ThingsBoard class to print all received and sent messages and their topic, from and to the server,
129// additionally some more debug messages will be printed. Requires more flash memory, and more calls to the logger implementation requiring more performance.
130// Recommended to disable when building for release, should only be enabled to debug where a issue might stem from.
131// Can also optionally be configured via the ESP-IDF menuconfig, if that is the done the value is set to the value entered in the menuconfig,
132// if the value is manually overriden tough with a #define before including ThingsBoard then the hardcoded value takes precendence.
133# ifndef THINGSBOARD_ENABLE_DEBUG
134# define THINGSBOARD_ENABLE_DEBUG CONFIG_THINGSBOARD_ENABLE_DEBUG
135# endif
136
137// Use the StreamUtils header internally for enabling the usage of an additonal library as a fallback, as long as the header exists,
138// to allow to directly serialize a json message that is sent to the cloud, if the size of that message would be bigger than the internal buffer size of the client.
139// Allows sending much bigger messages than would otherwise be possible, and without the need to increase stack or heap requirements, but at the cost of increased send times.
140// See https://arduinojson.org/v6/how-to/use-arduinojson-with-pubsubclient/#serializing-a-json-document-into-an-mqtt-message for the main difference in the underlying code.
141// Option can only be enabled when using Arduino, because this feature relies on Arduino as it improves the underlying data streams to directly write the data into the MQTT Client,
142// but writing each byte one by one, would be too slow, therefore the ArduinoStreamUtils (https://github.com/bblanchon/ArduinoStreamUtils) library is used to buffer those calls into bigger packets.
143// This allows sending data that is very big without requiring to allocate that much memory, because it is sent in smaller packets.
144// To support this feature, however the IMQTT_Client interface implementation, needs to additionally override the Print interface, because that is required by the wrapper class BufferingPrint.
145# ifndef THINGSBOARD_ENABLE_STREAM_UTILS
146# ifdef __has_include
147# if __has_include(<StreamUtils.h>)
148# define THINGSBOARD_ENABLE_STREAM_UTILS 1
149# else
150# define THINGSBOARD_ENABLE_STREAM_UTILS 0
151# endif
152# else
153# define THINGSBOARD_ENABLE_STREAM_UTILS 0
154# endif
155# endif
156
157// Enables the ThingsBoard class to save the allocated memory of the DynamicJsonDocument into psram instead of onto the sram.
158// Enabled by default if THINGSBOARD_ENABLE_DYNAMIC has been set and the esp_heap_caps header exists, because it requries DynamicJsonDocument to work.
159// If enabled the program might be slightly slower, but all the memory will be placed onto psram instead of sram, meaning the sram can be allocated for other things.
160// See https://arduinojson.org/v6/how-to/use-external-ram-on-esp32/ and https://arduinojson.org/v6/api/basicjsondocument/ for the main difference in the underlying code.
161# ifndef THINGSBOARD_ENABLE_PSRAM
162# ifdef __has_include
163# if THINGSBOARD_ENABLE_DYNAMIC && __has_include(<esp_heap_caps.h>)
164# define THINGSBOARD_ENABLE_PSRAM 1
165# else
166# define THINGSBOARD_ENABLE_PSRAM 0
167# endif
168# else
169# define THINGSBOARD_ENABLE_PSRAM 0
170# endif
171# endif
172
173#endif // Configuration_h