本文分享自华为云社区《DAYU200+OpenHarmony 3.1.1对接华为云IOT【华为云IoT+鸿蒙】》,作者:DS小龙哥。
OpenHarmony 3.1.1 是一个开源的智能终端操作系统,主要用于智能家居、智能手机、平板电脑、智能穿戴设备等智能终端设备。是一个分布式操作系统,支持多种硬件平台和多种编程语言,可以方便地进行移植和定制。
特点:
(1) 分布式:支持分布式计算和分布式存储,可以在多个设备之间进行任务调度和数据共享。
(2)可裁剪:支持根据设备的需求进行裁剪,以满足不同设备的资源限制。
(3)安全:提供了安全机制,保护设备的隐私和安全。
(4)可移植:支持多种硬件平台和多种编程语言,可以方便地进行移植和定制。
当前文章介绍在DAYU200开发板上烧写OpenHarmony系统,利用huaweicloud-iot-device-sdk
完成华为云IOT平台对接,完成物联网数据通信。
所需硬件:DAYU200开发板(RK3568)
关于开发板的介绍在这里:https://gitee.com/hihope_iot/docs/tree/master/HiHope_DAYU200
基于Rockchip RK3568,集成双核心架构GPU以及高效能NPU; 板载四核64位Cortex-A55 处理器采用22nm先进工艺,主频高达2.0GHz; 支持蓝牙、Wi-Fi、音频、视频和摄像头等功能,拥有丰富的扩展接口,支持多种视频输入输出接口; 配置双千兆自适应RJ45以太网口,可满足NVR、工业网关等多网口产品需求。
开发板插上串口线之后,打开设备管理器可以看到识别到串口COM8
,这就是开发板的Debug串口。(需要提前安装好USB转串口驱动)。
打开串口工具,新建会话,选择串口协议。
波特率选择1500000
也就是1.5M。
创建完成。
选择刚才创建好的会话,点击连接。
复位开发板(开发板上有一个RESET按钮),正常情况下会在终端上看到内核启动过程;启动完成后按下回车即可进入到Linux终端命令行。
从打印的命令行数据可以看出当前设备的配置:
这是uboot打印出来的配置信息。从当前信息里可以看出CPU型号RK3568,内存2GB。
U-Boot 2017.09-gb448fedf55-211210 #addy (Dec 20 2021 - 10:58:09 +0800) Model: Rockchip RK3568 Evaluation Board PreSerial: 2, raw, 0xfe660000 DRAM: 2 GiB Sysmem: init Relocation Offset: 7d34d000 Relocation fdt: 7b9f87e8 - 7b9fecd0 CR: M/C/I Using default environment
内核启动打印的信息;从信息里可以看出当前系统使用的内核是Linux 5.10内核。
Starting kernel ... [ 0.000000] Booting Linux on physical CPU 0x0000000000 [0x412fd050] [ 0.000000] Linux version 5.10.79 (root@ecs-58f4) (aarch64-linux-gnu-gcc (Linaro GCC 7.5-2019.12) 7.5.0, GNU ld (Linaro_Binutils-2019.12) 2.28.2.20170706) #1 SMP Thu Jun 29 09:39:49 CST 2023 [ 0.000000] Machine model: rockchip,rk3568-toybrick-dev-linux-x0 [ 0.000000] earlycon: uart8250 at MMIO32 0x00000000fe660000 (options '') [ 0.000000] printk: bootconsole [uart8250] enabled [ 0.000000] Zone ranges: [ 0.000000] DMA [mem 0x0000000000200000-0x000000007fffffff] [ 0.000000] DMA32 empty [ 0.000000] Normal empty [ 0.000000] Movable zone start for each node [ 0.000000] Early memory node ranges
在串口软件上可以设置终端类型,方便区分Linux终端文件类型。
下来下来之后打开HiHope_DAYU200
文件夹。
我这里在windows下进行烧写。
在DriverAssitant_v5.1.1.zip
目录下是USB驱动,解压后进行安装。如果已经安装旧版本的烧写工具, 需要先点击“驱动卸载” 按钮下载驱动, 然后再点击“驱动安装” 按钮安装驱动。
RKDevTool.exe
就是烧写工具。
地址:https://gitee.com/hihope_iot/images/tree/master/HiHope_DAYU200
下载下来解压,打开烧写工具选择路径。
确认开发板是否进入烧写模式
(1)如果界面显示"发现一个 LOADER 设备", 说明开发板进入 Loader 模式等待烧写固件。
(2)如果界面显示"发现一个 MASKROM 设备", 说明开发板进入 Maskrom 模式等待烧写固 件。
(3)如果界面显示"没有发现设备", 说明开发板没有进入烧写模式, 需要先让开发板进入烧写模式
进入烧写模式的步骤
(1)先按住 VOL-/RECOVERY 按键 和 RESET 按钮不松开, 烧录工具此时显示“没有发现设备”
(2)然后再 松开 RESER 键, 烧录工具显示“发现一个 LOADER 设备” , 说明此时已经进入烧写模式。
说明文档:https://gitee.com/openharmony-sig/iot_device_sdk_c/blob/master/README_CN.md#5
Huawei Cloud IOT Device SDK for C 是华为云推出的一套面向嵌入式设备的物联网开发套件,支持 C 语言开发。该套件提供了一系列 API,可以方便地实现设备与云端的连接、数据上报、远程控制等功能。
该套件主要包括以下组件:
使用 Huawei Cloud IOT Device SDK for C 可以大大简化物联网设备的开发流程,提高开发效率,同时也可以保证设备与云端之间的连接稳定性和安全性。该套件适用于各种类型的嵌入式设备,例如智能家居、智能家电、智能穿戴等。
Huawei Cloud IOT SDK for C SDK面向运算、存储能力较强的嵌入式终端设备,开发者通过调用SDK接口,便可实现设备与物联网平台的上下行通讯。SDK当前支持的功能有:
华为云物联网平台(IoT 设备接入云服务)提供海量设备的接入和管理能力,将物理设备联接到云,支撑设备数据采集上云和云端下发命令给设备进行远程控制,配合华为云其他产品,帮助我们快速构筑物联网解决方案。
使用物联网平台构建一个完整的物联网解决方案主要包括3部分:物联网平台、业务应用和设备。
物联网平台作为连接业务应用和设备的中间层,屏蔽了各种复杂的设备接口,实现设备的快速接入;同时提供强大的开放能力,支撑行业用户构建各种物联网解决方案。
设备可以通过固网、2G/3G/4G/5G、NB-IoT、Wifi等多种网络接入物联网平台,并使用LWM2M/CoAP、MQTT、HTTPS协议将业务数据上报到平台,平台也可以将控制命令下发给设备。
业务应用通过调用物联网平台提供的API,实现设备数据采集、命令下发、设备管理等业务场景。
地址: https://www.huaweicloud.com/product/iothub.html
点击总览
,查看接入信息。 我们当前设备准备采用MQTT协议接入华为云平台,这里可以看到MQTT协议的地址和端口号等信息。
总结:
端口号: MQTT (1883)| MQTTS (8883) 接入地址: a161a58a78.iot-mqtts.cn-north-4.myhuaweicloud.com
根据域名地址得到IP地址信息:
Microsoft Windows [版本 10.0.19045.2965] (c) Microsoft Corporation。保留所有权利。 C:\Users\11266>ping a161a58a78.iot-mqtts.cn-north-4.myhuaweicloud.com 正在 Ping a161a58a78.iot-mqtts.cn-north-4.myhuaweicloud.com [121.36.42.100] 具有 32 字节的数据: 来自 121.36.42.100 的回复: 字节=32 时间=38ms TTL=94 来自 121.36.42.100 的回复: 字节=32 时间=37ms TTL=94 来自 121.36.42.100 的回复: 字节=32 时间=38ms TTL=94 来自 121.36.42.100 的回复: 字节=32 时间=36ms TTL=94 121.36.42.100 的 Ping 统计信息: 数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失), 往返行程的估计时间(以毫秒为单位): 最短 = 36ms,最长 = 38ms,平均 = 37ms C:\Users\11266>
MQTT协议接入端口号有两个,1883是非加密端口,8883是证书加密端口,单片机无法加载证书,所以使用1883端口比较合适。 接下来的ESP8266就采用1883端口连接华为云物联网平台。
点击产品页,再点击左上角创建产品。
根据自己产品名字填写。
产品创建完成之后,点击进入产品详情页面,翻到最下面可以看到模型定义。
这个模型就是定义自己设备接下来需要向服务器上传那些数据类型。根据自己的数据类型进行编写。
先点击自定义模型。
再创建一个服务ID。
接着点击新增属性。
产品是属于上层的抽象模型,接下来在产品模型下添加实际的设备。添加的设备最终需要与真实的设备关联在一起,完成数据交互。
创建完毕之后,点击保存并关闭,得到创建的设备密匙信息。该信息在后续生成MQTT三元组的时候需要使用。
可以点击设备进入到设备详情页面。
在文件Harmony源码路径/build/subsystem_config.json中添加构建脚本:
"iot-device-sdk-c" : { "path": "third_party/iot-device-sdk-c", "name": "iot-device-sdk-c" },
在文件OpenHarmony源码路径/build/subsystem_config.json中添加如下构建脚本:
"iot-device-sdk-c" : { "path": "third_party/iot-device-sdk-c", "name": "iot-device-sdk-c" },
在产品配置文件中添加子系统,其子系统名称与文件中添加内容对应,就是iot-device-sdk-c:iot-device-sdk-c
。
配置文件位于`MY_OHOS_
此sdk主要依赖于libboundscheck.so
,libpaho-mqtt3as.so
,libssh.so
,libnopoll.so
这些动态库,其间接依赖于libz.so
,libssl.so
, libcrypto.so
。
对于libboundscheck.so
,libpaho-mqtt3as.so
,libssh.so
,libnopoll.so
, 这些库对应的源码没有在OpenHarmony中集成,如果开发板中没有这些动态库,需要自行下载并编译。
执行以下命令拉取对应源码:
cd $MY_OHOS_DIR/third_party/iot_device_sdk_c mkdir third_party cd third_party git clone https://gitee.com/Janisa/huawei_secure_c.git \ && git clone -b v1.3.12 --single-branch https://github.com/eclipse/paho.mqtt.c.git \ && git clone -b libssh-0.9.6 --single-branch https://git.libssh.org/projects/libssh.git \ && git clone -b 0.4.8 --single-branch https://github.com/ASPLes/nopoll.git \
分别在OpenHarmony源码路径/third_party/iot_device_sdk_c/third_party/huawei_secure_c,OpenHarmony源码路径/third_party/iot_device_sdk_c/third_party/paho.mqtt.c, OpenHarmony源码路径/third_party/iot_device_sdk_c/third_party/libssh, OpenHarmony源码路径/third_party/iot_device_sdk_c/third_party/nopoll文件夹中放入或替换BUILD.gn文件,
内容如下:
# 放入 $MY_OHOS_DIR/third_party/iot_device_sdk_c/third_party/huawei_secure_c # # Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. # # OpenArkCompiler is licensed under the Mulan PSL v1. # You can use this software according to the terms and conditions of the Mulan PSL v1. # You may obtain a copy of Mulan PSL v1 at: # # http://license.coscl.org.cn/MulanPSL # # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR # FIT FOR A PARTICULAR PURPOSE. # See the Mulan PSL v1 for more details. # import("//build/ohos.gni") src_libHWSecureC = [ "src/vsprintf_s.c", "src/wmemmove_s.c", "src/strncat_s.c", "src/vsnprintf_s.c", "src/fwscanf_s.c", "src/scanf_s.c", "src/strcat_s.c", "src/sscanf_s.c", "src/secureprintoutput_w.c", "src/wmemcpy_s.c", "src/wcsncat_s.c", "src/secureprintoutput_a.c", "src/secureinput_w.c", "src/memcpy_s.c", "src/fscanf_s.c", "src/vswscanf_s.c", "src/secureinput_a.c", "src/sprintf_s.c", "src/memmove_s.c", "src/swscanf_s.c", "src/snprintf_s.c", "src/vscanf_s.c", "src/vswprintf_s.c", "src/wcscpy_s.c", "src/vfwscanf_s.c", "src/memset_s.c", "src/wscanf_s.c", "src/vwscanf_s.c", "src/strtok_s.c", "src/wcsncpy_s.c", "src/vfscanf_s.c", "src/vsscanf_s.c", "src/wcstok_s.c", "src/securecutil.c", "src/gets_s.c", "src/swprintf_s.c", "src/strcpy_s.c", "src/wcscat_s.c", "src/strncpy_s.c", ] include_common = [ "include", "src", ] ohos_static_library("libHWSecureC") { sources = src_libHWSecureC include_dirs = include_common } ohos_shared_library("libboundscheck") { sources = src_libHWSecureC include_dirs = include_common } # 放入 $MY_OHOS_DIR/third_party/iot_device_sdk_c/third_party/paho.mqtt.c # # Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. # # OpenArkCompiler is licensed under the Mulan PSL v1. # You can use this software according to the terms and conditions of the Mulan PSL v1. # You may obtain a copy of Mulan PSL v1 at: # # http://license.coscl.org.cn/MulanPSL # # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR # FIT FOR A PARTICULAR PURPOSE. # See the Mulan PSL v1 for more details. # import("//build/ohos.gni") MQTT_SRC_DIR = "src" MQTT_AS_SOURCE_FILES = [ "${MQTT_SRC_DIR}/Base64.c", "${MQTT_SRC_DIR}/Clients.c", "${MQTT_SRC_DIR}/Heap.c", "${MQTT_SRC_DIR}/LinkedList.c", "${MQTT_SRC_DIR}/Log.c", "${MQTT_SRC_DIR}/Messages.c", "${MQTT_SRC_DIR}/MQTTAsync.c", "${MQTT_SRC_DIR}/MQTTAsyncUtils.c", "${MQTT_SRC_DIR}/MQTTPacket.c", "${MQTT_SRC_DIR}/MQTTPacketOut.c", "${MQTT_SRC_DIR}/MQTTPersistence.c", "${MQTT_SRC_DIR}/MQTTPersistenceDefault.c", "${MQTT_SRC_DIR}/MQTTProperties.c", "${MQTT_SRC_DIR}/MQTTProtocolClient.c", "${MQTT_SRC_DIR}/MQTTProtocolOut.c", "${MQTT_SRC_DIR}/MQTTReasonCodes.c", "${MQTT_SRC_DIR}/MQTTTime.c", "${MQTT_SRC_DIR}/OsWrapper.c", "${MQTT_SRC_DIR}/Proxy.c", "${MQTT_SRC_DIR}/SHA1.c", "${MQTT_SRC_DIR}/Socket.c", "${MQTT_SRC_DIR}/SocketBuffer.c", "${MQTT_SRC_DIR}/SSLSocket.c", "${MQTT_SRC_DIR}/StackTrace.c", "${MQTT_SRC_DIR}/Thread.c", "${MQTT_SRC_DIR}/Tree.c", "${MQTT_SRC_DIR}/utf-8.c", "${MQTT_SRC_DIR}/WebSocket.c", ] ohos_shared_library("libpaho-mqtt3as") { sources = MQTT_AS_SOURCE_FILES include_dirs = ["./src", "./build"] deps=[ "//third_party/openssl:libcrypto_static", "//third_party/openssl:ssl_source" ] cflags = ["-w", "-fPIC", "-Os", "-fvisibility=hidden", "-DOPENSSL", "-D_GNU_SOURCE", "-DPAHO_MQTT_EXPORTS=1"] libs= ["pthread", "dl"] ldflags = ["-Wl,-init,MQTTAsync_init"] } # 放入 $MY_OHOS_DIR/third_party/iot_device_sdk_c/third_party/libssh # # Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. # # OpenArkCompiler is licensed under the Mulan PSL v1. # You can use this software according to the terms and conditions of the Mulan PSL v1. # You may obtain a copy of Mulan PSL v1 at: # # http://license.coscl.org.cn/MulanPSL # # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR # FIT FOR A PARTICULAR PURPOSE. # See the Mulan PSL v1 for more details. # import("//build/ohos.gni") src_libHWSecureC = [ "src/agent.c", "src/auth.c", "src/base64.c", "src/bignum.c", "src/buffer.c", "src/callbacks.c", "src/channels.c", "src/client.c", "src/config.c", "src/connect.c", "src/connector.c", "src/curve25519.c", "src/dh.c", "src/ecdh.c", "src/error.c", "src/getpass.c", "src/init.c", "src/kdf.c", "src/kex.c", "src/known_hosts.c", "src/knownhosts.c", "src/legacy.c", "src/log.c", "src/match.c", "src/messages.c", "src/misc.c", "src/options.c", "src/packet.c", "src/packet_cb.c", "src/packet_crypt.c", "src/pcap.c", "src/pki.c", "src/pki_container_openssh.c", "src/poll.c", "src/session.c", "src/scp.c", "src/socket.c", "src/string.c", "src/threads.c", "src/wrapper.c", "src/external/bcrypt_pbkdf.c", "src/external/blowfish.c", "src/external/chacha.c", "src/external/poly1305.c", "src/chachapoly.c", "src/config_parser.c", "src/token.c", "src/pki_ed25519_common.c", "src/threads/noop.c", "src/threads/pthread.c", "src/threads/libcrypto.c", "src/pki_crypto.c", "src/ecdh_crypto.c", "src/libcrypto.c", "src/dh_crypto.c", "src/pki_ed25519.c", "src/external/ed25519.c", "src/external/fe25519.c", "src/external/ge25519.c", "src/external/sc25519.c", "src/sftp.c", "src/sftpserver.c", "src/server.c", "src/bind.c", "src/bind_config.c", "src/dh-gex.c", "src/external/curve25519_ref.c", ] include_common = [ "./build", "./include/", "//third_party/openssl/include", "./include/libssh", "./build/include", "./build/src", ] ohos_shared_library("libssh") { sources = src_libHWSecureC include_dirs = include_common deps=[ "//third_party/openssl:libcrypto_static", "//third_party/openssl:ssl_source" ] cflags = ["-w", "-std=gnu99", "-fPIC", "-DLIBSSH_EXPORTS", "-D_GNU_SOURCE"] } # 放入 $MY_OHOS_DIR/third_party/iot_device_sdk_c/third_party/nopoll # # Copyright (c) [2020] Huawei Technologies Co.,Ltd.All rights reserved. # # OpenArkCompiler is licensed under the Mulan PSL v1. # You can use this software according to the terms and conditions of the Mulan PSL v1. # You may obtain a copy of Mulan PSL v1 at: # # http://license.coscl.org.cn/MulanPSL # # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR # FIT FOR A PARTICULAR PURPOSE. # See the Mulan PSL v1 for more details. # import("//build/ohos.gni") src_nopoll = [ "src/nopoll.c", "src/nopoll_conn.c", "src/nopoll_conn_opts.c", "src/nopoll_ctx.c", "src/nopoll_decl.c", "src/nopoll_io.c", "src/nopoll_listener.c", "src/nopoll_log.c", "src/nopoll_loop.c", "src/nopoll_msg.c", "src/nopoll_win32.c", ] include_common = [ "include", "../../include/", "src", ] ohos_shared_library("libnopoll") { sources = src_nopoll include_dirs = include_common deps=[ "//third_party/openssl:libcrypto_static", "//third_party/openssl:ssl_source" ] cflags = ["-w"] }
由于libssh需要cmake生成一些包含各种配置的头文件,所以此处先用cmake命令生成中间文件。
此处需要根据开发板支持的功能向cmake传入参数,以便开启或关闭对应特性,如示例中的
-DHAVED_GLOB=0
命令如下:
cd $MY_OHOS_DIR/third_party/iot_device_sdk_c/third_party/libssh \ && mkdir -p build \ && cd build \ && cmake .. \ -DCMAKE_BUILD_TYPE=Release -DWITH_ZLIB=OFF \ -DOPENSSL_ROOT_DIR=$MY_OHOS_DIR/third_party/openssl \ -DOPENSSL_INCLUDE_DIR=$MY_OHOS_DIR/third_party/openssl/include \ -DOPENSSL_CRYPTO_LIBRARY=$MY_OHOS_DIR/out/rk3568/packages/phone/system/lib/libcrypto.z.so \ -DHAVE_STRTOULL=1 -DUNIX=1 -DHAVE_POLL=0 -DHAVE_GLOB=0 \ -DHAVE_OPENSSL_CRYPTO_CTR128_ENCRYPT=1
paho.mqtt.c需要用make生成VersionInfo.h
,执行如下命令生成:
cd $MY_OHOS_DIR/third_party/iot_device_sdk_c/third_party/paho.mqtt.c
make build/VersionInfo.h
nopoll需要对应的OpenHarmony源码路径/third_party/iot_device_sdk_c/third_party/nopoll/src/nopoll_config.h:
/* * Nopoll Library nopoll_config.h * Platform dependant definitions. * * This is a generated file. Please modify 'configure.in' */ #ifndef __NOPOLL_CONFIG_H__ #define __NOPOLL_CONFIG_H__ /** * \addtogroup nopoll_decl_module * @{ */ /** * @brief Allows to convert integer value (including constant values) * into a pointer representation. * * Use the oposite function to restore the value from a pointer to a * integer: \ref PTR_TO_INT. * * @param integer The integer value to cast to pointer. * * @return A \ref noPollPtr reference. */ #ifndef INT_TO_PTR #define INT_TO_PTR(integer) ((noPollPtr) (long) ((int)integer)) #endif /** * @brief Allows to convert a pointer reference (\ref noPollPtr), * which stores an integer that was stored using \ref INT_TO_PTR. * * Use the oposite function to restore the pointer value stored in the * integer value. * * @param ptr The pointer to cast to a integer value. * * @return A int value. */ #ifndef PTR_TO_INT #define PTR_TO_INT(ptr) ((int) (long) (ptr)) #endif /** * @brief Allows to get current platform configuration. This is used * by Nopoll library but could be used by applications built on top of * Nopoll to change its configuration based on the platform information. */ #define NOPOLL_OS_UNIX (1) /** * @internal Allows to now if the platform support vasprintf * function. Do not use this macro as it is supposed to be for * internal use. */ #define NOPOLL_HAVE_VASPRINTF (1) /** * @brief Indicates that this platform have support for 64bits. */ #define NOPOLL_64BIT_PLATFORM (1) /** * @brief Indicates where we have support for TLSv1.0 support. */ #define NOPOLL_HAVE_TLSv10_ENABLED (1) /** * @brief Indicates where we have support for TLSv1.1 support. */ #define NOPOLL_HAVE_TLSv11_ENABLED (1) /** * @brief Indicates where we have support for TLSv1.2 support. */ #define NOPOLL_HAVE_TLSv12_ENABLED (1) /** * @brief Indicates where we have support for TLS flexible method where the highest TLS version will be negotiated. */ #define NOPOLL_HAVE_TLS_FLEXIBLE_ENABLED (1) /* @} */ #endif
最后修改文件OpenHarmony源码路径/third_party/iot_device_sdk_c/BUILD.gn,在executable("mqtt_device_demo")的deps中加入以下依赖:
"third_party/huawei_secure_c:libboundscheck", "third_party/paho.mqtt.c:libpaho-mqtt3as", "third_party/libssh:libssh", "third_party/nopoll:libnopoll",
结果如图所示:
libz.so和libssl.so对应的源码在拉取OpenHarmony时会自获取,其分别对应OpenHarmony源码路径/third_party/libz,则属于OpenHarmony源码路径/third_party/openssl。 这些库在编译libboundscheck.so等动态库时会以依赖的方式来驱使其编译,所以只需要将对应的产物拷贝到目标设备中。
部分产物位于OpenHarmony源码路径/out/{产品型号}/common/common/目录下,部分则位于特殊的位置。这些动态库通常.z.so结尾。以rk3568为例,其`libssh.so和libz.so分别处于:
$MY_OHOS_DIR/out/rk3568/common/common/libz.z.so $MY_OHOS_DIR/out/rk3568/packages/phone/system/lib/libssl.z.so
对于示例开发板rk3861
,其内部已经存在这些动态库,所以示例中无需拷贝这些库。如果目标设备缺少这些库,可以使用以下命令来查找动态库位置:
find $MY_OHOS_DIR/out -name {动态库名称}.z.so find $MY_OHOS_DIR/out -name {动态库名称}.so
打开OpenHarmony源码路径/third_party/iot_device_sdk_c/src/device_demo/device_demo.c,修改接入地址,设备id和设备密钥,如下图所示:
最后执行编译:
cd $OpenHarmony源码路径
./build.sh --product-name 使用的产品 --build-target iot_device_sdk_c
输出如下内容则表示编译成功;
将需要的动态库和主程序./MQTT_Demo拷贝到目标设备的同一路径下,执行export LD_LIBRARY_PATH=. && ./MQTT_Demo,出现MqttBase_OnConnectSuccess则表示成功连接华为云: