This repo contains an implementation of an Astarte device SDK for C++.
N.B. At the current state this SDK only provides connectivity to Astarte through the Astarte message hub.
This library requires at least C++ 20.
This library relies on the Astarte message hub for connectivity with Astarte. The message hub should be at least at version 0.8.0 for this library to function properly.
Astarte data, both in transmission and reception is encapsulated in C++ objects. It is possible to pretty print data objects. The resulting string will be in a JSON compabile format and can be used to interact with the Astarte REST APIs during developement.
Some features of the library can be enabled or disabled using CMake options.
The spdlog libary is the logger used by the Astarte device library. By the default it's a private dependency, checked our with fetch content. However, the user can choose to link the library as a public dependency using the dedicated option ASTARTE_PUBLIC_SPDLOG_DEP.
The Astarte message hub proto is a separate CMake project that contains the protobuffer definitions of the gRPC used by this library to connect with the Astarte message hub. This feature makes the Astarte message hub proto project a public dependency of this library. The user can subsequently access the gRPC stubs directly from within C++ code.
The option to enable this feature is: ASTARTE_PUBLIC_PROTO_DEP.
N.B. This option should only be enabled during developement.
For this library to work properly some dependencies are required. All of them can be imported directly by the library using fetch content. However, the user may choose to use system installed ones setting some cmake options.
The most importand and large depencency for this library is gRPC. The officially supported version of gRPC is v1.72.0, but any gRPC recent version should work just fine.
By default gRPC will be imported using FetchContent. Users can choose to use their system gRPC by setting the CMake option ASTARTE_USE_SYSTEM_GRPC.
N.B. Importing gRPC with FetchContent requires a re-compilation of the gRPC library leading to a much longer build time. We suggest using your system gRPC for fast developement.
The Astarte message hub proto is a separate project that contains the protobuffer definitions of the gRPC used by this library to connect with the Astarte message hub. This dependency is imported using fetch content and it's necessary for the proper functioning of the library.
By default the Astarte message hub protos will be imported using FetchContent. Users can choose to use a local checkout of the repository by setting the CMake option ASTARTE_MESSAGE_HUB_PROTO_DIR to the appropriate directory.
This library uses spdlog to log information. The logging utility is imported using FetchContent and is an essential component of this library.
By default spdlog will be imported using FetchContent. Users can choose to use a local installation by setting the CMake option ASTARTE_USE_SYSTEM_SPDLOG.
Various samples have been added in the samples folder of this project. An utility bash script has also been added, named build_sample.sh. It can be used to build one of the samples without having to deal directly with CMake.
This library supports CMake as the default build system. It can be imported adding the following lines to your application CMakeList file.
include(FetchContent)
FetchContent_Declare(
astarte_device_sdk
GIT_REPOSITORY [email protected]:secomind/astarte-device-sdk-cpp.git
GIT_TAG v0.8.1
)
FetchContent_MakeAvailable(astarte_device_sdk)Additionally remember to link the library with your executable.
target_link_libraries(app
PRIVATE astarte_device_sdk)The package manager Conan is supported by this library. This package has not yet been added to the Conan center index and subsequently it's not yet available using the dependency import in a conanfile. However, users can always install into their local cache by checking out this repository and then running the following commands.
conan create . --build=missing --settings=compiler.cppstd=20The created package can then be added to the conanfile of a project.
[requires]
astarte-device-sdk/0.8.1Additionally remember to import and link the library with your executable.
find_package(astarte_device_sdk)
...
target_link_libraries(app
PRIVATE astarte_device_sdk::astarte_device_sdk)