<acronym id="s8ci2"><small id="s8ci2"></small></acronym>
<rt id="s8ci2"></rt><rt id="s8ci2"><optgroup id="s8ci2"></optgroup></rt>
<acronym id="s8ci2"></acronym>
<acronym id="s8ci2"><center id="s8ci2"></center></acronym>
0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

OpenHarmony鴻蒙南向開發案例:【智能門鈴】

jf_46214456 ? 來源:jf_46214456 ? 作者:jf_46214456 ? 2024-04-19 15:35 ? 次閱讀

樣例簡介

智能門鈴通過監控來訪者信息,告訴主人門外是否有人按鈴、有陌生人靠近或者無人狀態。主人可以在數字管家中遠程接收消息,并根據需要進行遠程取消報警和一鍵開鎖。同時,也可以通過室內屏幕獲取門外狀態。室內屏幕顯示界面使用DevEco Studio 編寫的js應用,具有很好的兼容和移植特性。硬件上采用了帶有HDF框架的驅動模型,通過GPIO來獲取傳感器采集信息并驅動報警器進行動作。

image-20211228172423071

運行效果

image-20220402103912059

樣例原理

如上圖所示,智能門鈴整體方案原理圖可以大致分成:智能門鈴設備、數字管家應用、云平臺三部分。智能門鈴通過MQTT協議連接華為IOT物聯網平臺,從而實現命令的接收和屬性上報。 。

工程版本

  • 系統版本/API版本:OpenHarmony 3.1 Beta
  • hb版本:0.4.4
  • 工具鏈版本:gcc-arm-none-eabi-10.3-2021.10
  • 鴻蒙開發指導文檔:[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md]

快速上手

準備硬件環境

  • 歐智通V200Z-R開發板
  • 潤和智能家居套件-紅綠燈板
  • 潤和智能家居套件-炫彩燈板
  • 預裝HarmonyOS手機一臺
    注:HarmonyOS是華為基于開源項目OpenHarmony開發的面向多種全場景智能設備的商用版本

準備開發環境

搜狗高速瀏覽器截圖20240326151547.png

安裝必備軟件

開發基礎環境由 windows 工作臺和 Linux 編譯服務器組成。windows 工作臺可以通過 samba 服務或 ssh 方式訪問 Linux編譯服務器。其中 windows 工作臺用來燒錄和代碼編輯,Linux 編譯服務器用來編譯 OpenHarmony 代碼,為了簡化步驟,Linux 編譯服務器推薦安裝 Ubuntu20.04。

安裝編譯依賴基礎軟件
sudo apt-get install -y build-essential gcc g++ make zlib* libffi-dev git git-lfs
安裝和配置Python
  • 打開Linux終端。
  • 輸入如下命令,查看python版本號,需要使用python3.7以上版本。
python3 --version
  • 安裝并升級Python包管理工具(pip3)。
sudo apt-get install python3-setuptools python3-pip -y
sudo pip3 install --upgrade pip
  • 設置pip的國內鏡像
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple requests
安裝hb
  • 輸入如下命令確認hb是否為version 0.4.4
hb -v

a. 若提示如下內容,則表示未安裝可以從第2步開始操作。

bash: /home/***/.local/bin/hb: No such file or directory

b.若提示如下內容,需要先卸載該版本,然后再執行第2步操作步驟。

[OHOS INFO] hb version 0.4.3

卸載命令:

pip3 uninstall ohos-build
  • 運行如下命令安裝hb
pip3 install build/lite   // 該命令需在OpenHarmony源碼根目錄下執行
  • 設置環境變量
vim ~/.bashrc

將以下命令拷貝到.bashrc文件的最后一行,保存并退出。

export PATH=~/.local/bin:$PATH

執行如下命令更新環境變量。

source ~/.bashrc
  • 再次執行”hb -v“,有以下版本顯示則表示安裝的hb版本正確。
[OHOS INFO] hb version 0.4.4
安裝交叉編譯環境

在Linux編譯服務器上搭建好基礎開發環境后,需要安裝OpenHarmony 編譯V200Z-R平臺特有的開發環境。

安裝arm-none-eabi-gcc
  • 打開Linux終端。
  • 下載[arm-none-eabi-gcc]編譯工具。
  • 安裝[arm-none-eabi-gcc]

解壓 [gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2]安裝包至~/toolchain/路徑下。

mkdir -p ~/toolchain/
tar -jxvf gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2 -C ~/toolchain/

設置環境變量。

vim ~/.bashrc

將以下命令拷貝到.bashrc文件的最后一行,保存并退出。

export PATH=~/toolchain/gcc-arm-none-eabi-10.3-2021.10/bin:$PATH

生效環境變量。

source ~/.bashrc
  • 在命令行中輸入如下命令,如果能正確顯示編譯器版本號,表明編譯器安裝成功。
arm-none-eabi-gcc -v

準備工程

本用例采用repo的方式從碼云官倉下載系統系統源碼以及開發板適配代碼,使用git從gitee的sig倉庫拉取設備應用代碼。

配置git
  • 提前注冊準備碼云gitee賬號。
  • git工具下載安裝
    sudo apt install git
    sudo apt install git-lfs
    
  • 生成/添加SSH密鑰:生成密鑰
    使用gitee賬號綁定的郵箱生成密鑰對
    ssh-keygen -t ed25519 -C "xxxxx@xxxxx.com"
    
  • 查看生成的密鑰
    cat ~/.ssh/id_ed25519.pub
    
  • 復制生成后的 ssh key,返回gitee個人主頁,通過主頁 「個人設置」->「安全設置」->「SSH 公鑰」 ,將生成的“SSH密鑰”添加到倉庫中。
  • 配置git用戶信息
    git config --global user.name "yourname"
    git config --global user.email "your-email-address"
    git config --global credential.helper store
    
準備repo
sudo curl https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > /usr/local/bin/repo
chmod a+x /usr/local/bin/repo
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple requests
準備系統源碼
#特別注意:請下載OpenHarmony 3.1 Beta版本
mkdir ~/OpenHarmony_3.1_Beta
cd ~/OpenHarmony_3.1_Beta
repo init -u git@gitee.com:openharmony/manifest.git -b refs/tags/OpenHarmony-v3.1-Beta --no-repo-verify
repo sync -c
repo forall -c 'git lfs pull'

注意:

  • 權限問題請參考[生成/添加SSH公鑰]。
  • 若在已安裝python3.8后,執行repo init 時,仍顯示如下錯誤:
/usr/bin/env: ‘python’: No such file or directory

執行如下命令后,進行重試:

sudo ln -s /usr/bin/python3.8 /usr/bin/python
準備設備側應用代碼

使用git 命令下載

git clone git@gitee.com:openharmony-sig/knowledge_demo_smart_home.git --depth=1
編譯前準備
  • 代碼拷貝

team_x源碼拷貝

mkdir ~/OpenHarmony_3.1_Beta/vendor/team_x
cp -rfa ~/knowledge_demo_smart_home/dev/team_x/smart_door_bell ~/OpenHarmony_3.1_Beta/vendor/team_x

common庫拷貝

cp -rfa ~/knowledge_demo_smart_home/dev/team_x/common ~/OpenHarmony_3.1_Beta/vendor/team_x

iot_link庫拷貝

cp -rfa ~/knowledge_demo_smart_home/dev/third_party/iot_link ~/OpenHarmony_3.1_Beta/third_party/

步驟1、下載patch

? 點擊上述鏈接進入瀏覽器,將該網頁中內容全部復制。

? 本地創建一個名為bes_kernle.patch文件,并將已經復制的內容粘貼到該文件中。

步驟2、 打上步驟1中的patch

cd ~/OpenHarmony_3.1_Beta/kernel/liteos_m
patch -p1 < bes_kernle.patch
  • device/soc/bestechnic 修改

步驟1、下載patch

? 點擊上述鏈接進入瀏覽器,將該網頁中內容全部復制。

? 本地創建一個名為bes_device.patch文件,并將已經復制的內容粘貼到該文件中。

步驟2、 打上步驟1中的patch

cd ~/OpenHarmony_3.1_Beta/device/soc/bestechnic
patch -p1 < bes_device.patch
  • third_party/mbedtls 修改

參考如下代碼段修改 mbedtls/library/platform.c

diff --git a/library/platform.c b/library/platform.c
index c4c3fd3..214173b 100755
--- a/library/platform.c
+++ b/library/platform.c
@@ -86,9 +86,24 @@ static void platform_free_uninit( void *ptr )
 static void * (*mbedtls_calloc_func)( size_t, size_t ) = MBEDTLS_PLATFORM_STD_CALLOC;
 static void (*mbedtls_free_func)( void * ) = MBEDTLS_PLATFORM_STD_FREE;
 
+#include "los_memory.h"
+
 void * mbedtls_calloc( size_t nmemb, size_t size )
 {
-    return (*mbedtls_calloc_func)( nmemb, size );
+    //return (*mbedtls_calloc_func)( nmemb, size );
+    size_t real_size;
+    void *ptr = NULL;
+
+    if (nmemb == 0 || size == 0) {
+        return NULL;
+    }
+
+    real_size = (size_t)(nmemb * size);
+    ptr = LOS_MemAlloc(OS_SYS_MEM_ADDR, real_size);
+    if (ptr != NULL) {
+        (void)memset_s(ptr, real_size, 0, real_size);
+    }
+    return ptr;
 }

參考如下代碼段修改 mbedtls/BUILD.gn

diff --git a/BUILD.gn b/BUILD.gn
index 9ecb37a..30dbb2e 100755
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -124,6 +124,7 @@ if (ohos_kernel_type == "liteos_m") {
      include_dirs = [
        "http://kernel/liteos_m/kal/posix/include",
         "http://kernel/liteos_m/kernel/include",
         "http://kernel/liteos_m/utils",
        "http://third_party/musl/porting/liteos_m/kernel/include/",
+        "http://kernel/liteos_m/kernel/include/",
       ]
     }
     output_name = "mbedtls"
  • third_party/lwip 修改

修改src/api/netdb.c 文件

diff --git a/src/api/netdb.c b/src/api/netdb.c
index 52a6fdf..2043636 100644
--- a/src/api/netdb.c
+++ b/src/api/netdb.c
@@ -100,7 +100,7 @@ lwip_gethostbyname(const char *name)
   err = netconn_gethostbyname(name, &addr);
   if (err != ERR_OK) {
     LWIP_DEBUGF(DNS_DEBUG, ("lwip_gethostbyname(%s) failed,   err=%dn", name, err));
-    h_errno = HOST_NOT_FOUND;
+    //h_errno = HOST_NOT_FOUND;
     return NULL;
   }
  • third_party/iot_link 修改

參考如下代碼段修改 third_party/iot_link/network/dtls/BUILD.gn

diff --git a/third_party/iot_link/network/dtls/BUILD.gn b/third_party/iot_link/network/dtls/BUILD.gn
index 035805d709075ef2bc9d9388e73edb84dc1ee943..ac7256cf2bc93a0a998388f31910f152bf306fa9 100755
--- a/third_party/iot_link/network/dtls/BUILD.gn
+++ b/third_party/iot_link/network/dtls/BUILD.gn
@@ -41,7 +41,8 @@ dtls_cflags = [
     "-Wno-unused-parameter",
 ]
 
-static_library("dtls") {
+#static_library("dtls") {
+source_set("dtls") {
         cflags = dtls_cflags
         defines = dtls_def
         sources = dtls_src

參考如下代碼段修改 third_party/iot_link/network/dtls/mbedtls/mbedtls_port/dtls_interface.c

diff --git a/third_party/iot_link/network/dtls/mbedtls/mbedtls_port/dtls_interface.c b/third_party/iot_link/network/dtls/mbedtls/mbedtls_port/dtls_interface.c
index 9f87c6fae041b17af4522d5d89114b69005a00be..73e406893a33385a9888a82cf6d1b3706a81387d 100755
--- a/third_party/iot_link/network/dtls/mbedtls/mbedtls_port/dtls_interface.c
+++ b/third_party/iot_link/network/dtls/mbedtls/mbedtls_port/dtls_interface.c
@@ -56,6 +56,7 @@
 #include "dtls_interface.h"
 #include "mbedtls/net_sockets.h"
 #include "mbedtls/ssl_internal.h"
+#include "mbedtls/platform.h"
 #include "cmsis_os2.h"
 #include "string.h"
 
@@ -157,6 +158,7 @@ mbedtls_ssl_context *dtls_ssl_new(dtls_establish_info_s *info, char plat_type)
 #if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
     if (info- >psk_or_cert == VERIFY_WITH_PSK)
     {
+	  #if 0
         if ((ret = mbedtls_ssl_conf_psk(conf,
                                         info- >v.p.psk,
                                         info- >v.p.psk_len,
@@ -166,6 +168,7 @@ mbedtls_ssl_context *dtls_ssl_new(dtls_establish_info_s *info, char plat_type)
             MBEDTLS_LOG("mbedtls_ssl_conf_psk failed: -0x%x", -ret);
             goto exit_fail;
         }
+		#endif
     }
 #endif
 
@@ -548,5 +551,5 @@ void dtls_init(void)
 {
     (void)mbedtls_platform_set_calloc_free(calloc, free);
     (void)mbedtls_platform_set_snprintf(snprintf);
-    (void)mbedtls_platform_set_printf(printf);
+    //(void)mbedtls_platform_set_printf(printf);
 }

參考如下代碼段修改 third_party/iot_link/network/mqtt/BUILD.gn

diff --git a/third_party/iot_link/network/mqtt/BUILD.gn b/third_party/iot_link/network/mqtt/BUILD.gn
index 5a4a8e0ded129b91ce550a5d16f04e0784fddd45..d6bc39b8ede5735d79c74a6ab562c6141bd0b377 100755
--- a/third_party/iot_link/network/mqtt/BUILD.gn
+++ b/third_party/iot_link/network/mqtt/BUILD.gn
@@ -16,6 +16,7 @@ mqtt_paho_inc = [
     "paho_mqtt/paho/MQTTPacket/src",
     "paho_mqtt/port",
     "../../inc",
+    "http://third_party/musl/porting/liteos_m/kernel/include/",
     "http://kernel/liteos_m/components/cmsis/2.0",
     "http://vendor/hisi/hi3861/hi3861/third_party/lwip_sack/include/",
 ]
@@ -50,7 +51,8 @@ mqtt_cflags = [
     "-Wno-unused-function",
 ]
 
-static_library("mqtt") {
+#static_library("mqtt") {
+source_set("mqtt") {
         cflags = mqtt_cflags
         defines = mqtt_paho_defs
         sources = mqtt_paho_src

參考如下代碼段修改 third_party/iot_link/network/mqtt/paho_mqtt/port/paho_mqtt_port.c

diff --git a/third_party/iot_link/network/mqtt/paho_mqtt/port/paho_mqtt_port.c b/third_party/iot_link/network/mqtt/paho_mqtt/port/paho_mqtt_port.c
index a213b74c7286c68061e3285c0c3ac6c440949f26..d0900c8d88149f08c93fe885f34f4d2affa30885 100755
--- a/third_party/iot_link/network/mqtt/paho_mqtt/port/paho_mqtt_port.c
+++ b/third_party/iot_link/network/mqtt/paho_mqtt/port/paho_mqtt_port.c
@@ -180,6 +180,50 @@ static int __socket_read(void *ctx, unsigned char *buf, int len, int timeout)
     int fd;
     int ret = 0;
 
+#if 1
+        int bytes = 0;
+    fd_set fdset;
+
+    struct timeval timedelay = {timeout / 1000, (timeout % 1000) * 1000};
+    if(NULL== buf)
+    {
+        return ret;
+    }
+
+    fd = (int)(intptr_t)ctx;  ///< socket could be zero
+
+    if (timedelay.tv_sec < 0 || (timedelay.tv_sec == 0 && timedelay.tv_usec <= 0))
+    {
+        timedelay.tv_sec = 0;
+        timedelay.tv_usec = 100;
+    }
+    timedelay.tv_sec = 5;
+    FD_ZERO(&fdset);
+    FD_SET(fd, &fdset);
+
+    ret = select(fd + 1, &fdset, NULL, NULL, &timedelay);
+    printf("[%s|%s|%d]fd = %d, ret = %dn", __FILE__,__func__,__LINE__, fd, ret);
+    if (ret > 0) {
+        while (bytes < len) {
+            int rc = recv(fd, &buf[bytes], (size_t)(len - bytes), 0);
+            printf("[%s|%s|%d]fd = %d, rc = %dn", __FILE__,__func__,__LINE__, fd, rc);
+            if (rc == -1) {
+                if (errno != EAGAIN && errno != EWOULDBLOCK) {
+                    bytes = -1;
+                }
+                break;
+            } else if (rc == 0) {
+                bytes = 0;
+                break;
+            } else {
+                bytes += rc;
+            }
+        }
+   }
+
+   return bytes;
+#else
+
     struct timeval timedelay = {timeout / 1000, (timeout % 1000) * 1000};
     if(NULL== buf)
     {
@@ -216,7 +260,7 @@ static int __socket_read(void *ctx, unsigned char *buf, int len, int timeout)
         }
     }
     return bytes;
-
+  #endif
 }
 
 
@@ -586,7 +630,7 @@ static void * __connect(mqtt_al_conpara_t *conparam)
     attr.cb_mem = NULL;
     attr.cb_size = 0U;
     attr.stack_mem = NULL;
-    attr.stack_size = 1024 * 2;
+    attr.stack_size = 1024 * 4;
     attr.priority = 28;
     cb- >task = osThreadNew((osThreadFunc_t)__loop_entry, cb, &attr);
     if(NULL == cb- >task)

參考如下代碼段修改 third_party/iot_link/network/mqtt/paho_mqtt/port/paho_osdepends.h

diff --git a/third_party/iot_link/network/mqtt/paho_mqtt/port/paho_osdepends.h b/third_party/iot_link/network/mqtt/paho_mqtt/port/paho_osdepends.h
index 2c6cab1b90bef7be82891637c200cdb664e9735b..38e3dce3867d2b2d538858c72b36bee7330c7b4f 100755
--- a/third_party/iot_link/network/mqtt/paho_mqtt/port/paho_osdepends.h
+++ b/third_party/iot_link/network/mqtt/paho_mqtt/port/paho_osdepends.h
@@ -84,6 +84,7 @@
 
 #include "ohos_init.h"
 #include "cmsis_os2.h"
+#include "sys/time.h"
 #include  < mqtt_al.h >
 
 #define MQTT_TASK 1
@@ -117,6 +118,13 @@ typedef struct Thread
 int ThreadStart(Thread*, void (*fn)(void*), void* arg);
 
 
+#define timeradd(s,t,a) (void) ( (a)- >tv_sec = (s)- >tv_sec + (t)- >tv_sec, 
+        ((a)- >tv_usec = (s)- >tv_usec + (t)- >tv_usec) >= 1000000 && 
+        ((a)- >tv_usec -= 1000000, (a)- >tv_sec++) )
+#define timersub(s,t,a) (void) ( (a)- >tv_sec = (s)- >tv_sec - (t)- >tv_sec, 
+        ((a)- >tv_usec = (s)- >tv_usec - (t)- >tv_usec) < 0 && 
+        ((a)- >tv_usec += 1000000, (a)- >tv_sec--) )
+
 typedef struct Network
 {
     void *ctx;                      ///< if it is tls, then it is tls context, else it is socket fd

參考如下代碼段修改 third_party/iot_link/oc_mqtt/BUILD.gn

diff --git a/third_party/iot_link/oc_mqtt/BUILD.gn b/third_party/iot_link/oc_mqtt/BUILD.gn
index c777c5e4f2e79646a5c76471f22c5437e9d4b3ee..1e3e07ddb6c0bc52465a60c415c8550608a21e55 100755
--- a/third_party/iot_link/oc_mqtt/BUILD.gn
+++ b/third_party/iot_link/oc_mqtt/BUILD.gn
@@ -11,7 +11,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-static_library("oc_mqtt") {
+#static_library("oc_mqtt") {
+source_set("oc_mqtt") {
     sources = [
         "oc_mqtt_al/oc_mqtt_al.c",
         "oc_mqtt_profile_v5/oc_mqtt_profile.c",
  • communicationkit相關修改

參考下方代碼修改foundation/ace/ace_engine_lite/frameworks/module_manager/ohos_module_config.h

diff --git a/frameworks/module_manager/ohos_module_config.h b/frameworks/module_manager/ohos_module_config.h
index f8eb744..3bb25d1 100644
--- a/frameworks/module_manager/ohos_module_config.h
+++ b/frameworks/module_manager/ohos_module_config.h
@@ -47,6 +47,10 @@ extern void InitNativeApiFs(JSIValue exports);
 extern void InitNativeApiKv(JSIValue exports);
 #endif

+#if (FEATURE_MODULE_COMMUNICATIONKIT == 1)
+extern void InitNativeApiCommunicationKit(JSIValue exports);
+#endif
+
 #if (FEATURE_MODULE_DEVICE == 1)
 extern void InitDeviceModule(JSIValue exports);
 #endif
@@ -98,11 +102,13 @@ const Module OHOS_MODULES[] = {
 #if (FEATURE_MODULE_DIALOG == 1)
     {"prompt", InitDialogModule},
 #endif // FEATURE_MODULE_DIALOG
-
 #if (FEATURE_MODULE_STORAGE == 1)
     {"file", InitNativeApiFs},
     {"storage", InitNativeApiKv},
 #endif
+#if (FEATURE_MODULE_COMMUNICATIONKIT == 1)
+    {"CommunicationKit", InitNativeApiCommunicationKit},
+#endif
 #if (FEATURE_MODULE_DEVICE == 1)
     {"device", InitDeviceModule},
 #endif
  • flash_size配置修改

根據開發板的硬件版本不同,還需更改配置文件中flash_size的值。具體路徑為/device/board/fnlink/v200zr/liteos_m/config.gni。其中v1.0版本對應16,2.0版本對應32,硬件版本打印在了開發板正面。

diff --git a/v200zr/liteos_m/config.gni b/v200zr/liteos_m/config.gni
index b288101..6489dd2 100644
--- a/v200zr/liteos_m/config.gni
+++ b/v200zr/liteos_m/config.gni
@@ -47,7 +47,7 @@ if (product_path != "") {
   bsp_bin_list = product_conf.bsp_bin_list
   pack_burn = product_conf.pack_burn
 }
-flash_size = 16
+flash_size = 32
  • hdf配置文件修改

參考下方代碼修改device/board/fnlink/shields/v200zr-evb-t1/v200zr-evb-t1.hcs

diff --git a/shields/v200zr-evb-t1/v200zr-evb-t1.hcs b/shields/v200zr-evb-t1/v200zr-evb-t1.hcs
index 44212eb..4fc99da 100644
--- a/shields/v200zr-evb-t1/v200zr-evb-t1.hcs
+++ b/shields/v200zr-evb-t1/v200zr-evb-t1.hcs
@@ -17,12 +17,17 @@ root {
     platform {
         gpio_config {
             match_attr = "gpio_config";
-            pin = [0, 1];
+            pin = [0, 1, 2, 3, 4, 5, 6, 7];
             // touch_ztw523: TSP_RST - GPIO12, TSP_INT-GPIO27
             // touch_fts: TSP_RST - GPIO05, TSP_INT-GPIO27
-            realPin = [5, 27];
-            config = [5, 2];
-            pinNum = 2;
+            realPin = [5, 27, 1, 11, 15, 10, 14, 13];
+            config = [5, 2, 2, 4, 5, 5, 5, 2];
+            pinNum = 8;
+        }
+        pwm0_config{
+            match_attr = "pwm0_config";
+            pwmId = 0;
+            pwmPin = 20;
         }
         i2c_config {
             i2c0 {
  • gpio hdf框架相關修改。

根據下方代碼修改drivers/adapter/platform/gpio/gpio_bes.c

diff --git a/platform/gpio/gpio_bes.c b/platform/gpio/gpio_bes.c
index ed4d18b..890d528 100755
--- a/platform/gpio/gpio_bes.c
+++ b/platform/gpio/gpio_bes.c
@@ -257,7 +257,7 @@ static int32_t GpioDriverBind(struct HdfDeviceObject *device)
     }

     gpioCntlr.device.hdfDev = device;
-    device- >service = gpioCntlr.device.service;
+    device- >service = &(gpioCntlr.device);

     return HDF_SUCCESS;
 }
  • 將pwm_if.c納入編譯。

參考下方代碼修改driversadapterkhdfliteos_mplatformBUILD.gn

diff --git a/khdf/liteos_m/platform/BUILD.gn b/khdf/liteos_m/platform/BUILD.gn
index 84c9152..8a4016a 100755
--- a/khdf/liteos_m/platform/BUILD.gn
+++ b/khdf/liteos_m/platform/BUILD.gn
@@ -63,7 +63,10 @@ hdf_driver("hdf_platform_lite") {
   }

   if (defined(LOSCFG_DRIVERS_HDF_PLATFORM_PWM)) {
-    sources += [ "$HDF_FRAMEWORKS_PATH/support/platform/src/pwm/pwm_core.c" ]
+    sources += [
+      "$HDF_FRAMEWORKS_PATH/support/platform/src/pwm/pwm_core.c",
+      "$HDF_FRAMEWORKS_PATH/support/platform/src/pwm/pwm_if.c",
+    ]
   }

   if (defined(LOSCFG_DRIVERS_HDF_PLATFORM_RTC)) {
  • 將JS應用合入工程。

關于JS應用開發請參考[從零開始學習L0: JS開發系列]。本節為可選章節,忽略本節內容不影響智能門鈴項目的展示和運行。但若想要在本項目的基礎上進行涉及到顯示的內容修改與新規開發,例如增加天氣預報的圖標,則需完整的閱讀本節及鏈接內容。

  • 下載并安裝[DevEco Studio]。

  • 打開js工程。

工程目錄為:knowledge_demo_smart_home/dev/team_x/smart_door_bell/FA

  • 在DevEco Studio的SDK中添加@system.communicationkit.d.ts文件。

將@system.communicationkit.d.ts文件(源文件目錄:~/knowledge_demo_smart_home/dev/interface/sdk-js/api/common/@system.communicationkit.d.ts)拷貝到在DevEco Studio的SDK中(目標目錄: HarmonyOS Legacy SDK /js/3.0.0.0/api/common)。HarmonyOS Legacy SDK目錄在DevEco Studio安裝時,由用戶配置,該目錄位置可在設置(ctrl+alt+s)中查找。

  • 編譯hap包。

依次選擇構建 -> Build Hap(s)/APP(s) -> Build Hap(s)進行hap包編譯,編譯后的hap包目錄為:FAentrybuildoutputshapdebugentry-debug-lite-unsigned.hap。

  • 將js代碼合入OpenHarmonySDK。

將entry-debug-lite-unsigned.hap修改后綴為zip并解壓。在解壓后的目錄:entry-debug-lite-unsigned/assets/js/default目錄中除app.js.map外的的數據全部拷貝到OpenHarmonySDK中的vendor/team_x/smart_door_bell/fs/data/data/js目錄下。

工程效果

整合并修改完成后的代碼目錄結構如下圖:

image-20211228205514766

編譯

編譯命令:

hb set  // 如果是第一次編譯,Input code path 命令行中鍵入"./" 指定OpenHarmony工程編譯根目錄后回車。

image-20211228205557170

如下圖所示,使用鍵盤上下鍵選中智能門鈴 “smart_door_bell”(注:工程名字根據實際要編譯的工程來):

hb build // 如果需要全量編譯,可以添加-f 選項

編譯通過,生成固件成功,如圖:

image-20211228205659402

燒錄/安裝

  • 安裝[CP2102驅動]
  • 固件編譯完成以后拷貝/out/v200zr/smart_door_bell/write_flash_gui文件夾到windows下,并點擊Wifi_download_main.exe

  • 點擊工具上的文件夾圖標

  • 選擇List按鈕

  • 在顯示出來的串口列表中選擇需要燒錄的串口,并點擊開始按鈕。

  • 在開發板上點擊reset按鍵,或者重新上電。

  • 進入燒錄狀態

  • 燒錄成功

? 注意:固件燒錄完成后需將燒錄窗口關閉,再按下設備Reset鍵設備才能啟動。如果未將燒錄窗口關閉,設備會再次進行燒寫狀態。

####操作體驗

設備配網
  • 在設備上電前需準備好安裝了數字管家應用的HarmonyOS手機, 并在設置中開啟手機的NFC功能;
  • 寫設備NFC標簽;
  • 燒錄完成后,上電。開發者在觀察開發板上狀態LED燈以1Hz的頻率閃爍時,將手機上半部靠近開發板NFC標簽處;
  • 手機將自動拉起數字管家應用并進入配網狀態,根據手機提示連接到設備熱點teamX-DoorBell01后返回數字管家APP,輸入路由賬號密碼,點擊確定后,手機將信息傳輸到設備側,設備開始聯網。
    ![](//file1.elecfans.com/web2/M00/CF/C7/wKgZomYiHdKAGL0OAA_n0GFunYg951.jpg)
    
設備控制
  • 有陌生人靠近:

  • 有人按門鈴:

  • 遠程一鍵開門:

審核編輯 黃宇

聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。 舉報投訴
  • 智能門鈴
    +關注

    關注

    0

    文章

    43

    瀏覽量

    5818
  • 鴻蒙
    +關注

    關注

    55

    文章

    1769

    瀏覽量

    42153
  • HarmonyOS
    +關注

    關注

    79

    文章

    1878

    瀏覽量

    29335
  • OpenHarmony
    +關注

    關注

    23

    文章

    3380

    瀏覽量

    15194
收藏 人收藏

    評論

    相關推薦

    OpenHarmony南向開發案例:【分布式畫板】

    使用OpenHarmony3.1-Release開發的應用。通過OpenHarmony的分布式技術,使多人能夠一起畫畫。
    的頭像 發表于 04-12 14:40 ?559次閱讀
    <b class='flag-5'>OpenHarmony</b><b class='flag-5'>南向</b><b class='flag-5'>開發案</b>例:【分布式畫板】

    OpenHarmony南向開發案例:【智能油煙機】

    基于Hi3516開發板,使用開源OpenHarmony開發的應用。
    的頭像 發表于 04-18 15:54 ?692次閱讀
    <b class='flag-5'>OpenHarmony</b><b class='flag-5'>南向</b><b class='flag-5'>開發案</b>例:【<b class='flag-5'>智能</b>油煙機】

    OpenHarmony南向開發案例:【 智能家居中控】

    今天打造的這一款全新智能家庭控制系統,凸顯應用在智能控制和用戶體驗的特點,開創國內智能家居系統體驗新局面。新的系統主要應用在鴻蒙生態。
    的頭像 發表于 04-23 15:50 ?507次閱讀
    <b class='flag-5'>OpenHarmony</b><b class='flag-5'>南向</b><b class='flag-5'>開發案</b>例:【 <b class='flag-5'>智能</b>家居中控】

    鴻蒙開發南向環境搭建教學

    南向開發環境搭建教學,更多鴻蒙開發資料可以前往高清完整版 《鴻蒙開發4.0基礎-高階文檔》找保存
    發表于 01-05 16:38

    鴻蒙不再兼容安卓,那么鴻蒙開發者是否會大增?

    。以上為略縮版圖冊,如果需要高清完整的可以在主頁4或https://qr23.cn/AKFP8k保存。 內容涵蓋:(文檔形式) OpenHarmony入門基礎 OpenHarmony核心技能 OpenHarmony高級技能
    發表于 01-31 22:17

    OpenHarmony南向能力征集令

    1、適配過程中缺少哪些接口能力或者南向能力,需要OpenHarmony去補齊的?例如內核、編譯、器件適配、單板適配等; 2、對標linux,需要OpenHarmony提供哪些能力?比如V4L2
    發表于 04-09 15:32

    【每日精選】鴻蒙大咖HarmonyOS開發資料合集

    分享一些嵌入式的學習、工作經驗。2.韋東山老師OpenHarmony內核在第三方開發板上的移植簡介:韋東山老師就鴻蒙內核移植進行講解,比如:一個完整的嵌入式系統都有什么?操作系統怎么“同時運行”多個任務
    發表于 10-28 18:43

    2022年首屆福建省大學生人工智能創意賽—開源鴻蒙開發者大賽賽事宣講&答疑

    OpenHarmony經典開發案例。凌智電子聯合電子發燒友進行線上宣講通知:《2022年首屆福建省大學生人工智能創意賽—開源鴻蒙開發者大賽賽
    發表于 09-08 14:01

    凌蒙派-開源鴻蒙北向App控制南向設備應用示例-RGB燈控制

    OpenHarmony標準系統,rgb三色燈APP控制,hdf?napi?UI框架,一個開源鴻蒙北向應用開發,控制南向設備應用。
    發表于 03-22 10:56

    openharmony鴻蒙有什么關系

    ,讓平板、手機、智能家居都可以通過建房子搭積木的方式來使用鴻蒙系統。 openharmony鴻蒙之間屬于相輔相成的,可以說openharmony
    的頭像 發表于 06-22 16:02 ?1.1w次閱讀

    華為開發者分論壇HarmonyOS學生公開課-OpenHarmony Codelabs開發案

    2021華為開發者分論壇HarmonyOS學生公開課-OpenHarmony Codelabs開發案
    的頭像 發表于 10-24 11:25 ?1636次閱讀
    華為<b class='flag-5'>開發</b>者分論壇HarmonyOS學生公開課-<b class='flag-5'>OpenHarmony</b> Codelabs<b class='flag-5'>開發案</b>例

    OpenHarmony Dev-Board-SIG專場:南向共建案例分享

    OpenHarmony南向共建案例分享: 審核編輯:金巧
    的頭像 發表于 12-28 14:16 ?840次閱讀
    <b class='flag-5'>OpenHarmony</b> Dev-Board-SIG專場:<b class='flag-5'>南向</b>共建案例分享

    OpenHarmony南向開發案例:【智能照相機】

    基于Hi3516開發板,使用OpenHarmony3.0-LTS開發的應用。通過獲取攝像頭數據,實現預覽拍照以及路視頻等功能。并且通過后臺AI服務識別喚醒詞來進行語音控制拍照及錄制視頻。
    的頭像 發表于 04-18 22:19 ?91次閱讀
    <b class='flag-5'>OpenHarmony</b><b class='flag-5'>南向</b><b class='flag-5'>開發案</b>例:【<b class='flag-5'>智能</b>照相機】

    OpenHarmony鴻蒙南向開發案例:【智能燃氣檢測設備】

    安全廚房案例中的相關智能燃氣檢測設備,本安全廚房案例利用輕量級軟總線能力,將兩塊歐智通V200Z-R/BES2600開發板模擬的智能燃氣檢測設備和燃氣告警設備組合成。當燃氣數值告警時,無需其它操作,直接通知軟總線網絡中的通風設備
    的頭像 發表于 04-19 17:17 ?201次閱讀
    <b class='flag-5'>OpenHarmony</b><b class='flag-5'>鴻蒙</b><b class='flag-5'>南向</b><b class='flag-5'>開發案</b>例:【<b class='flag-5'>智能</b>燃氣檢測設備】

    OpenHarmony鴻蒙南向開發案例:【智能貓眼(基于3516開發板)】

    基于Hi3516開發板,使用開源OpenHarmony開發的RTSP協議流媒體應用。達到將Hi3516開發板中攝像頭獲取的數據通過RTSP協議傳輸到手機并顯示 。
    的頭像 發表于 04-19 22:01 ?80次閱讀
    <b class='flag-5'>OpenHarmony</b><b class='flag-5'>鴻蒙</b><b class='flag-5'>南向</b><b class='flag-5'>開發案</b>例:【<b class='flag-5'>智能</b>貓眼(基于3516<b class='flag-5'>開發</b>板)】
    亚洲欧美日韩精品久久_久久精品AⅤ无码中文_日本中文字幕有码在线播放_亚洲视频高清不卡在线观看
    <acronym id="s8ci2"><small id="s8ci2"></small></acronym>
    <rt id="s8ci2"></rt><rt id="s8ci2"><optgroup id="s8ci2"></optgroup></rt>
    <acronym id="s8ci2"></acronym>
    <acronym id="s8ci2"><center id="s8ci2"></center></acronym>