### Compile and Run IOWA SDK Samples on Linux Source: https://github.com/ioterop/iowa/blob/master/README.md This snippet provides the command-line steps to build and execute IOWA SDK samples on a Linux system. It covers creating a build directory, configuring with CMake, compiling with Make, navigating to a sample, and running it. ```Shell mkdir build ``` ```Shell cd build ``` ```Shell cmake -DCMAKE_BUILD_TYPE=Debug .. ``` ```Shell make -j 4 ``` ```Shell cd samples/01-baseline_client ``` ```Shell ./baseline_client ``` -------------------------------- ### Clone Ioterop IOWA GitHub Repository Source: https://github.com/ioterop/iowa/blob/master/README.md This command is used to clone the Ioterop IOWA GitHub repository, which contains the source code and all available SDK samples. It's the first step in setting up the development environment. ```Bash git clone https://github.com/IOTEROP/IOWA.git ``` -------------------------------- ### CMake Project Setup and IOWA SDK Inclusion Source: https://github.com/ioterop/iowa/blob/master/samples/01-baseline_client/CMakeLists.txt This snippet defines the minimum CMake version, sets up the project name, and locates/includes the IoTerop (IOWA) SDK. It checks for a global property `iowa_sdk_folder` and falls back to a relative path if not found, then includes the SDK's CMake file. ```CMake cmake_minimum_required(VERSION 3.5) project(baseline_client C) get_property(IOWA_DIR GLOBAL PROPERTY iowa_sdk_folder) if (NOT IOWA_DIR) set(IOWA_DIR ${CMAKE_CURRENT_LIST_DIR}/../../iowa) endif() include(${IOWA_DIR}/src/iowa.cmake) ``` -------------------------------- ### Example tinydtls Client PSK Credentials Configuration Source: https://github.com/ioterop/iowa/blob/master/samples/08-secure_client_tinydtls/README.md Provides an example of how to define Pre-Shared Key (PSK) identity and key value in a C header file for tinydtls client security configuration. This demonstrates the correct format for `SAMPLE_PSK_IDENTITY` as a string and `SAMPLE_PSK_KEY` as a byte array. ```c // PSK security credentials #define SAMPLE_PSK_IDENTITY "MyTestID" #define SAMPLE_PSK_KEY {'T','e','s','t','K','E','Y'} ``` -------------------------------- ### Example Mbed TLS PSK Credentials Configuration in C Source: https://github.com/ioterop/iowa/blob/master/samples/07-secure_client_mbedtls3/README.md This C code snippet provides an example of how to define Pre-Shared Key (PSK) identity and key for Mbed TLS security. It demonstrates setting a string for `SAMPLE_PSK_IDENTITY` and a byte array for `SAMPLE_PSK_KEY`. ```C // PSK security credentials #define SAMPLE_PSK_IDENTITY "MyTestID" #define SAMPLE_PSK_KEY {'T','e','s','t','K','E','Y'} ``` -------------------------------- ### IOWA IPSO Client API Reference Source: https://github.com/ioterop/iowa/blob/master/samples/02-IPSO_client/README.md This section details the core API functions for managing IPSO objects within the IOWA LwM2M client. It includes functions for adding, updating, and removing sensor instances, along with their parameters, return values, and usage examples. ```APIDOC iowa_client_IPSO_add_sensor(iowaH, IOWA_IPSO_TEMPERATURE, initial_value, unit, application_type, min_range_value, max_range_value, &sensorId) - Adds an IPSO sensor instance to the LwM2M Client. - Parameters: - iowaH: The IOWA context, created during initialization. - IOWA_IPSO_TEMPERATURE: The type of the sensor (e.g., IOWA_IPSO_TEMPERATURE for a temperature sensor). - initial_value: The initial value of the sensor. Interpretation (float, int, bool) depends on sensor type. - unit: (Optional) Human-readable representation of the unit (e.g., "Cel"). Has no impact on object behavior. - application_type: (Optional) Human-readable string for LwM2M Server to discriminate sensors of the same type. - min_range_value: (Optional) Minimum measurable value by the sensor. If both min/max are zero, resources are not exposed. - max_range_value: (Optional) Maximum measurable value by the sensor. If both min/max are zero, resources are not exposed. - &sensorId: Pointer to store the sensor identifier generated by IOWA, used in other APIs. - Returns: A result code indicating success or failure (e.g., IOWA_COAP_NO_ERROR). - Example: iowa_sensor_t sensorId; result = iowa_client_IPSO_add_sensor(iowaH, IOWA_IPSO_TEMPERATURE, 20, "Cel", "Test Temperature", -20.0, 50.0, &sensorId); iowa_client_IPSO_update_value(iowaH, sensorId, new_value) - Informs IOWA that the value measured by the sensor has changed. - Parameters: - iowaH: The IOWA context. - sensorId: The identifier of the sensor, retrieved from `iowa_client_IPSO_add_sensor()`. - new_value: The new value measured by the sensor. Interpretation (float, int, bool) depends on sensor type. - Returns: A result code indicating success or failure (e.g., IOWA_COAP_NO_ERROR). - Usage: The function handles LwM2M Server operations (Read, Write, Observations) on the Object Instance. - Example: int i; for (i = 0; i < 40 && result == IOWA_COAP_NO_ERROR; i++) { result = iowa_step(iowaH, 3); result = iowa_client_IPSO_update_value(iowaH, sensorId, 20 + i%4); } iowa_client_IPSO_remove_sensor(iowaH, sensorId) - Removes an IPSO sensor instance from the LwM2M Client. - Parameters: - iowaH: The IOWA context. - sensorId: The identifier of the sensor, retrieved from `iowa_client_IPSO_add_sensor()`. - Returns: A result code indicating success or failure. - Example: iowa_client_IPSO_remove_sensor(iowaH, sensorId); ``` -------------------------------- ### Run LwM2M Baseline Client Sample Source: https://github.com/ioterop/iowa/blob/master/samples/01-baseline_client/README.md Demonstrates how to execute the compiled baseline client sample from the command line, showing its output during registration to a LwM2M server and displaying the assigned endpoint name. ```bash $ ./Evaluation_SDK_Samples/01-baseline_client/baseline_client This a simple LwM2M Client. Registering to the LwM2M server at "coap://datagram-no-sec-ingress.alaska.ioterop.com" under the Endpoint name "IOWA_sample_client_8323329". Use Ctrl-C to stop. ``` -------------------------------- ### Configure IOWA SDK Samples Build Environment Source: https://github.com/ioterop/iowa/blob/master/docker/samples/CMakeLists.txt This CMake script configures the build environment for the IOWA SDK samples. It sets the minimum required CMake version, defines the project, locates the IOWA SDK (defaulting to a parent directory if not found), and includes various sample subdirectories for different client types and custom object implementations. It also handles platform-specific inclusions, such as `tinydtls` for non-Windows systems, and sets the runtime output directory. ```CMake cmake_minimum_required(VERSION 3.5) project(IOWA_Evaluation_SDK_samples C) get_property(IOWA_DIR GLOBAL PROPERTY iowa_sdk_folder) if (NOT IOWA_DIR) # The samples expect the IOWA SDK to be present in the parent folder. # You can modify the following line to point to a different location. set_property(GLOBAL PROPERTY iowa_sdk_folder "${CMAKE_CURRENT_LIST_DIR}/../iowa") endif() set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/../bin) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/01-baseline_client) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/02-IPSO_client) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/03-custom_object_baseline) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/04-custom_object_dynamic) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/05-custom_object_multiple_instances) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/06-custom_object_multiple_resource_instances) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/07-secure_client_mbedtls3) if (NOT WIN32) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/08-secure_client_tinydtls) endif() add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/IOWA_cli) ``` -------------------------------- ### CMake Project Initialization and IOWA SDK Path Resolution Source: https://github.com/ioterop/iowa/blob/master/samples/07-secure_client_mbedtls3/CMakeLists.txt This snippet sets the minimum required CMake version, defines the project name and language, and resolves the path to the IOWA SDK. It first attempts to retrieve a global property and falls back to a relative path if not found. It also includes the `FetchContent` module and handles a CMake policy for newer versions to avoid warnings. ```CMake cmake_minimum_required(VERSION 3.11) project(secure_client_mbedtls3 C) get_property(IOWA_DIR GLOBAL PROPERTY iowa_sdk_folder) if (NOT IOWA_DIR) set(IOWA_DIR ${CMAKE_CURRENT_LIST_DIR}/../../iowa) endif() # Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24+: if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0") cmake_policy(SET CMP0135 NEW) endif() include(FetchContent) ``` -------------------------------- ### Configure IoTerop iowa C Project with CMake Source: https://github.com/ioterop/iowa/blob/master/samples/05-custom_object_multiple_instances/CMakeLists.txt This CMake script defines the build process for a C project utilizing the IoTerop iowa SDK. It sets up the project name, locates the SDK, adds executable sources, specifies include directories, and handles platform-specific library linking and compilation flags for Windows. ```CMake ########################################## # # Copyright (c) 2016-2020 IoTerop. # All rights reserved. # ########################################## cmake_minimum_required(VERSION 3.5) project(custom_object_multiple_instances C) get_property(IOWA_DIR GLOBAL PROPERTY iowa_sdk_folder) if (NOT IOWA_DIR) set(IOWA_DIR ${CMAKE_CURRENT_LIST_DIR}/../../iowa) endif() include(${IOWA_DIR}/src/iowa.cmake) ############################################ # Build project # add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/main.c ${CMAKE_CURRENT_LIST_DIR}/sample_object.c ${CMAKE_CURRENT_LIST_DIR}/iowa_config.h ${CMAKE_CURRENT_LIST_DIR}/../abstraction_layer/core_abstraction.c ${CMAKE_CURRENT_LIST_DIR}/../abstraction_layer/connection_abstraction.c ${IOWA_CLIENT_SOURCES} ${IOWA_CLIENT_HEADERS}) target_include_directories(${PROJECT_NAME} PRIVATE ${IOWA_INCLUDE_DIR} ${CMAKE_CURRENT_LIST_DIR}) if (WIN32) target_link_libraries(${PROJECT_NAME} wsock32 ws2_32) endif() ## Compilation flags if (WIN32) set(CMAKE_C_FLAGS_DEBUG "/ZI") endif() ``` -------------------------------- ### Configure IOWA SDK Samples using CMake Source: https://github.com/ioterop/iowa/blob/master/CMakeLists.txt This CMakeLists.txt snippet defines the build process for IOWA SDK samples. It ensures a minimum CMake version, declares the project name and language, sets a global property for the IOWA SDK folder path (which can be easily modified), and includes the 'samples' subdirectory for compilation. ```CMake cmake_minimum_required(VERSION 3.5) project(IOWA_samples C) set_property(GLOBAL PROPERTY iowa_sdk_folder "${CMAKE_CURRENT_LIST_DIR}/iowa") add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/samples) ``` -------------------------------- ### Configure IPSO Client Project with CMake Source: https://github.com/ioterop/iowa/blob/master/samples/02-IPSO_client/CMakeLists.txt This CMake script defines the build process for the IPSO client application. It sets the minimum required CMake version, defines the project name, locates the IOWA SDK, includes necessary CMake modules, adds the executable with its source files and headers, specifies include directories, and conditionally links Windows-specific libraries and sets debug flags. ```CMake ########################################## # # Copyright (c) 2016-2020 IoTerop. # All rights reserved. # ########################################## cmake_minimum_required(VERSION 3.5) project(IPSO_client C) get_property(IOWA_DIR GLOBAL PROPERTY iowa_sdk_folder) if (NOT IOWA_DIR) set(IOWA_DIR ${CMAKE_CURRENT_LIST_DIR}/../../iowa) endif() include(${IOWA_DIR}/src/iowa.cmake) ############################################ # Build project # add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/main.c ${CMAKE_CURRENT_LIST_DIR}/iowa_config.h ${CMAKE_CURRENT_LIST_DIR}/../abstraction_layer/core_abstraction.c ${CMAKE_CURRENT_LIST_DIR}/../abstraction_layer/connection_abstraction.c ${IOWA_CLIENT_SOURCES} ${IOWA_CLIENT_HEADERS}) target_include_directories(${PROJECT_NAME} PRIVATE ${IOWA_INCLUDE_DIR} ${CMAKE_CURRENT_LIST_DIR}) if (WIN32) target_link_libraries(${PROJECT_NAME} wsock32 ws2_32) endif() ## Compilation flags if (WIN32) set(CMAKE_C_FLAGS_DEBUG "/ZI") endif() ``` -------------------------------- ### Configure CMake Build for IoTerop IOWA Client Source: https://github.com/ioterop/iowa/blob/master/samples/04-custom_object_dynamic/CMakeLists.txt This CMake script defines the build process for a custom IoT device client using the IoTerop IOWA SDK. It sets the minimum CMake version, defines the project name, locates the IOWA SDK directory, includes necessary CMake modules, adds executable sources, specifies include directories, and applies platform-specific linking and compilation flags for Windows. ```CMake cmake_minimum_required(VERSION 3.5) project(custom_object_dynamic_client C) get_property(IOWA_DIR GLOBAL PROPERTY iowa_sdk_folder) if (NOT IOWA_DIR) set(IOWA_DIR ${CMAKE_CURRENT_LIST_DIR}/../../iowa) endif() include(${IOWA_DIR}/src/iowa.cmake) add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/main.c ${CMAKE_CURRENT_LIST_DIR}/sample_object.c ${CMAKE_CURRENT_LIST_DIR}/iowa_config.h ${CMAKE_CURRENT_LIST_DIR}/../abstraction_layer/core_abstraction.c ${CMAKE_CURRENT_LIST_DIR}/../abstraction_layer/connection_abstraction.c ${IOWA_CLIENT_SOURCES} ${IOWA_CLIENT_HEADERS}) target_include_directories(${PROJECT_NAME} PRIVATE ${IOWA_INCLUDE_DIR} ${CMAKE_CURRENT_LIST_DIR}) if (WIN32) target_link_libraries(${PROJECT_NAME} wsock32 ws2_32) endif() if (WIN32) set(CMAKE_C_FLAGS_DEBUG "/ZI") endif() ``` -------------------------------- ### CMake Target Include Directories and Link Libraries Source: https://github.com/ioterop/iowa/blob/master/samples/01-baseline_client/CMakeLists.txt This snippet configures the include directories for the project, adding the IOWA SDK include path and the current directory. It also conditionally links Windows-specific libraries (`wsock32`, `ws2_32`) if the target platform is WIN32. ```CMake target_include_directories(${PROJECT_NAME} PRIVATE ${IOWA_INCLUDE_DIR} ${CMAKE_CURRENT_LIST_DIR}) if (WIN32) target_link_libraries(${PROJECT_NAME} wsock32 ws2_32) endif() ``` -------------------------------- ### Configure IOWA SDK Samples with CMake Source: https://github.com/ioterop/iowa/blob/master/samples/CMakeLists.txt This CMake script defines the build process for the IOWA SDK samples. It sets the minimum required CMake version, defines the project name, and attempts to locate the IOWA SDK directory. If the SDK path is not globally defined, it defaults to a relative path. The script then includes various sample subdirectories, with some being conditionally added based on the operating system (e.g., '08-secure_client_tinydtls' is excluded on Windows). It also adds a preprocessor definition for MSVC compilers to suppress CRT secure warnings. ```CMake cmake_minimum_required(VERSION 3.5) project(IOWA_Evaluation_SDK_samples C) get_property(IOWA_DIR GLOBAL PROPERTY iowa_sdk_folder) if (NOT IOWA_DIR) # The samples expect the IOWA SDK to be present in the parent folder. # You can modify the following line to point to a different location. set_property(GLOBAL PROPERTY iowa_sdk_folder "${CMAKE_CURRENT_LIST_DIR}/../iowa") endif() add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/01-baseline_client) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/02-IPSO_client) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/03-custom_object_baseline) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/04-custom_object_dynamic) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/05-custom_object_multiple_instances) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/06-custom_object_multiple_resource_instances) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/07-secure_client_mbedtls3) if (NOT WIN32) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/08-secure_client_tinydtls) endif() if(MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS) endif() ``` -------------------------------- ### Add Executable and Link Libraries for Secure Client Source: https://github.com/ioterop/iowa/blob/master/samples/08-secure_client_tinydtls/CMakeLists.txt This snippet defines the executable for the project, including all necessary source files from the current directory, IOWA SDK, and the fetched TinyDTLS library. It then sets the private include directories for the project and conditionally links Windows-specific libraries (`wsock32`, `ws2_32`) if building on a Windows platform. ```CMake include(${CMAKE_CURRENT_LIST_DIR}/tinydtls.cmake) include(${IOWA_DIR}/src/iowa.cmake) add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/main.c ${CMAKE_CURRENT_LIST_DIR}/user_security_tinydtls.c ${CMAKE_CURRENT_LIST_DIR}/iowa_config.h ${CMAKE_CURRENT_LIST_DIR}/../abstraction_layer/core_abstraction.c ${CMAKE_CURRENT_LIST_DIR}/../abstraction_layer/connection_abstraction.c ${IOWA_CLIENT_SOURCES} ${IOWA_CLIENT_HEADERS} ${TINYDTLS_SOURCES} ${TINYDTLS_HEADERS}) target_include_directories(${PROJECT_NAME} PRIVATE ${IOWA_INCLUDE_DIR} ${TINYDTLS_INCLUDE_DIR} ${CMAKE_CURRENT_LIST_DIR}) if (WIN32) target_link_libraries(${PROJECT_NAME} wsock32 ws2_32) endif() ``` -------------------------------- ### Define Project Executable and Source Files Source: https://github.com/ioterop/iowa/blob/master/samples/03-custom_object_baseline/CMakeLists.txt This section defines the executable for the project, listing all necessary source files and headers. It includes application-specific files, abstraction layer components, and IOWA client sources and headers, ensuring all required code is compiled into the final binary. ```CMake add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/main.c ${CMAKE_CURRENT_LIST_DIR}/sample_object.c ${CMAKE_CURRENT_LIST_DIR}/iowa_config.h ${CMAKE_CURRENT_LIST_DIR}/../abstraction_layer/core_abstraction.c ${CMAKE_CURRENT_LIST_DIR}/../abstraction_layer/connection_abstraction.c ${IOWA_CLIENT_SOURCES} ${IOWA_CLIENT_HEADERS}) ``` -------------------------------- ### Initialize IOWA Context Source: https://github.com/ioterop/iowa/blob/master/samples/01-baseline_client/README.md Shows how to initialize the IOWA library by creating a new context. This context is crucial as IOWA does not use global variables, storing all its internal data within this context. ```c iowa_context_t iowaH; iowaH = iowa_init(NULL); ``` -------------------------------- ### Run a Specific Sample within IOWA SDK Lite Docker Container Source: https://github.com/ioterop/iowa/blob/master/docker/README.md This command executes a specific application, `IPSO_client`, located at `./bin/IPSO_client` inside the `iowa_sdk_lite` Docker container. The `--init` flag is used to run an init process inside the container, which handles signal forwarding and allows the sample to be stopped gracefully using Ctrl-C. ```Shell docker run --init iowa_sdk_lite ./bin/IPSO_client ``` -------------------------------- ### CMake Executable Definition and Source Files Source: https://github.com/ioterop/iowa/blob/master/samples/01-baseline_client/CMakeLists.txt This section defines the executable for the project, adding `main.c`, `iowa_config.h`, core and connection abstraction layers, and other client-specific sources and headers. It uses the `${PROJECT_NAME}` variable for the executable name. ```CMake add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/main.c ${CMAKE_CURRENT_LIST_DIR}/iowa_config.h ${CMAKE_CURRENT_LIST_DIR}/../abstraction_layer/core_abstraction.c ${CMAKE_CURRENT_LIST_DIR}/../abstraction_layer/connection_abstraction.c ${IOWA_CLIENT_SOURCES} ${IOWA_CLIENT_HEADERS}) ``` -------------------------------- ### IOWA LwM2M Client API Reference Source: https://github.com/ioterop/iowa/blob/master/samples/01-baseline_client/README.md Comprehensive documentation for key IOWA library functions used in LwM2M client management, including adding and removing servers, and managing the main event loop. This section details function signatures, parameter descriptions, and their roles in the client's lifecycle. ```APIDOC iowa_client_add_server(iowa_context_t iowaH, uint16_t short_id, const char* uri, uint32_t lifetime, uint32_t flags, iowa_security_mode_t security_mode) - Description: Configures and adds a LwM2M Server to the IOWA Client. - Parameters: - iowaH: The IOWA context handle, created in an earlier step. - short_id: A numeric identifier for the LwM2M Server, known as "Short Server ID" in the LwM2M protocol. Other IOWA APIs use this to reference the server. - uri: The LwM2M Server URI (e.g., "coap://datagram-no-sec-ingress.alaska.ioterop.com"). - lifetime: The registration lifetime in seconds. This is the validity period of the client's registration to the server. The client sends Registration Update messages to renew this period. - flags: Flags enabling advanced features (e.g., 0 for baseline). - security_mode: The security mode used for communication with the LwM2M Server (e.g., IOWA_SEC_NONE). - Returns: An integer result code indicating success or failure. iowa_step(iowa_context_t iowaH, uint32_t timeout_ms) - Description: Manages the Finite State Machine of the LwM2M and CoAP stacks. This function must be called periodically for IOWA to operate. - Parameters: - iowaH: The IOWA context handle. - timeout_ms: The maximum time (in milliseconds) allowed for IOWA to run. The function will not return until this time expires or an error occurs. - Returns: An integer result code. iowa_client_remove_server(iowa_context_t iowaH, uint16_t short_id) - Description: Removes a LwM2M Server from the IOWA Client. Calling this API automatically sends a deregistration message to the Server. - Parameters: - iowaH: The IOWA context handle. - short_id: The Short Server ID of the LwM2M Server to be removed, as passed to `iowa_client_add_server()`. - Returns: An integer result code. iowa_close(iowa_context_t iowaH) - Description: Frees the IOWA context and associated resources to prevent memory leaks. This should be called when the client is no longer needed. - Parameters: - iowaH: The IOWA context handle to be closed. - Returns: An integer result code. ``` -------------------------------- ### Fetch Mbed TLS v3.1.0 using FetchContent Source: https://github.com/ioterop/iowa/blob/master/samples/07-secure_client_mbedtls3/CMakeLists.txt This section demonstrates how to use CMake's `FetchContent` module to download and populate the Mbed TLS library version 3.1.0 from its official GitHub repository. It declares the content source URL and then triggers the download and extraction process, providing a user message during retrieval. ```CMake FetchContent_Declare( mbedtls3 URL https://github.com/Mbed-TLS/mbedtls/archive/refs/tags/v3.1.0.zip ) message("Retrieving Mbed TLS v3.1.0 release from https://github.com/Mbed-TLS/mbedtls...") FetchContent_Populate(mbedtls3) ``` -------------------------------- ### Configure CMake Project and Include IOWA SDK Source: https://github.com/ioterop/iowa/blob/master/samples/03-custom_object_baseline/CMakeLists.txt This snippet sets the minimum required CMake version, defines the project name and language, and locates the IoTerop IOWA SDK directory. It then includes the main IOWA CMake script to integrate the SDK's build system. ```CMake cmake_minimum_required(VERSION 3.5) project(custom_object_baseline_client C) get_property(IOWA_DIR GLOBAL PROPERTY iowa_sdk_folder) if (NOT IOWA_DIR) set(IOWA_DIR ${CMAKE_CURRENT_LIST_DIR}/../../iowa) endif() include(${IOWA_DIR}/src/iowa.cmake) ``` -------------------------------- ### Execute IOWA Main Loop Step in C Source: https://github.com/ioterop/iowa/blob/master/samples/01-baseline_client/README.md This C code snippet illustrates the core operation of the IOWA client by calling `iowa_step()`. This function manages the internal Finite State Machine for LwM2M and CoAP stacks, handling communication and state transitions. The second argument specifies the maximum time (in seconds) the function is allowed to run before returning. ```C result = iowa_step(iowaH, 120); ``` -------------------------------- ### IOWA LwM2M Client Core API Source: https://github.com/ioterop/iowa/blob/master/samples/01-baseline_client/README.md Comprehensive documentation for the core API functions used to manage an IOWA LwM2M client, covering initialization, configuration, server management, and the main processing loop. ```APIDOC iowa_init(user_data_ptr: void*) - Description: Creates a new IOWA context. IOWA does not use global variables; all internal data is stored in this context. - Parameters: - user_data_ptr: An optional user-defined pointer passed to the system abstraction functions. Can be NULL. - Returns: iowa_context_t (a handle to the new IOWA context). iowa_close(iowa_context: iowa_context_t) - Description: Cleans up and closes the IOWA context, releasing associated resources. - Parameters: - iowa_context: The IOWA context handle to close. - Returns: void. iowa_client_configure(iowa_context: iowa_context_t, endpoint_name: char*, device_info: iowa_device_info_t*, event_callback: void*) - Description: Configures the LwM2M client, setting its endpoint name and optional device information. - Parameters: - iowa_context: The IOWA context created by iowa_init(). - endpoint_name: The unique name for the LwM2M Client. For non-secure samples, this is the primary identifier for the LwM2M Server. - device_info: An optional pointer to an iowa_device_info_t structure containing values for resources exposed in the LwM2M Device Object (ID: 3). If NULL or members are unset, corresponding resources will not be presented. - event_callback: An optional event callback function (explained in another sample). - Returns: iowa_status_t (status of the configuration operation). iowa_client_add_server(iowa_context: iowa_context_t, short_id: uint16_t, uri: char*, lifetime: uint32_t) - Description: Declares and adds a LwM2M server to which the client will register. - Parameters: - iowa_context: The IOWA context. - short_id: A short identifier for the server. - uri: The URI of the LwM2M server (e.g., "coap://server.example.com"). - lifetime: The client's registration lifetime with the server in seconds. - Returns: iowa_status_t. iowa_client_remove_server(iowa_context: iowa_context_t, short_id: uint16_t) - Description: Removes a previously added LwM2M server from the client's configuration. - Parameters: - iowa_context: The IOWA context. - short_id: The short identifier of the server to remove. - Returns: iowa_status_t. iowa_step(iowa_context: iowa_context_t, timeout_ms: uint32_t) - Description: The main processing function for the IOWA client, handling network events and LwM2M operations. It should be called periodically. - Parameters: - iowa_context: The IOWA context. - timeout_ms: The maximum time in milliseconds to wait for network events. - Returns: iowa_status_t. ``` -------------------------------- ### Configure IoTerop C Project with CMake Source: https://github.com/ioterop/iowa/blob/master/samples/06-custom_object_multiple_resource_instances/CMakeLists.txt This CMake script defines the build process for a C project within the IoTerop framework. It sets the minimum CMake version, defines the project name, locates the IoTerop SDK, adds executable sources, specifies include directories, and applies platform-specific link libraries and compilation flags for Windows. ```CMake cmake_minimum_required(VERSION 3.5) project(custom_object_multiple_resourece_instances C) get_property(IOWA_DIR GLOBAL PROPERTY iowa_sdk_folder) if (NOT IOWA_DIR) set(IOWA_DIR ${CMAKE_CURRENT_LIST_DIR}/../../iowa) endif() include(${IOWA_DIR}/src/iowa.cmake) ############################################ # Build project # add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/main.c ${CMAKE_CURRENT_LIST_DIR}/sample_object.c ${CMAKE_CURRENT_LIST_DIR}/iowa_config.h ${CMAKE_CURRENT_LIST_DIR}/../abstraction_layer/core_abstraction.c ${CMAKE_CURRENT_LIST_DIR}/../abstraction_layer/connection_abstraction.c ${IOWA_CLIENT_SOURCES} ${IOWA_CLIENT_HEADERS}) target_include_directories(${PROJECT_NAME} PRIVATE ${IOWA_INCLUDE_DIR} ${CMAKE_CURRENT_LIST_DIR}) if (WIN32) target_link_libraries(${PROJECT_NAME} wsock32 ws2_32) endif() ## Compilation flags if (WIN32) set(CMAKE_C_FLAGS_DEBUG "/ZI") endif() ``` -------------------------------- ### Fetch TinyDTLS Source Code with FetchContent Source: https://github.com/ioterop/iowa/blob/master/samples/08-secure_client_tinydtls/CMakeLists.txt This section uses CMake's `FetchContent` module to download the TinyDTLS library from its GitHub repository. It includes a conditional check to skip the build process and return if the operating system is Windows, as TinyDTLS does not support Windows platforms. ```CMake include(FetchContent) if (WIN32) message("Tinydtls does not build on Windows platforms, skipping this sample build.") return() endif() FetchContent_Declare( tinydtls URL https://github.com/eclipse/tinydtls/archive/706888256c3e03d9fcf1ec37bb1dd6499213be3c.zip ) message("Retrieving tinydtls from https://github.com/eclipse/tinydtls...") FetchContent_Populate(tinydtls) ``` -------------------------------- ### Apply Windows-Specific Linking and Compilation Flags Source: https://github.com/ioterop/iowa/blob/master/samples/03-custom_object_baseline/CMakeLists.txt This snippet applies platform-specific configurations for Windows builds. It links necessary socket libraries (wsock32, ws2_32) for network communication and sets the debug compilation flag '/ZI' for program database generation. ```CMake if (WIN32) target_link_libraries(${PROJECT_NAME} wsock32 ws2_32) endif() if (WIN32) set(CMAKE_C_FLAGS_DEBUG "/ZI") endif() ``` -------------------------------- ### Configure tinydtls Client PSK Credentials Placeholder Source: https://github.com/ioterop/iowa/blob/master/samples/08-secure_client_tinydtls/README.md Defines placeholders for Pre-Shared Key (PSK) identity and key value in a C header file (`sample_env.h`) for tinydtls client security configuration. These values must be replaced with actual credentials to establish a secure connection. ```c // PSK security credentials #define SAMPLE_PSK_IDENTITY " /*Enter your Pre-Shared Key identity here as String */" #define SAMPLE_PSK_KEY {/*Enter your Pre-Shared Key value here as bytes array*/ } ``` -------------------------------- ### Add LwM2M Server to IOWA Client in C Source: https://github.com/ioterop/iowa/blob/master/samples/01-baseline_client/README.md This C code demonstrates how to register a LwM2M server with the IOWA client using the `iowa_client_add_server()` API. It utilizes predefined configuration macros for the server's short ID, URI, and lifetime, establishing the client's connection parameters to the LwM2M server. ```C #define SERVER_SHORT_ID SAMPLE_SERVER_SHORT_ID #define SERVER_LIFETIME SAMPLE_SERVER_LIFETIME #define SERVER_URI SAMPLE_SERVER_URI result = iowa_client_add_server(iowaH, SERVER_SHORT_ID, SERVER_URI, SERVER_LIFETIME, 0, IOWA_SEC_NONE); ``` -------------------------------- ### CMake Executable Definition, Include Paths, and Linking Source: https://github.com/ioterop/iowa/blob/master/samples/07-secure_client_mbedtls3/CMakeLists.txt This snippet configures the main executable for the project, including source files from the current directory, IOWA client, and Mbed TLS. It sets a compile definition for the Mbed TLS configuration file and specifies all necessary include directories. Additionally, it conditionally links Windows-specific libraries (wsock32, ws2_32) if the target platform is WIN32. ```CMake include(${CMAKE_CURRENT_LIST_DIR}/mbedtls.cmake) include(${IOWA_DIR}/src/iowa.cmake) add_compile_definitions(MBEDTLS_CONFIG_FILE="${CMAKE_CURRENT_LIST_DIR}/mbedtls_config.h") add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/main.c ${CMAKE_CURRENT_LIST_DIR}/user_security_mbedtls3.c ${CMAKE_CURRENT_LIST_DIR}/iowa_config.h ${CMAKE_CURRENT_LIST_DIR}/../abstraction_layer/core_abstraction.c ${CMAKE_CURRENT_LIST_DIR}/../abstraction_layer/connection_abstraction.c ${IOWA_CLIENT_SOURCES} ${IOWA_CLIENT_HEADERS} ${MBEDTLS_SOURCES} ${MBEDTLS_HEADERS}) target_include_directories(${PROJECT_NAME} PRIVATE ${IOWA_INCLUDE_DIR} ${MBEDTLS_INCLUDE_DIR} ${CMAKE_CURRENT_LIST_DIR}) if (WIN32) target_link_libraries(${PROJECT_NAME} wsock32 ws2_32) endif() ``` -------------------------------- ### Build Docker Image for IOWA SDK Lite Source: https://github.com/ioterop/iowa/blob/master/docker/README.md This command builds the `iowa_sdk_lite` Docker image from the Dockerfile located in the current directory. The `--no-cache` flag ensures that the image is built without using any cached layers, and `--tag` assigns a human-readable name to the resulting image. ```Shell docker build --no-cache --tag iowa_sdk_lite . ``` -------------------------------- ### Configure CMake Project and IOWA SDK Path Source: https://github.com/ioterop/iowa/blob/master/samples/08-secure_client_tinydtls/CMakeLists.txt This snippet sets the minimum required CMake version, defines the project name as a C project, and retrieves or sets the global IOWA SDK directory. It also includes a policy setting for newer CMake versions to avoid warnings related to `DOWNLOAD_EXTRACT_TIMESTAMP`. ```CMake cmake_minimum_required(VERSION 3.11) project(secure_client_tinydtls C) get_property(IOWA_DIR GLOBAL PROPERTY iowa_sdk_folder) if (NOT IOWA_DIR) set(IOWA_DIR ${CMAKE_CURRENT_LIST_DIR}/../../iowa) endif() # Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24+: if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0") cmake_policy(SET CMP0135 NEW) endif() ``` -------------------------------- ### Configure LwM2M Client with IOWA Source: https://github.com/ioterop/iowa/blob/master/samples/01-baseline_client/README.md Illustrates the configuration of the LwM2M client using `iowa_client_configure()`. This includes setting a unique endpoint name and optionally providing device information that will be exposed in the LwM2M Device Object (ID: 3). ```c char endpoint_name[64]; iowa_device_info_t devInfo; iowa_status_t result; prv_generate_unique_name(endpoint_name); memset(&devInfo, 0, sizeof(iowa_device_info_t)); devInfo.manufacturer = "https://ioterop.com"; devInfo.deviceType = "IOWA sample from https://github.com/IOTEROP/IOWA"; devInfo.modelNumber = "1-simple_client"; result = iowa_client_configure(iowaH, endpoint_name, &devInfo, NULL); ``` -------------------------------- ### LwM2M Client Main Function Pseudo-Code Source: https://github.com/ioterop/iowa/blob/master/samples/05-custom_object_multiple_instances/README.md This pseudo-code outlines the main function of the LwM2M client, demonstrating the initialization, configuration, custom object addition, server declaration, main loop, dynamic instance creation/deletion, and cleanup steps. It illustrates the flow of a client managing multiple object instances. ```C main() { // Initialization iowa_init(); // LwM2M Client configuration iowa_client_configure(CLIENT_NAME); // Custom Object addition iowa_client_add_custom_object(OBJECT_ID, resourceDescription, instanceIDs, dataCallback); // LwM2M Server declaration iowa_client_add_server(SERVER_SHORT_ID, SERVER_URI, SERVER_LIFETIME); // "Main loop" iowa_step(60s) // Declare third instance iowa_client_object_instance_changed(OBJECT_ID, 5, CREATE); iowa_step(30s) // Declare third instance iowa_client_object_instance_changed(OBJECT_ID, 0, DELETE); iowa_step(30s) // Cleanup iowa_client_remove_custom_object(OBJECT_ID); iowa_client_IPSO_remove_sensor(); iowa_close(); } ``` -------------------------------- ### LwM2M Client Main Function Pseudo Code Source: https://github.com/ioterop/iowa/blob/master/samples/01-baseline_client/README.md Outlines the high-level structure of the LwM2M client's main function, covering initialization, configuration, server declaration, the main processing loop, and final cleanup using IOWA API calls. ```c main() { // Initialization iowa_init(); // LwM2M Client configuration iowa_client_configure(CLIENT_NAME); // LwM2M Server declaration iowa_client_add_server(SERVER_SHORT_ID, SERVER_URI, SERVER_LIFETIME); // "Main loop" iowa_step(120); // Cleanup iowa_client_remove_server(SERVER_SHORT_ID); iowa_close(); } ``` -------------------------------- ### Run IOWA SDK Lite Docker Image Interactively Source: https://github.com/ioterop/iowa/blob/master/docker/README.md This command runs the `iowa_sdk_lite` Docker image, providing an interactive shell session within the container. The `-it` flags are crucial: `-i` keeps STDIN open even if not attached, and `-t` allocates a pseudo-TTY, enabling interactive input and output. ```Shell docker run -it iowa_sdk_lite ``` -------------------------------- ### IOWA LwM2M Client Main Function Pseudo Code Source: https://github.com/ioterop/iowa/blob/master/samples/03-custom_object_baseline/README.md Illustrates the high-level execution flow of the IOWA LwM2M client's main function. It covers the sequence of operations from initialization and configuration to custom object management, server registration, the main processing loop, and final cleanup. ```C main() { // Initialization iowa_init(); // LwM2M Client configuration iowa_client_configure(CLIENT_NAME); // Custom Object addition iowa_client_add_custom_object(OBJECT_ID, resourceDescription, dataCallback); // LwM2M Server declaration iowa_client_add_server(SERVER_SHORT_ID, SERVER_URI, SERVER_LIFETIME); // "Main loop" iowa_step(120s) // Cleanup iowa_client_remove_custom_object(OBJECT_ID); iowa_client_IPSO_remove_sensor(); iowa_close(); } ``` -------------------------------- ### LwM2M Client Main Function Pseudo Code Source: https://github.com/ioterop/iowa/blob/master/samples/04-custom_object_dynamic/README.md This pseudo-code outlines the main function of the LwM2M client, demonstrating initialization, configuration, custom object addition, server declaration, a main loop for dynamic resource updates, and cleanup. It highlights the use of `iowa_step`, `iowa_client_notification_lock`, and `iowa_client_object_resource_changed` for managing resource changes and notifications. ```C main() { // Initialization iowa_init(); // LwM2M Client configuration iowa_client_configure(CLIENT_NAME); // Custom Object addition iowa_client_add_custom_object(OBJECT_ID, resourceDescription, dataCallback); // LwM2M Server declaration iowa_client_add_server(SERVER_SHORT_ID, SERVER_URI, SERVER_LIFETIME); // "Main loop" for (120s) { iowa_step(3); Invert Boolean value Increment Integer value iowa_client_notification_lock(true); iowa_client_object_resource_changed(BOOLEAN_RESOURCE_ID); iowa_client_object_resource_changed(INTEGER_RESOURCE_ID); iowa_client_notification_lock(false); } // Cleanup iowa_client_remove_custom_object(OBJECT_ID); iowa_client_IPSO_remove_sensor(); iowa_close(); } ``` -------------------------------- ### Set Target Include Directories Source: https://github.com/ioterop/iowa/blob/master/samples/03-custom_object_baseline/CMakeLists.txt This snippet specifies the private include directories for the project's executable. It adds the IOWA SDK's include path and the current directory, allowing the compiler to find necessary header files during compilation. ```CMake target_include_directories(${PROJECT_NAME} PRIVATE ${IOWA_INCLUDE_DIR} ${CMAKE_CURRENT_LIST_DIR}) ``` -------------------------------- ### Configure Mbed TLS PSK Credentials Placeholder in C Source: https://github.com/ioterop/iowa/blob/master/samples/07-secure_client_mbedtls3/README.md This C code snippet shows the placeholders for defining Pre-Shared Key (PSK) identity and key within the `sample_env.h` file for Mbed TLS security. Users need to replace the comments with their actual PSK identity string and key byte array. ```C // PSK security credentials #define SAMPLE_PSK_IDENTITY " /*Enter your Pre-Shared Key identity here as String */" #define SAMPLE_PSK_KEY {/*Enter your Pre-Shared Key value here as bytes array*/ } ``` -------------------------------- ### Define LwM2M Server Configuration Parameters in C Source: https://github.com/ioterop/iowa/blob/master/samples/01-baseline_client/README.md This C code snippet defines essential configuration parameters for an LwM2M client, including the device's unique endpoint name, the LwM2M server's URI, its short identifier, and the registration lifetime. These parameters are typically set as preprocessor macros in a header file for easy modification and reuse. ```C #define SAMPLE_ENDPOINT_NAME "prod123456" #define SAMPLE_SERVER_URI "coap://datagram-no-sec-ingress.alaska.ioterop.com" #define SAMPLE_SERVER_SHORT_ID 1234 #define SAMPLE_SERVER_LIFETIME 50 ``` -------------------------------- ### IOWA LwM2M Client Main Function Pseudo Code Source: https://github.com/ioterop/iowa/blob/master/samples/02-IPSO_client/README.md This pseudo code outlines the main execution flow of an IOWA LwM2M client. It demonstrates the typical sequence of operations including initialization, client and server configuration, IPSO Temperature Object management (add, update, remove), and the main loop for periodic sensor value updates. ```C main() { // Initialization iowa_init(); // LwM2M Client configuration iowa_client_configure(CLIENT_NAME); // IPSO Temperature Object enabling iowa_client_IPSO_add_sensor(IOWA_IPSO_TEMPERATURE); // LwM2M Server declaration iowa_client_add_server(SERVER_SHORT_ID, SERVER_URI, SERVER_LIFETIME); // "Main loop" for (120s) { iowa_step(3); iowa_client_IPSO_update_value() } // Cleanup iowa_client_remove_server(SERVER_SHORT_ID); iowa_client_IPSO_remove_sensor(); iowa_close(); } ``` -------------------------------- ### CMake Compilation Flags for Windows Source: https://github.com/ioterop/iowa/blob/master/samples/01-baseline_client/CMakeLists.txt This section sets specific compilation flags for the project when building on Windows. It enables debug information (`/ZI`) and suppresses specific warnings (`/wd4267`, `/wd4334`) for the MSVC compiler. ```CMake if (WIN32) set(CMAKE_C_FLAGS_DEBUG "/ZI") add_definitions("/wd4267 /wd4334") endif() ```