Skip to content

Commit

Permalink
Overhaul API
Browse files Browse the repository at this point in the history
  • Loading branch information
MathewHDYT committed Sep 18, 2024
1 parent fa22023 commit 12dd9ba
Show file tree
Hide file tree
Showing 95 changed files with 5,523 additions and 4,710 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/arduino-compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ jobs:
- source-path: ./
- name: TBPubSubClient
- name: ArduinoHttpClient
- { name: ArduinoJson, version: 6.21.4 }
- { name: ArduinoJson, version: 6.21.5 }
- name: StreamUtils
- name: WiFiEsp
- name: TinyGSM
- name: Seeed_Arduino_mbedtls
- name: arduino-timer
strategy:
matrix:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/esp32-compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ jobs:
- source-path: ./
- name: TBPubSubClient
- name: ArduinoHttpClient
- { name: ArduinoJson, version: 6.21.4 }
- name: StreamUtils
- { name: ArduinoJson, version: 6.21.5 }
strategy:
matrix:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/esp8266-compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ jobs:
LIBRARIES: |
# Install the additionally needed dependency from the respository
- source-path: ./
- name: arduino-timer
- name: TBPubSubClient
- name: ArduinoHttpClient
- { name: ArduinoJson, version: 6.21.4 }
- { name: ArduinoJson, version: 6.21.5 }
- name: Seeed_Arduino_mbedtls
- name: StreamUtils
strategy:
matrix:
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/espidf-compile-v4.4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,21 @@ jobs:
esp_idf_version: v4.4
target: esp32
path: 'examples/0015-espressif_esp32_process_OTA_MQTT'
- name: Build process RPC example on v4.4
uses: espressif/esp-idf-ci-action@v1
with:
esp_idf_version: v4.4
target: esp32
path: 'examples/0016-espressif_esp32_rpc'
- name: Build process Shared Attribute example on v4.4
uses: espressif/esp-idf-ci-action@v1
with:
esp_idf_version: v4.4
target: esp32
path: 'examples/0017-espressif_esp32_process_shared_attribute_update'
- name: Build process Provision example on v4.4
uses: espressif/esp-idf-ci-action@v1
with:
esp_idf_version: v4.4
target: esp32
path: 'examples/0018-espressif_esp32_provision_device'
18 changes: 18 additions & 0 deletions .github/workflows/espidf-compile-v5.1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,21 @@ jobs:
esp_idf_version: v5.1
target: esp32
path: 'examples/0015-espressif_esp32_process_OTA_MQTT'
- name: Build process RPC example on v5.1
uses: espressif/esp-idf-ci-action@v1
with:
esp_idf_version: v5.1
target: esp32
path: 'examples/0016-espressif_esp32_rpc'
- name: Build process Shared Attribute example on v5.1
uses: espressif/esp-idf-ci-action@v1
with:
esp_idf_version: v5.1
target: esp32
path: 'examples/0017-espressif_esp32_process_shared_attribute_update'
- name: Build process Provision example on v5.1
uses: espressif/esp-idf-ci-action@v1
with:
esp_idf_version: v5.1
target: esp32
path: 'examples/0018-espressif_esp32_provision_device'
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 3.12)
set(srcs
src/Arduino_HTTP_Client.cpp
src/Arduino_MQTT_Client.cpp
src/Callback_Watchdog.cpp
src/Arduino_ESP32_Updater.cpp
src/Arduino_ESP8266_Updater.cpp
src/Espressif_Updater.cpp
Expand Down Expand Up @@ -41,4 +40,4 @@ if(ESP_PLATFORM)
return()
endif()

project(ThingsBoardClientSDK VERSION 0.13.0)
project(ThingsBoardClientSDK VERSION 0.14.0)
2 changes: 1 addition & 1 deletion Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ menu "ThingsBoard Client SDK Configurations"
bool "Replace static with dynami library usage"
default n
help
If this is enabled the library will use DynamicJsonDocument to receive messages from the MQTT broker and use Vector to hold Subscription data instead of Arrays. Removing the need to declare MaxFieldsAmount, MaxSubscribtions, MaxAttributes and MaxRPC template arguments. But instead increasing heap allocation and usage drastically.
If this is enabled the library will use DynamicJsonDocument to receive messages from the MQTT broker and use Vector to hold Subscription data instead of Arrays. Removing the need to declare MaxResponse, MaxSubscriptions, MaxAttributes, MaxRPC and MaxRequestRPC template arguments. But instead increasing heap allocation and usage drastically.

config THINGSBOARD_ENABLE_DEBUG
bool "Enable additional debug log messages"
Expand Down
285 changes: 215 additions & 70 deletions README.md

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions docs/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "ThingsBoard Client SDK"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 0.13.0
PROJECT_NUMBER = 0.14.0

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down Expand Up @@ -1978,7 +1978,7 @@ ENABLE_PREPROCESSING = YES
# The default value is: NO.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

MACRO_EXPANSION = NO
MACRO_EXPANSION = YES

# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then
# the macro expansion is limited to the macros specified with the PREDEFINED and
Expand Down Expand Up @@ -2124,7 +2124,7 @@ DIA_PATH =
# and usage relations if the target is undocumented or is not a class.
# The default value is: YES.

HIDE_UNDOC_RELATIONS = YES
HIDE_UNDOC_RELATIONS = NO

# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
# available from the path. This tool is part of Graphviz (see:
Expand All @@ -2133,7 +2133,7 @@ HIDE_UNDOC_RELATIONS = YES
# set to NO
# The default value is: NO.

HAVE_DOT = NO
HAVE_DOT = YES

# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed
# to run in parallel. When set to 0 doxygen will base this on the number of
Expand Down Expand Up @@ -2220,7 +2220,7 @@ UML_LIMIT_NUM_FIELDS = 10
# The default value is: NO.
# This tag requires that the tag HAVE_DOT is set to YES.

TEMPLATE_RELATIONS = NO
TEMPLATE_RELATIONS = YES

# If the INCLUDE_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are set to
# YES then doxygen will generate a graph for each documented file showing the
Expand Down Expand Up @@ -2293,7 +2293,7 @@ DIRECTORY_GRAPH = YES
# The default value is: png.
# This tag requires that the tag HAVE_DOT is set to YES.

DOT_IMAGE_FORMAT = png
DOT_IMAGE_FORMAT = svg

# If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to
# enable generation of interactive SVG images that allow zooming and panning.
Expand All @@ -2305,7 +2305,7 @@ DOT_IMAGE_FORMAT = png
# The default value is: NO.
# This tag requires that the tag HAVE_DOT is set to YES.

INTERACTIVE_SVG = NO
INTERACTIVE_SVG = YES

# The DOT_PATH tag can be used to specify the path where the dot tool can be
# found. If left blank, it is assumed the dot tool can be found in the path.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,64 +12,32 @@
#include <SoftwareSerial.h>


#if THINGSBOARD_ENABLE_PROGMEM
constexpr char WIFI_SSID[] PROGMEM = "YOUR_WIFI_SSID";
constexpr char WIFI_PASSWORD[] PROGMEM = "YOUR_WIFI_PASSWORD";
#else
constexpr char WIFI_SSID[] = "YOUR_WIFI_SSID";
constexpr char WIFI_PASSWORD[] = "YOUR_WIFI_PASSWORD";
#endif

// See https://thingsboard.io/docs/getting-started-guides/helloworld/
// to understand how to obtain an access token
#if THINGSBOARD_ENABLE_PROGMEM
constexpr char TOKEN[] PROGMEM = "YOUR_DEVICE_ACCESS_TOKEN";
#else
constexpr char TOKEN[] = "YOUR_DEVICE_ACCESS_TOKEN";
#endif

// Thingsboard we want to establish a connection too
#if THINGSBOARD_ENABLE_PROGMEM
constexpr char THINGSBOARD_SERVER[] PROGMEM = "demo.thingsboard.io";
#else
constexpr char THINGSBOARD_SERVER[] = "demo.thingsboard.io";
#endif

// MQTT port used to communicate with the server, 1883 is the default unencrypted MQTT port,
// whereas 8883 would be the default encrypted SSL MQTT port
#if THINGSBOARD_ENABLE_PROGMEM
constexpr uint16_t THINGSBOARD_PORT PROGMEM = 1883U;
#else
constexpr uint16_t THINGSBOARD_PORT = 1883U;
#endif

// Maximum size packets will ever be sent or received by the underlying MQTT client,
// if the size is to small messages might not be sent or received messages will be discarded
#if THINGSBOARD_ENABLE_PROGMEM
constexpr uint16_t MAX_MESSAGE_SIZE PROGMEM = 128U;
#else
constexpr uint16_t MAX_MESSAGE_SIZE = 128U;
#endif

// Baud rate for the debugging serial connection
// If the Serial output is mangled, ensure to change the monitor speed accordingly to this variable
#if THINGSBOARD_ENABLE_PROGMEM
constexpr uint32_t SERIAL_DEBUG_BAUD PROGMEM = 9600U;
constexpr uint32_t SERIAL_ESP8266_DEBUG_BAUD PROGMEM = 9600U;
#else
constexpr uint32_t SERIAL_DEBUG_BAUD = 9600U;
constexpr uint32_t SERIAL_ESP8266_DEBUG_BAUD = 9600U;
#endif

#if THINGSBOARD_ENABLE_PROGMEM
constexpr char CONNECTING_MSG[] PROGMEM = "Connecting to: (%s) with token (%s)";
constexpr char TEMPERATURE_KEY[] PROGMEM = "temperature";
constexpr char HUMIDITY_KEY[] PROGMEM = "humidity";
#else
constexpr char CONNECTING_MSG[] = "Connecting to: (%s) with token (%s)";
constexpr char TEMPERATURE_KEY[] = "temperature";
constexpr char HUMIDITY_KEY[] = "humidity";
#endif


// Serial driver for ESP
Expand All @@ -78,34 +46,22 @@ SoftwareSerial soft(2U, 3U); // RX, TX
WiFiEspClient espClient;
// Initalize the Mqtt client instance
Arduino_MQTT_Client mqttClient(espClient);
// Initialize ThingsBoard instance
// Initialize ThingsBoard instance with the maximum needed buffer size
ThingsBoard tb(mqttClient, MAX_MESSAGE_SIZE);


/// @brief Initalizes WiFi connection,
// will endlessly delay until a connection has been successfully established
void InitWiFi() {
#if THINGSBOARD_ENABLE_PROGMEM
Serial.println(F("Connecting to AP ..."));
#else
Serial.println("Connecting to AP ...");
#endif
// Attempting to establish a connection to the given WiFi network
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
// Delay 500ms until a connection has been successfully established
delay(500);
#if THINGSBOARD_ENABLE_PROGMEM
Serial.print(F("."));
#else
Serial.print(".");
#endif
}
#if THINGSBOARD_ENABLE_PROGMEM
Serial.println(F("Connected to AP"));
#else
Serial.println("Connected to AP");
#endif
#if ENCRYPTED
espClient.setCACert(ROOT_CERT);
#endif
Expand Down Expand Up @@ -141,11 +97,7 @@ void setup() {
WiFi.init(&soft);
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
#if THINGSBOARD_ENABLE_PROGMEM
Serial.println(F("WiFi shield not present"));
#else
Serial.println("WiFi shield not present");
#endif
// don't continue
while (true);
}
Expand All @@ -166,20 +118,12 @@ void loop() {
snprintf(message, sizeof(message), CONNECTING_MSG, THINGSBOARD_SERVER, TOKEN);
Serial.println(message);
if (!tb.connect(THINGSBOARD_SERVER, TOKEN, THINGSBOARD_PORT)) {
#if THINGSBOARD_ENABLE_PROGMEM
Serial.println(F("Failed to connect"));
#else
Serial.println("Failed to connect");
#endif
return;
}
}

#if THINGSBOARD_ENABLE_PROGMEM
Serial.println(F("Sending telemetry data..."));
#else
Serial.println("Sending telemetry data...");
#endif
// Uploads new telemetry to ThingsBoard using MQTT.
// See https://thingsboard.io/docs/reference/mqtt-api/#telemetry-upload-api
// for more details
Expand Down
Loading

0 comments on commit 12dd9ba

Please sign in to comment.