Connecting Embedded Linux Single Board to Feiyan IoT Platform

Hello everyone, I am the Mixed Cuisine Master.

Recently, our device’s cloud platform needs to switch to Alibaba’s Feiyan platform, so I’m making some notes to document the process.

Alibaba has several IoT platforms:

  • IoT Platform
  • Smart Living IoT Platform (Feiyan Platform)
  • Urban IoT Platform

They have different application scenarios. Among them, the entry point for the IoT platform is the easiest to find, and most online demos are based on the IoT platform. However, this note is based on the Smart Living IoT Platform (Feiyan Platform).

Alibaba’s Smart Living IoT Platform is aimed at consumer-grade smart living devices.

Platform entry:

https://www.aliyun.com/product/livinglink?spm=5176.13907935.J_3207526240.46.56603cc7M41In4

Development documentation:

https://help.aliyun.com/document_detail/142147.html?spm=5176.20184507.J_1419255180.2.4c111d2e2IUsMC

Next, we will connect the Feiyan platform step by step using a device based on the embedded Linux single board system.

1. Create Product in the Cloud

1. Function Definition

Define some attributes:

Connecting Embedded Linux Single Board to Feiyan IoT Platform

2. Human-Computer Interaction

Configure the APP, and we will later use the public version APP for testing.

Connecting Embedded Linux Single Board to Feiyan IoT Platform

3. Device Debugging / Adding Device

Connecting Embedded Linux Single Board to Feiyan IoT Platform

4. Product Release

Connecting Embedded Linux Single Board to Feiyan IoT Platform

5. Obtain Device SDK

The device SDK for the Feiyan platform needs to be requested via email. For specific methods, please refer to the documentation. You will obtain:

Connecting Embedded Linux Single Board to Feiyan IoT Platform

2. Port SDK Library to the Board

You can refer to the document “SDK Adaptation Guide Without AliOS Things” to cross-compile the libiot_sdk.a library.

https://help.aliyun.com/document_detail/178333.htm?spm=a2c4g.11186623.0.0.1b046fdbIkFmIT#task-1935127

1. Configure the cross-compiler.

(1) Modify the TOOLCHAIN_DLDIR in the build-rules/settings.mk file. For example, I modified it to:

Connecting Embedded Linux Single Board to Feiyan IoT Platform

(2) Modify the function Relative_TcPath in build-rules/funcs.mk to add the relative path of the compiler. For example, I modified it to:

Connecting Embedded Linux Single Board to Feiyan IoT Platform

(3) Add a config file for our board. In the src/board/ directory, add a new config file, and the content can refer to existing config files. For example, I referred to config.ubuntu.x86 to create my board’s config file config.linux.rv1126:

CONFIG_ENV_CFLAGS   += \
    -Os -Wall \
    -g3 --coverage \
    -D_PLATFORM_IS_LINUX_ \
    -D__UBUNTU_SDK_DEMO__ \

CONFIG_ENV_CFLAGS   += \
    -DWITH_MQTT_DYN_BUF=1 \
    -DWITH_MEM_STATS=0 \
    -DWITH_MEM_STATS_PER_MODULE=0 \
    -DWITH_MQTT_JSON_FLOW=1 \
    -DWITH_MQTT_ZIP_TOPIC=1 \
    -DWITH_MQTT_SUB_SHORTCUT=1

CONFIG_ENV_CFLAGS   += \
    -DCONFIG_HTTP_AUTH_TIMEOUT=10000 \
    -DCONFIG_MID_HTTP_TIMEOUT=10000 \
    -DCONFIG_GUIDER_AUTH_TIMEOUT=10000 \
    -DCONFIG_MQTT_RX_MAXLEN=10000 \
    -DCONFIG_MBEDTLS_DEBUG_LEVEL=0 \
    -DCOMPATIBLE_LK_KV

ifneq (Darwin,$(strip $(shell uname)))
CONFIG_ENV_CFLAGS   += -rdynamic
CONFIG_ENV_CFLAGS   += -Werror
CONFIG_ENV_CFLAGS   += -Wno-missing-braces
else
CONFIG_src/ref-impl/hal :=
CONFIG_examples     :=
CONFIG_src/tools/linkkit_tsl_convert :=
endif

CONFIG_src/ref-impl/tls         :=
CONFIG_src/ref-impl/hal         :=

CONFIG_ENV_LDFLAGS  += -lpthread -lrt

# The prefix of the cross-compiler, do not include the path here
CROSS_PREFIX := arm-linux-gnueabihf-

2. Configure the SDK functions.

We can directly edit the make.settings file in the root directory or execute the make menuconfig command for graphical configuration. For example, I enabled device AP configuration:

Connecting Embedded Linux Single Board to Feiyan IoT Platform

3. Compile the libiot_sdk.a library.

First, execute the make clean command to clean up, then execute make reconfig to select the configuration.

Connecting Embedded Linux Single Board to Feiyan IoT Platform

The board we just added is at configuration number 3, input 3 and then press Enter:

Connecting Embedded Linux Single Board to Feiyan IoT Platform

Then execute the make command to compile, and the result should be without errors:

Connecting Embedded Linux Single Board to Feiyan IoT Platform

If there are no compilation errors, the generated library file libiot_sdk.a will be in the output/release/lib directory.

4. Cross-compile the demo project.

Prepare a project and copy the necessary files from the SDK to our project. For example, I created a folder called ali_smartliving to store the SDK-related code, and the contents of ali_smartliving are:

Connecting Embedded Linux Single Board to Feiyan IoT Platform

The include and src folders are the corresponding folders in the SDK, and the lib folder contains the libiot_sdk.a we obtained from cross-compilation.

Copy the entire folder examples/linkkit/living_platform from the SDK into our project, and then write the CMakeLists.txt file:

cmake_minimum_required(VERSION 3.1)

message(STATUS "######################################")
message(STATUS "Build on target platform: ${TARGET_PLATFORM}")
message(STATUS "######################################")

####################################### Compile Mode Settings #######################################
set(DEBUG_VERSION "DebugMode")
set(RELEASE_VERSION "ReleaseMode")
set(COMPILE_MODE ${RELEASE_VERSION})            # Compile Mode
set(TARGET_NAME "ali_sdk_test")                 # Target Executable Name
string(TIMESTAMP COMPILE_TIME %m%d_%H%M)        # Generate Compile Time

# Debug Mode (Target: Project Name + Compile Time)
if(${COMPILE_MODE} MATCHES ${DEBUG_VERSION})   
    message(STATUS "Compile mode: ${COMPILE_MODE}")
    set(USE_RELEASE_MODE 0)
    set(CMAKE_BUILD_TYPE "Debug")
    set(target ${TARGET_NAME}_${COMPILE_TIME})
# Release Mode (Target: Project Name + Version Number)
else()
    message(STATUS "Compile mode: ${COMPILE_MODE}")
    set(USE_RELEASE_MODE 1)
    set(CMAKE_BUILD_TYPE "Release") 
    set(VERSION_MAJOR  1)    # Major Version Number
    set(VERSION_MINOR  0)    # Minor Version Number
    set(VERSION_LEVEL3 0)    # Patch Version Number
    set(target ${TARGET_NAME}_V${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_LEVEL3})
endif()
project(${target})

####################################### Compile Options Configuration #######################################
set(TARGET_PLATFORM "x86-64" CACHE STRING "which platform the source code should be compiled on")
message(STATUS "Build on target platform: ${TARGET_PLATFORM}")
if(TARGET_PLATFORM MATCHES "rv1126")
    include(cmake/rv1126_crosscompile_toolchain.cmake)  # Cross-compile Environment Settings
elseif(TARGET_PALTFORM MATCHES "x86-64")
    message(STATUS "PC_DEBUG: ${PC_DEBUG}")
endif()
set(CMAKE_CXX_FLAGS "-std=c++11")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall")  #-g for debug
set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-Map=out.map")
if(TARGET_PLATFORM MATCHES "rv1126")
set(CMAKE_C_FLAGS "-fdata-sections -g -rdynamic -mapcs-frame -funwind-tables -ffunction-sections -Wall -Os")
set(CMAKE_C_FLAGS "$ENV{CMAKE_C_FLAGS} -DDLL_HAL_EXPORTS -DCOMPATIBLE_LK_KV -lrt")
elseif(TARGET_PALTFORM MATCHES "x86-64")
set(CMAKE_C_FLAGS "-fdata-sections -g -rdynamic -mapcs-frame -funwind-tables -ffunction-sections -Wall -Os")
set(CMAKE_C_FLAGS "$ENV{CMAKE_C_FLAGS} -DDLL_HAL_EXPORTS -DCOMPATIBLE_LK_KV -lrt")
endif()
set(CMAKE_CXX_FLAGS "-fdata-sections -Wno-psabi") 

####################################### Shared Libraries ############################################
set(ALI_IOT_LIBDIR ali_smartliving/lib)
link_directories(${ALI_IOT_LIBDIR})
set(ALI_IOT_LIBS libiot_sdk.a)

add_definitions (-DDLL_IOT_EXPORTS)

add_definitions (-DAWSS_DISABLE_ENROLLEE)
add_definitions (-DAWSS_DISABLE_REGISTRAR)
add_definitions (-DAWSS_SUPPORT_ADHA)
add_definitions (-DAWSS_SUPPORT_AHA)
add_definitions (-DAWSS_SUPPORT_APLIST)
add_definitions (-DAWSS_SUPPORT_DEV_AP)
add_definitions (-DAWSS_SUPPORT_PHONEASAP)
add_definitions (-DAWSS_SUPPORT_ROUTER)
add_definitions (-DAWSS_SUPPORT_SMARTCONFIG)
add_definitions (-DAWSS_SUPPORT_SMARTCONFIG_WPS)
add_definitions (-DAWSS_SUPPORT_ZEROCONFIG)
add_definitions (-DCOAP_SERV_MULTITHREAD)
add_definitions (-DCONFIG_HTTP_AUTH_TIMEOUT=5000)
add_definitions (-DCONFIG_MID_HTTP_TIMEOUT=5000)
add_definitions (-DCONFIG_GUIDER_AUTH_TIMEOUT=10000)
add_definitions (-DDEVICE_MODEL_ENABLED)
add_definitions (-DDEV_BIND_ENABLED)
add_definitions (-DFORCE_SSL_VERIFY)
add_definitions (-DMQTT_COMM_ENABLED)
add_definitions (-DMQTT_DIRECT)
add_definitions (-DOTA_ENABLED)
add_definitions (-DOTA_SIGNAL_CHANNEL=1)
add_definitions (-DSUPPORT_TLS)
add_definitions (-DWIFI_PROVISION_ENABLED)
add_definitions (-D_PLATFORM_IS_HOST_)

include_directories(build)
include_directories(ali_smartliving)
include_directories(ali_smartliving/include)
include_directories(ali_smartliving/include/exports)
include_directories(ali_smartliving/include/imports)
include_directories(ali_smartliving/linkkit/living_platform)
include_directories(ali_smartliving/src/ref-impl/hal)
include_directories(ali_smartliving/src/ref-impl/hal/os/ubuntu)
include_directories(ali_smartliving/src/infra/log)
include_directories(ali_smartliving/src/ref-impl/tls/include)
include_directories(ali_smartliving/src/infra/utils/digest)
include_directories(living_platform)

####################################### Source Files ############################################
aux_source_directory(living_platform living_platform_src)
file(GLOB hal_srcs ${PROJECT_SOURCE_DIR}/ali_smartliving/src/ref-impl/hal/os/ubuntu/*.c)
file(GLOB ssl_mbedtls_srcs ${PROJECT_SOURCE_DIR}/ali_smartliving/src/ref-impl/hal/ssl/mbedtls/*.c)
file(GLOB tls_srcs ${PROJECT_SOURCE_DIR}/ali_smartliving/src/ref-impl/tls/library/*.c)

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

message(STATUS "################## Compile timeļ¼š${COMPILE_TIME} ##################")

add_executable(${PROJECT_NAME}
        ${living_platform_src}
        ${hal_srcs}
        ${ssl_mbedtls_srcs}
        ${tls_srcs}
        main.c
        )
target_link_libraries(${PROJECT_NAME}
        ${ALI_IOT_LIBS}
        Threads::Threads
        m
        )

The structure of our project is as follows:

Connecting Embedded Linux Single Board to Feiyan IoT Platform

You can get our demo project by replying with the specific keyword at the end of this article.

Note:

When you port and compile the project yourself, you may encounter the following two issues:

(1) Many system functions cannot be found; you can add the compilation parameter -lrt.

(2) The function softap_decrypt_password cannot be found. This function is in the libawss_security.a library, which we have not cross-compiled. The demo’s documentation also mentions:

Connecting Embedded Linux Single Board to Feiyan IoT Platform

We don’t need it for now, and you can also comment out the places in the SDK that call this function, such as:

Connecting Embedded Linux Single Board to Feiyan IoT Platform

At this point, the project should compile without any major issues. Now, let’s start connecting to the cloud.

5. Device Connection to the Cloud

First, test the device connection to the cloud. You need to write the device certificate into the code.

Cloud device certificate:

Connecting Embedded Linux Single Board to Feiyan IoT Platform

You need to modify the following macro definitions in the living_platform_ut.h file:

Connecting Embedded Linux Single Board to Feiyan IoT Platform

When modifying, you need to remove the prefixes PK_, PS_, DN_, DS_.

Modification example:

Connecting Embedded Linux Single Board to Feiyan IoT Platform

Run the test, and if there are no errors, the cloud device will show online:

Connecting Embedded Linux Single Board to Feiyan IoT Platform
Connecting Embedded Linux Single Board to Feiyan IoT Platform

You can debug the device online:

Connecting Embedded Linux Single Board to Feiyan IoT Platform
Connecting Embedded Linux Single Board to Feiyan IoT Platform

Demo Acquisition

You can obtain the demo of this note by replying with the keyword: Feiyan Platform Initial Experience in the background of this public account.

That’s all for sharing the example of connecting an embedded Linux single board system to the Feiyan platform. In the next article, we will share network configuration based on the Feiyan platform.

Note

Due to recent changes in the WeChat public account push rules, to prevent missing articles, you can star and pin this account so that the articles pushed will appear in your subscription list.

Recommended Articles:

Sharing a Highly Flexible Protocol Format (with Code Example)

Embedded Mixed Cuisine Weekly | Issue 16

Embedded Mixed Cuisine Weekly | Issue 15

Why Accessing Invalid Memory Doesn’t Cause Errors?

Embedded Mixed Cuisine Weekly | Issue 14

Sharing Several Practical Code Snippets (Part Two)

Sharing a Bug Locating Method You Might Not Know

Sharing a Method to Modify Configuration Files

Embedded Mixed Cuisine Weekly Issue 13: lz4

Understanding Embedded Parallel Multithreaded Processors!

Sharing a Method to Modify Configuration Files

Sharing Several Practical Code Snippets (with Code Examples)

Reusing Old Boards: Building a Wireless Debugging Environment!

Summary of 3 Debugging Methods for Embedded Segmentation Faults!

Briefly Discussing Non-blocking Reception in TCP Communication (with Code Example)

Encapsulating Common Interfaces in TCP Communication

How to Handle Time Issues in Internationalized Embedded Code?

The Universal Unzip Command in Linux Command Line

Common Pitfalls of Bus Errors in Embedded Software!

Sharing Embedded Software Debugging Methods and Useful Tools!

Two Suggestions to Improve Programming Skills!

Reply 1024 in the public account chat interface to get embedded resources; reply m to view article summaries.

Leave a Comment