|
Astarte device API for C++ 0.8.1
Astarte device SDK for C++
|
This repository contains the implementation of the Astarte device SDK for C++. This library enables devices to communicate with an Astarte instance using one of two supported transport layers:
This library requires C++ 20 or later.
If using gRPC as the transport layer, this library relies on the Astarte message hub for connectivity. The message hub must be version 0.8.0 or higher.
This library requires several dependencies to function. By default, the build system imports them automatically using CMake's FetchContent. Alternatively, you can configure the build to use system-installed versions or manage dependencies via Conan.
The library uses spdlog for logging.
FetchContent.ASTARTE_USE_SYSTEM_SPDLOG to use a local installation.FetchContent.ASTARTE_USE_SYSTEM_MQTT to use system-installed dependencies.For MQTT communication, the SDK uses the paho MQTT C++ library. This is a wrapper around the Paho MQTT C library that enables direct connectivity with Astarte.
When gRPC is selected as the transport layer, the primary dependency is gRPC. While the officially supported version is v1.72.0, most recent versions should work.
FetchContent.ASTARTE_USE_SYSTEM_GRPC to use your system's gRPC installation.Note: Importing gRPC via
FetchContentrequires recompiling the gRPC library, which significantly increases build time. We recommend using a system-installed gRPC for faster development.
The Astarte message hub proto repository contains the .proto files and CMake functions required for gRPC communication with the message hub.
FetchContent.ASTARTE_MESSAGE_HUB_PROTO_DIR to the path of your local repository checkout.The samples folder contains various examples demonstrating how to use the SDK. A utility script, build_sample.sh, is provided to build these samples without interacting directly with CMake.
This library is designed to be integrated using CMake. Add the following to your CMakeLists.txt:
Ensure you link the library to your executable:
This library supports the Conan package manager. Although the package is not yet available on the Conan Center Index, you can install it into your local cache by cloning this repository and running:
Add the requirement to your project's conanfile:
Then, import and link the library in your CMake configuration:
You can expose certain internal dependencies as part of the library's public interface using specific CMake options.
To link spdlog as a public dependency, enable the option: ASTARTE_PUBLIC_SPDLOG_DEP.
To expose the generated gRPC stubs and Protobuf messages in the public interface (allowing direct access from your C++ code), enable the option: ASTARTE_PUBLIC_PROTO_DEP.
N.B. This option is intended primarily for development purposes.