Wrapper for the Tuya IoT Core SDK for Embedded C SDK
This wrapper modifies the original Tuya SDK so it conveniently can be used as single library for own projects / targets.
The following modifications/enhancements are applied to the original Tuya SDK:
- the examples from the SDK aren't built with the ALL target
(we are only interested in the Tuya SDK as library). - the platform/posix layer is only included
in the Tuya SDK for native build. This enables the possibilty to cross compile the Tuya SDK.
For cross compiling only network_wrapper.c is kept as it connects the Tuya SDK to mbedtls and we want to keep it.
More information about cross compiling later in this document. - an overall library named tuya-iot-core-sdk is build from the original Tuya SDK libraries
- This overall library
tuya-iot-core-sdk
can be installed.
Pass CMAKE_INSTALL_PREFIX when configuring this project to set the tuya-iot-core-sdk library/header installation directory of your choice.
As we now have a single Tuya SDK library, we can conveniently use and embed it to our project
-
as git submodule in your project and FetchContent_Declare() / FetchContent_MakeAvailable():
make_minimum_required( VERSION 3.11.0 ) project( my_project LANGUAGES C ) include( FetchContent ) # add Tuya IoT Core SDK FetchContent_Declare( tuya-iot-core-sdk SOURCE_DIR ${CMAKE_SOURCE_DIR}/tuya-iot-core-sdk ) FetchContent_MakeAvailable( tuya-iot-core-sdk ) # my project as executable # (we can simply use / start from a copy of a Tuya SDK example source file we copy to our local project # e.g. tuya-iot-core-sdk/examples/data_model_basic_demo/data_model_basic_demo.c) add_executable( my_project data_model_basic_demo.c ) # link Tuya SDK as dependency to my project add_dependencies( my_project tuya-iot-core-sdk ) target_link_libraries( my_project tuya-iot-core-sdk )
-
directly by FetchContent_Declare() / FetchContent_MakeAvailable() (populate at configure time):
make_minimum_required( VERSION 3.11.0 ) project( my_project LANGUAGES C ) include( FetchContent ) # add Tuya IoT Core SDK FetchContent_Declare( tuya-iot-core-sdk GIT_REPOSITORY https://github.com/gcopoix/tuya-iot-core-sdk.git GIT_TAG <commit hash> ) FetchContent_MakeAvailable( tuya-iot-core-sdk ) # my project as executable # (we can simply use / start from a copy of a Tuya SDK example source file we copy to our local project # e.g. tuya-iot-core-sdk/examples/data_model_basic_demo/data_model_basic_demo.c) add_executable( my_project data_model_basic_demo.c ) # link Tuya SDK as dependency to my project add_dependencies( my_project tuya-iot-core-sdk ) target_link_libraries( my_project tuya-iot-core-sdk )
-
as git submodule in your project and add_subdirectory():
make_minimum_required( VERSION 3.5.0 ) project( my_project LANGUAGES C ) # add Tuya IoT Core SDK add_subdirectory( tuya-iot-core-sdk ) # my project as executable # (we can simply use / start from a copy of a Tuya SDK example source file we copy to our local project # e.g. tuya-iot-core-sdk/examples/data_model_basic_demo/data_model_basic_demo.c) add_executable( my_project data_model_basic_demo.c ) # link Tuya SDK as dependency to my project add_dependencies( my_project tuya-iot-core-sdk ) target_link_libraries( my_project tuya-iot-core-sdk )
With the modifications above the Tuya SDK library now can be cross compiled.
To fulfill the dependencies for a cross compiled Tuya SDK please implement the platform wrappers for your own target:
- system_wrapper.c (implementing system_interface.h)
- storage_wrapper.c (implementing storage_interface.h)
- If using mbedtls from the Tuya SDK (preferred option):
- mbedtls_sockets_wrapper.c implementing mbedtls/net_sockets.h
(network_wrapper.c from the Tuya SDK is still part of this library as it connects the Tuya SDK to mbedtls)
- mbedtls_sockets_wrapper.c implementing mbedtls/net_sockets.h
- if using an own TLS implementation:
- own network_wrapper.c implementing network_interface.h
(nombedtls_sockets_wrapper.c
required, no mbedtls used from the Tuya SDK in this case)
- own network_wrapper.c implementing network_interface.h
An ESP-IDF wrapper implementation is mentioned e.g. here
More information about cross compiling in the cmake documentation.