diff --git a/src/.gitignore b/src/.gitignore
new file mode 100644
index 0000000..72e653a
--- /dev/null
+++ b/src/.gitignore
@@ -0,0 +1,5 @@
+.deveco/**
+.vscode/**
+**/.DS_Store
+.remote-sync.json
+.ftpconfig*
diff --git a/src/LICENSE b/src/LICENSE
new file mode 100644
index 0000000..261eeb9
--- /dev/null
+++ b/src/LICENSE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/src/applications/sample/wifi-iot/.gitee/ISSUE_TEMPLATE.zh-CN.md b/src/applications/sample/wifi-iot/.gitee/ISSUE_TEMPLATE.zh-CN.md
new file mode 100644
index 0000000..651e02c
--- /dev/null
+++ b/src/applications/sample/wifi-iot/.gitee/ISSUE_TEMPLATE.zh-CN.md
@@ -0,0 +1,11 @@
+### 该问题是怎么引起的?
+
+
+
+### 重现步骤
+
+
+
+### 报错信息
+
+
diff --git a/src/applications/sample/wifi-iot/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md b/src/applications/sample/wifi-iot/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md
new file mode 100644
index 0000000..86dd358
--- /dev/null
+++ b/src/applications/sample/wifi-iot/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md
@@ -0,0 +1,12 @@
+### 相关的Issue
+
+
+### 原因(目的、解决的问题等)
+
+
+### 描述(做了什么,变更了什么)
+
+
+### 测试用例(新增、改动、可能影响的功能)
+
+
diff --git a/src/applications/sample/wifi-iot/LICENSE b/src/applications/sample/wifi-iot/LICENSE
new file mode 100644
index 0000000..4947287
--- /dev/null
+++ b/src/applications/sample/wifi-iot/LICENSE
@@ -0,0 +1,177 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
\ No newline at end of file
diff --git a/src/applications/sample/wifi-iot/OAT.xml b/src/applications/sample/wifi-iot/OAT.xml
new file mode 100644
index 0000000..56abade
--- /dev/null
+++ b/src/applications/sample/wifi-iot/OAT.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/applications/sample/wifi-iot/README.md b/src/applications/sample/wifi-iot/README.md
new file mode 100644
index 0000000..b606fd4
--- /dev/null
+++ b/src/applications/sample/wifi-iot/README.md
@@ -0,0 +1,26 @@
+# WIFI\_IOT\_APP
+
+- [Introduction](#section11660541593)
+- [Directory Structure](#section1464106163817)
+- [Repositories Involved](#section1718733212019)
+
+## Introduction
+
+The WIFI\_IOT\_APP module provides sample code for iothardware, demolink, and samgr.
+
+## Directory Structure
+
+```
+applications/sample/wifi-iot/ # Sample code
+└── app
+ ├── BUILD.gn # Build script
+ ├── demolink # Sample code for integrating demolink
+ ├── iothardware # Sample code for LED operations
+ ├── samgr # Sample code for the service framework
+ └── startup
+```
+
+## Repositories Involved
+
+applications\_sample\_wifi-iot
+
diff --git a/src/applications/sample/wifi-iot/README_zh.md b/src/applications/sample/wifi-iot/README_zh.md
new file mode 100644
index 0000000..99e4755
--- /dev/null
+++ b/src/applications/sample/wifi-iot/README_zh.md
@@ -0,0 +1,26 @@
+# WIFI\_IOT\_APP组件
+
+- [简介](#section11660541593)
+- [目录](#section1464106163817)
+- [涉及仓](#section1718733212019)
+
+## 简介
+
+WIFI\_IOT\_APP组件,提供了iothardware、demolink、samgr等示例代码。
+
+## 目录
+
+```
+applications/sample/wifi-iot/ # sample模块目录
+└── app
+ ├── BUILD.gn # 模块构建脚本
+ ├── demolink # demolink集成示例代码
+ ├── iothardware # LED操作示例代码
+ ├── samgr # 服务框架示例代码
+ └── startup
+```
+
+## 涉及仓
+
+applications\_sample\_wifi-iot
+
diff --git a/src/applications/sample/wifi-iot/app/BUILD.gn b/src/applications/sample/wifi-iot/app/BUILD.gn
new file mode 100644
index 0000000..7465791
--- /dev/null
+++ b/src/applications/sample/wifi-iot/app/BUILD.gn
@@ -0,0 +1,18 @@
+# Copyright (c) 2020-2022 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build/lite/config/component/lite_component.gni")
+
+lite_component("app") {
+ features = [ "cloud_to_uart:cloud_uart", ]
+}
diff --git a/src/applications/sample/wifi-iot/app/core/BUILD.gn b/src/applications/sample/wifi-iot/app/core/BUILD.gn
new file mode 100644
index 0000000..a2151b3
--- /dev/null
+++ b/src/applications/sample/wifi-iot/app/core/BUILD.gn
@@ -0,0 +1,41 @@
+# Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+static_library("cloud_uart") {
+ sources = [
+ "app_demo_iot.c",
+ "cjson_init.c",
+ "iot_hmac.c",
+ "iot_log.c",
+ "iot_main.c",
+ "iot_profile.c",
+ "iot_sta.c",
+ "hal_iot_gpio_ex.c",
+ "hisignalling_protocol.c",
+ ]
+
+ include_dirs = [
+ "./",
+ "//utils/native/lite/include",
+ "//kernel/liteos_m/kal/cmsis",
+ "//base/iot_hardware/peripheral/interfaces/kits",
+ "//device/soc/hisilicon/hi3861v100/sdk_liteos/third_party/lwip_sack/include/lwip",
+ "//third_party/cJSON",
+ "//device/soc/hisilicon/hi3861v100/sdk_liteos/third_party/mbedtls/include/mbedtls",
+ "//foundation/communication/wifi_lite/interfaces/wifiservice",
+ "//device/soc/hisilicon/hi3861v100/sdk_liteos/third_party/paho.mqtt.c/include/mqtt",
+ "//device/soc/hisilicon/hi3861v100/sdk_liteos/third_party/libcoap/include/coap2",
+ ]
+
+ defines = [ "WITH_LWIP" ]
+}
diff --git a/src/applications/sample/wifi-iot/app/core/app_demo_iot.c b/src/applications/sample/wifi-iot/app/core/app_demo_iot.c
new file mode 100644
index 0000000..26a81cf
--- /dev/null
+++ b/src/applications/sample/wifi-iot/app/core/app_demo_iot.c
@@ -0,0 +1,507 @@
+/*
+ * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "iot_config.h"
+#include "iot_log.h"
+#include "iot_main.h"
+#include "iot_profile.h"
+#include "ohos_init.h"
+#include "cmsis_os2.h"
+#include "iot_gpio.h"
+#include
+#include
+#include
+#include
+#include
+#include "iot_gpio_ex.h"
+
+
+
+
+/* attribute initiative to report */
+#define TAKE_THE_INITIATIVE_TO_REPORT
+#define TWO_SECOND (2000)
+/* oc request id */
+#define CN_COMMADN_INDEX "commands/request_id="
+#define WECHAT_SUBSCRIBE_control "slot_num"
+#define WECHAT_SUBSCRIBE_channel1 "slot_1"
+#define WECHAT_SUBSCRIBE_channel2 "slot_2"
+#define WECHAT_SUBSCRIBE_channel3 "slot_3"
+#define WECHAT_SUBSCRIBE_channel4 "4"
+#define topic_data "YT32IOSCAL/Hi38611_mqtt/data"
+#define topic_event "YT32IOSCAL/Hi38611_mqtt/event"
+#define topic_control "YT32IOSCAL/Hi38611_mqtt/control"
+#define human_detect_io 7
+
+int g_ligthStatus = -1;
+int control_success = 0;
+char *control_flag = "failed";
+char *message = NULL;
+UartDefConfig uartDefConfig = {0};
+//int slot1 = 20,slot2 = 20, slot3 = 20, slot4 = 20;
+typedef void (*FnMsgCallBack)(hi_gpio_value val);
+
+typedef struct FunctionCallback {
+ hi_bool stop;
+ hi_u32 conLost;
+ hi_u32 queueID;
+ hi_u32 iotTaskID;
+ FnMsgCallBack msgCallBack;
+}FunctionCallback;
+FunctionCallback g_functinoCallback;
+
+// uart
+
+static void Uart1GpioCOnfig(void)
+{
+#ifdef ROBOT_BOARD
+ IoSetFunc(HI_IO_NAME_GPIO_5, IOT_IO_FUNC_GPIO_5_UART1_RXD);
+ IoSetFunc(HI_IO_NAME_GPIO_6, IOT_IO_FUNC_GPIO_6_UART1_TXD);
+ /* IOT_BOARD */
+#elif defined (EXPANSION_BOARD)
+ IoSetFunc(HI_IO_NAME_GPIO_0, IOT_IO_FUNC_GPIO_0_UART1_TXD);
+ IoSetFunc(HI_IO_NAME_GPIO_1, IOT_IO_FUNC_GPIO_1_UART1_RXD);
+#endif
+}
+
+/* CPU Sleep time Set */
+unsigned int TaskMsleep(unsigned int ms)
+{
+ if (ms <= 0) {
+ return HI_ERR_FAILURE;
+ }
+ return hi_sleep((hi_u32)ms);
+}
+
+static void DeviceConfigInit(hi_gpio_value val)
+{
+ hi_io_set_func(HI_IO_NAME_GPIO_9, HI_IO_FUNC_GPIO_9_GPIO);
+ hi_gpio_set_dir(HI_GPIO_IDX_9, HI_GPIO_DIR_OUT);
+ hi_gpio_set_ouput_val(HI_GPIO_IDX_9, val);
+}
+
+static void engine_control(unsigned int IO){
+ IoTGpioInit(IO);
+ IoSetFunc(IO, 0);
+ IoTGpioSetDir(IO, IOT_GPIO_DIR_OUT);
+ IoTGpioSetOutputVal(IO, IOT_GPIO_VALUE1);
+ IOT_LOG_DEBUG("Engine at GPIO:%u started!\n", IO);
+ hi_udelay(20000);
+ IoTGpioSetOutputVal(IO, IOT_GPIO_VALUE0);
+ IOT_LOG_DEBUG("Engine at GPIO:%u stopped!\n", IO);
+}
+
+static void engine_start(unsigned int IO){
+ IoSetFunc(IO, 0);
+ IoTGpioSetDir(IO, IOT_GPIO_DIR_OUT);
+ IoTGpioSetOutputVal(IO, IOT_GPIO_VALUE1);
+ IOT_LOG_DEBUG("Engine at GPIO:%u started!\n", IO);
+}
+
+static void engine_stop(unsigned int IO){
+ IoSetFunc(IO, 0);
+ IoTGpioSetDir(IO, IOT_GPIO_DIR_OUT);
+ IoTGpioSetOutputVal(IO, IOT_GPIO_VALUE0);
+ IOT_LOG_DEBUG("Engine at GPIO:%u stopped!\n", IO);
+}
+
+static void engine_reinit(unsigned int IO){
+ IoTGpioInit(IO);
+ IoSetFunc(IO, 0);
+ IoTGpioSetDir(IO, IOT_GPIO_DIR_OUT);
+ IoTGpioSetOutputVal(IO, IOT_GPIO_VALUE0);
+ IOT_LOG_DEBUG("Engine at GPIO:%u initialized!\n", IO);
+}
+
+static void all_engine_reinit(){
+ engine_reinit(6);
+ engine_reinit(7);
+ engine_reinit(9);
+ engine_reinit(10);
+ IOT_LOG_DEBUG("All engines initialized!\n");
+}
+
+static void Sensor_init(){
+ IoTGpioInit(human_detect_io);
+ IoSetFunc(human_detect_io, 0);
+ IoTGpioSetDir(human_detect_io, IOT_GPIO_DIR_IN);
+ IOT_LOG_DEBUG("Sensor initialized!\n");
+}
+
+static int DeviceMsgCallback(FnMsgCallBack msgCallBack)
+{
+ g_functinoCallback.msgCallBack = msgCallBack;
+ return 0;
+}
+
+static void wechatControlDeviceMsg(hi_gpio_value val)
+{
+ DeviceConfigInit(val);
+}
+
+
+// < this is the callback function, set to the mqtt, and if any messages come, it will be called
+// < The payload here is the json string
+static void DemoMsgRcvCallBack(int qos, const char *topic, const char *payload)/*定义3861接收到json文件后的操作*/
+{
+ IOT_LOG_DEBUG("RCVMSG:QOS:%d TOPIC:%s PAYLOAD:%s\r\n", qos, topic, payload);
+ printf(strstr(payload, WECHAT_SUBSCRIBE_control));
+ /* 云端下发命令后,板端的操作处理 */
+ if (strstr(payload, WECHAT_SUBSCRIBE_control) != NULL) {
+ //printf(strstr(payload, WECHAT_SUBSCRIBE_control));
+
+ all_engine_reinit();
+ if (strstr(payload, WECHAT_SUBSCRIBE_channel1) != NULL) {
+ engine_start(6);
+ hi_udelay(4000000);
+ engine_stop(6);
+ wechatControlDeviceMsg(HI_GPIO_VALUE1);
+ control_success = 1;
+ control_flag = payload;
+ }
+ else if (strstr(payload, WECHAT_SUBSCRIBE_channel2) != NULL) {
+ engine_start(7);
+ hi_udelay(4000000);
+ engine_stop(7);
+ wechatControlDeviceMsg(HI_GPIO_VALUE1);
+ control_success = 1;
+ control_flag = payload;
+ }
+ else if (strstr(payload, WECHAT_SUBSCRIBE_channel3) != NULL) {
+ engine_start(2);
+ hi_udelay(4000000);
+ engine_stop(2);
+ wechatControlDeviceMsg(HI_GPIO_VALUE1);
+ control_success = 1;
+ control_flag = payload;
+ }
+ else if (strstr(payload, WECHAT_SUBSCRIBE_channel4) != NULL) {
+ engine_start(10);
+ hi_udelay(4000000);
+ engine_stop(10);
+ wechatControlDeviceMsg(HI_GPIO_VALUE1);
+ control_success = 1;
+ control_flag = payload;
+ }
+
+ }
+
+ return HI_NULL;
+}
+
+static void DemoMsgRcvsynchronize(int qos, const char *topic, const char *payload)
+{
+ message = payload;
+
+}
+
+/* publish sample */
+/*hi_void IotPublishSample(int slot1, int slot2, int slot3, int slot4)
+{
+ // reported attribute
+ WeChatProfile weChatProfile = {
+ .subscribeType = "type",
+ .status.subState = "state",
+ .status.subReport = "reported",
+ .status.reportVersion = "version",
+ .status.Token = "clientToken",
+ // report motor
+ .reportAction.subDeviceActionMotor = "slot_1",
+ .reportAction.motorActionStatus = slot1, // 0 : motor off
+ // report temperature
+ .reportAction.subDeviceActionTemperature = "slot_2",
+ .reportAction.temperatureData = slot2, // 30 :temperature data
+ // report humidity
+ .reportAction.subDeviceActionHumidity = "slot_3",
+ .reportAction.humidityActionData = slot3, // humidity data
+ // report light_intensity
+ .reportAction.subDeviceActionLightIntensity = "slot_4",
+ .reportAction.lightIntensityActionData = slot4, // 60 : light_intensity
+ };
+
+ // report light
+ if (g_ligthStatus == HI_TRUE) {
+ weChatProfile.reportAction.subDeviceActionLight = "light";
+ weChatProfile.reportAction.lightActionStatus = 1; // 1: light on
+ } else if (g_ligthStatus == HI_FALSE) {
+ weChatProfile.reportAction.subDeviceActionLight = "light";
+ weChatProfile.reportAction.lightActionStatus = 0; // 0: light off
+ } else {
+ weChatProfile.reportAction.subDeviceActionLight = "light";
+ weChatProfile.reportAction.lightActionStatus = 0; // 0: light off
+ }
+ //profile report
+ IoTProfilePropertyReport(CONFIG_USER_ID, &weChatProfile1);
+}*/
+
+// < this is the demo main task entry,here we will set the wifi/cjson/mqtt ready and
+// < wait if any work to do in the while
+//static hi_void *DemoEntry(const char *arg)
+//{
+
+ //int feedback = 0;
+
+
+ /*6WifiStaReadyWait();
+ cJsonInit();
+ IoTMain();
+ /* 云端下发回调 */
+ //IoTSetMsgCallback(DemoMsgRcvCallBack);
+
+ /*if (control_success == 1)
+ {
+ //Uart1GpioCOnfig();
+ feedback = IoTUartWrite(DEMO_UART_NUM, control_flag, 7);
+ printf("feedback: %d", feedback);
+
+ }*/
+
+ /* 主动上报 */
+/*#ifdef TAKE_THE_INITIATIVE_TO_REPORT
+ while (1) {
+ // 用户可以在这调用发布函数进行发布,需要用户自己写调用函数
+ IotPublishSample(slot1,slot2,slot3,slot4); // 发布例程
+#endif*/
+ //TaskMsleep(TWO_SECOND);
+
+ //return NULL;
+//}
+
+///////////////////////////////////////////////////////////////////////////////////////////
+int SetUartRecvFlag(UartRecvDef def)
+{
+ if (def == UART_RECV_TRUE) {
+ uartDefConfig.g_uartReceiveFlag = HI_TRUE;
+ } else {
+ uartDefConfig.g_uartReceiveFlag = HI_FALSE;
+ }
+
+ return uartDefConfig.g_uartReceiveFlag;
+}
+
+int GetUartConfig(UartDefType type)
+{
+ int receive = 0;
+
+ switch (type) {
+ case UART_RECEIVE_FLAG:
+ receive = uartDefConfig.g_uartReceiveFlag;
+ break;
+ case UART_RECVIVE_LEN:
+ receive = uartDefConfig.g_uartLen;
+ break;
+ default:
+ break;
+ }
+ return receive;
+}
+
+void ResetUartReceiveMsg(void)
+{
+ (void)memset_s(uartDefConfig.g_receiveUartBuff, sizeof(uartDefConfig.g_receiveUartBuff),
+ 0x0, sizeof(uartDefConfig.g_receiveUartBuff));
+}
+
+unsigned char *GetUartReceiveMsg(void)
+{
+ return uartDefConfig.g_receiveUartBuff;
+}
+
+static hi_void *UartDemoTask(char *param)
+{
+ hi_u8 uartBuff[UART_BUFF_SIZE] = {0};
+ char *recBuff = NULL;
+ int feedback_1 = 0;
+ int feedback_2 = 0;
+ int length = 0;
+ unsigned char *detect_flag = "start";
+ unsigned char *data_send = "jdata";
+ IotGpioValue value = IOT_GPIO_VALUE0;
+
+ hi_unref_param(param);
+ printf("Initialize uart demo successfully, please enter some datas via DEMO_UART_NUM port...\n");
+ Uart1GpioCOnfig();
+ Sensor_init();
+ printf("Please wait for 60 seconds for the system to start...\n");
+ TaskMsleep(60000);
+ printf("Done!\n");
+
+ for (;;)
+ {
+ int isTimeOut = 0;
+
+ IoTGpioGetInputVal(human_detect_io, &value);
+
+ if(value == IOT_GPIO_VALUE1)
+ {
+ //get from cloud and send to 3516
+ IoTUartWrite(DEMO_UART_NUM, detect_flag, 5);
+ IoTSetMsgCallback(DemoMsgRcvsynchronize);
+ //start to work
+ feedback_1 = IoTUartWrite(DEMO_UART_NUM, detect_flag, 5);//
+ printf("uart feedback %d\n", feedback_1);
+
+ //TaskMsleep(20);
+ uartDefConfig.g_uartLen = IoTUartRead(DEMO_UART_NUM, uartBuff, UART_BUFF_SIZE);
+ int waitCount = 0;
+ while (!((uartDefConfig.g_uartLen > 0) && (uartBuff[0] == 0xaa) && (uartBuff[1] == 0x55))) {
+ uartDefConfig.g_uartLen = IoTUartRead(DEMO_UART_NUM, uartBuff, UART_BUFF_SIZE);
+ TaskMsleep(50);
+ waitCount += 1;
+ if(waitCount > 400){
+ isTimeOut = 1;
+ printf("Timeout!\n");
+ break;
+ }
+
+ }
+ if(isTimeOut)
+ continue;
+ if (GetUartConfig(UART_RECEIVE_FLAG) == HI_FALSE) {
+ (void)memcpy_s(uartDefConfig.g_receiveUartBuff, uartDefConfig.g_uartLen,
+ uartBuff, uartDefConfig.g_uartLen);/*uartBuff中的信息放到uartDefConfig.g_receiveUartBuff*/
+ (void)SetUartRecvFlag(UART_RECV_TRUE);
+ }
+ printf("UART start\n");
+ printf("len:%d\n", uartDefConfig.g_uartLen);
+ recBuff = (char*)malloc(uartDefConfig.g_uartLen-3);
+
+ for (int i = 0; i
+#include
+#include
+
+static void *cJsonMalloc(size_t sz)
+{
+ return hi_malloc(0, sz);
+}
+
+static void cJsonFree(const char *p)
+{
+ hi_free(0, p);
+}
+
+void cJsonInit(void)
+{
+ cJSON_Hooks hooks;
+ hooks.malloc_fn = cJsonMalloc;
+ hooks.free_fn = cJsonFree;
+ cJSON_InitHooks(&hooks);
+
+ return;
+}
\ No newline at end of file
diff --git a/src/applications/sample/wifi-iot/app/core/hal_iot_gpio_ex.c b/src/applications/sample/wifi-iot/app/core/hal_iot_gpio_ex.c
new file mode 100644
index 0000000..68121d9
--- /dev/null
+++ b/src/applications/sample/wifi-iot/app/core/hal_iot_gpio_ex.c
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "iot_errno.h"
+#include "iot_gpio_ex.h"
+#include "hi_gpio.h"
+#include "hi_io.h"
+#include "hi_task.h"
+#include "hi_types_base.h"
+
+
+unsigned int IoSetPull(unsigned int id, IotIoPull val)
+{
+ if (id >= HI_GPIO_IDX_MAX) {
+ return IOT_FAILURE;
+ }
+ return hi_io_set_pull((hi_io_name)id, (hi_io_pull)val);
+}
+
+unsigned int IoSetFunc(unsigned int id, unsigned char val)
+{
+ if (id >= HI_GPIO_IDX_MAX) {
+ return IOT_FAILURE;
+ }
+ return hi_io_set_func((hi_io_name)id, val);
+}
+
+/*unsigned int TaskMsleep(unsigned int ms)
+{
+ if (ms <= 0) {
+ return IOT_FAILURE;
+ }
+ return hi_sleep((hi_u32)ms);
+}*/
\ No newline at end of file
diff --git a/src/applications/sample/wifi-iot/app/core/hisignalling_protocol.c b/src/applications/sample/wifi-iot/app/core/hisignalling_protocol.c
new file mode 100644
index 0000000..d55f4bb
--- /dev/null
+++ b/src/applications/sample/wifi-iot/app/core/hisignalling_protocol.c
@@ -0,0 +1,286 @@
+/*
+ * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include "ohos_init.h"
+#include "cmsis_os2.h"
+#include "iot_gpio_ex.h"
+#include "hi_io.h"
+#include "iot_gpio.h"
+#include "hisignalling_protocol.h"
+
+#define LED_TEST_GPIO 9
+#define LED_INTERVAL_TIME_US 300000
+
+hi_u8 g_sendUartBuff[UART_BUFF_SIZE];
+
+UartDefConfig recConfig = {0};
+
+/*
+ * crc32 Verification implementation
+*/
+static const unsigned int crc32table[] = {
+ 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL,
+ 0x076dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L,
+ 0x0edb8832L, 0x79dcb8a4L, 0xe0d5e91eL, 0x97d2d988L,
+ 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, 0x90bf1d91L,
+ 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
+ 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L,
+ 0x136c9856L, 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL,
+ 0x14015c4fL, 0x63066cd9L, 0xfa0f3d63L, 0x8d080df5L,
+ 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L, 0xa2677172L,
+ 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
+ 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L,
+ 0x32d86ce3L, 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L,
+ 0x26d930acL, 0x51de003aL, 0xc8d75180L, 0xbfd06116L,
+ 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L, 0xb8bda50fL,
+ 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
+ 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL,
+ 0x76dc4190L, 0x01db7106L, 0x98d220bcL, 0xefd5102aL,
+ 0x71b18589L, 0x06b6b51fL, 0x9fbfe4a5L, 0xe8b8d433L,
+ 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL, 0xe10e9818L,
+ 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
+ 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL,
+ 0x6c0695edL, 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L,
+ 0x65b0d9c6L, 0x12b7e950L, 0x8bbeb8eaL, 0xfcb9887cL,
+ 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L, 0xfbd44c65L,
+ 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
+ 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL,
+ 0x4369e96aL, 0x346ed9fcL, 0xad678846L, 0xda60b8d0L,
+ 0x44042d73L, 0x33031de5L, 0xaa0a4c5fL, 0xdd0d7cc9L,
+ 0x5005713cL, 0x270241aaL, 0xbe0b1010L, 0xc90c2086L,
+ 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
+ 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L,
+ 0x59b33d17L, 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL,
+ 0xedb88320L, 0x9abfb3b6L, 0x03b6e20cL, 0x74b1d29aL,
+ 0xead54739L, 0x9dd277afL, 0x04db2615L, 0x73dc1683L,
+ 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
+ 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L,
+ 0xf00f9344L, 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL,
+ 0xf762575dL, 0x806567cbL, 0x196c3671L, 0x6e6b06e7L,
+ 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL, 0x67dd4accL,
+ 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
+ 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L,
+ 0xd1bb67f1L, 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL,
+ 0xd80d2bdaL, 0xaf0a1b4cL, 0x36034af6L, 0x41047a60L,
+ 0xdf60efc3L, 0xa867df55L, 0x316e8eefL, 0x4669be79L,
+ 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
+ 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL,
+ 0xc5ba3bbeL, 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L,
+ 0xc2d7ffa7L, 0xb5d0cf31L, 0x2cd99e8bL, 0x5bdeae1dL,
+ 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL, 0x026d930aL,
+ 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
+ 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L,
+ 0x92d28e9bL, 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L,
+ 0x86d3d2d4L, 0xf1d4e242L, 0x68ddb3f8L, 0x1fda836eL,
+ 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L, 0x18b74777L,
+ 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
+ 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L,
+ 0xa00ae278L, 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L,
+ 0xa7672661L, 0xd06016f7L, 0x4969474dL, 0x3e6e77dbL,
+ 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L, 0x37d83bf0L,
+ 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
+ 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L,
+ 0xbad03605L, 0xcdd70693L, 0x54de5729L, 0x23d967bfL,
+ 0xb3667a2eL, 0xc4614ab8L, 0x5d681b02L, 0x2a6f2b94L,
+ 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL, 0x2d02ef8dL
+};
+
+static unsigned int crc32(const unsigned char *buf, unsigned int len)
+{
+ unsigned int i, crc = 0xFFFFFFFF;
+
+ for (i = 0; i < len; i++) {
+ crc = crc32table[(crc ^ buf[i]) & 0xff] ^ (crc >> 8); /* 8: right move 8 bit */
+ }
+ return crc ^ 0xFFFFFFFF;
+}
+/* Log level look up table */
+static const char *hisignallingLevelNames[] = {
+ "TRACE",
+ "DEBUG",
+ "INFO",
+ "WARN",
+ "ERROR",
+ "FATAL"
+};
+/* get hisignaling log level */
+const char *HisignallingLevelNum (HisignallingLogType hisignallingLevel)
+{
+ if (hisignallingLevel >= HISIGNALLING_LEVEL_MAX) {
+ return "NULL";
+ } else {
+ return hisignallingLevelNames[hisignallingLevel];
+ }
+}
+#define RIGHT_MOVE_8_BIT (8)
+#define RIGHT_MOVE_16_BIT (16)
+#define RIGHT_MOVE_24_BIT (24)
+/* hisignal Hi3861 message package */
+static hi_u32 HisignallingDataPackage(HisignallingProtocalType *buf, hi_u32 len, hi_u8 *hisignallingDataBuf)
+{
+ hi_u32 crcCheckSend = 0;
+ hi_u32 packageLen = 0;
+
+ memcpy_s(hisignallingDataBuf, HISGNALLING_MSG_FRAME_HEADER_LEN,
+ buf->frameHeader, HISGNALLING_MSG_FRAME_HEADER_LEN);
+ memcpy_s(&hisignallingDataBuf[HISGNALLING_MSG_FRAME_HEADER_LEN],
+ len, buf->hisignallingMsgBuf, len);
+ memcpy_s(&hisignallingDataBuf[HISGNALLING_MSG_FRAME_HEADER_LEN + len],
+ HISIGNALLING_MSG_HEADER_LEN, &(buf->endOfFrame), HISIGNALLING_MSG_HEADER_LEN);
+ crcCheckSend = crc32(hisignallingDataBuf, (len + HISIGNALLING_MSG_HEADER_TAIL_LEN));
+ hisignallingDataBuf[len + HISIGNALLING_MSG_HEADER_TAIL_LEN] =
+ (hi_u8) ((crcCheckSend & 0xff000000)>>RIGHT_MOVE_24_BIT);
+ hisignallingDataBuf[len + HISIGNALLING_MSG_HEADER_TAIL_LEN + 1] = /* 1: addr offset */
+ (hi_u8) ((crcCheckSend & 0x00ff0000)>>RIGHT_MOVE_16_BIT);
+ hisignallingDataBuf[len + HISIGNALLING_MSG_HEADER_TAIL_LEN + 2] = /* 2: addr offset */
+ (hi_u8) ((crcCheckSend & 0x0000ff00)>>RIGHT_MOVE_8_BIT);
+ hisignallingDataBuf[len + HISIGNALLING_MSG_HEADER_TAIL_LEN + 3] = /* 3: addr offset */
+ (hi_u8)crcCheckSend;
+ packageLen = len + HISIGNALLING_MSG_HEADER_TAIL_LEN + HISGNALLING_MSG_CRC32_LEN;
+ return packageLen;
+}
+
+/* hisignal Hi3861 message recevice */
+HisignallingErrorType HisignallingMsgReceive(hi_u8 *buf, hi_u32 len)
+{
+ hi_u32 crcCheckReceived = 0;
+ unsigned char testBuff[7] = {0xaa, 0x55, 0x0, 0x2, 0x0, 0x8, 0xff};
+ if (buf == HI_NULL && len > 0) {
+ HISIGNALLING_LOG_FATAL("received buf is null");
+ return HISGNALLING_RET_VAL_MAX;
+ }
+ printf("length:%u\n", len);
+
+ /* 校验crc */
+ if (len > HISGNALLING_MSG_CRC32_LEN) {
+ crcCheckReceived = crc32(buf, len - HISGNALLING_MSG_CRC32_LEN);
+ if (((hi_u8)((crcCheckReceived & 0xff000000)>>RIGHT_MOVE_24_BIT) != buf[len - 4]) && /* 4: addr offset */
+ ((hi_u8)((crcCheckReceived & 0x00ff0000)>>RIGHT_MOVE_16_BIT) != buf[len - 3]) && /* 3: addr offset */
+ ((hi_u8)((crcCheckReceived & 0x0000ff00)>>RIGHT_MOVE_8_BIT) != buf[len - 2]) && /* 2: addr offset */
+ ((hi_u8)crcCheckReceived != buf[len - 1])) {
+ HISIGNALLING_LOG_ERROR(": crc32 Verification failed!");
+ HISIGNALLING_LOG_ERROR(":crc_4=0x%x, crc_3=0x%x, crc_2=0x%x, crc_1=0x%x",
+ buf[len - 4], buf[len - 3], buf[len - 2], buf[len - 1]); /* 4,3,2,1 addr offset */
+ return HISIGNALLING_RET_VAL_ERROR;
+ }
+ }
+ IoTGpioSetOutputVal(LED_TEST_GPIO, 0);
+ usleep(LED_INTERVAL_TIME_US);
+ IoTGpioSetOutputVal(LED_TEST_GPIO, 1);
+ usleep(LED_INTERVAL_TIME_US);
+ /* 输出回显收到的数据 */
+ /*if ((buf[0] == HISIGNALLING_MSG_FRAME_HEADER_1) && (buf[1] == HISIGNALLING_MSG_FRAME_HEADER_2)) {
+ for (int i = 0; i < len; i++) {
+ HISIGNALLING_LOG_INFO("0x%x", buf[i]);
+ }
+ }*/
+ return HISIGNALLING_RET_VAL_CORRECT;
+}
+/* hisignal Hi3861 message send */
+hi_u32 HisignallingMsgSend(char *buf, hi_u32 dataLen)
+{
+ HisignallingProtocalType hisignallingMsg = {0};
+ hi_u8 hisignallingSendBuf[HISIGNALLING_MSG_BUFF_LEN] = {0};
+ hi_u32 hisignallingPackageLen = 0;
+ hi_u32 writeDataLen = 0;
+
+ hisignallingMsg.frameHeader[0]= HISIGNALLING_MSG_FRAME_HEADER_1;
+ hisignallingMsg.frameHeader[1]= HISIGNALLING_MSG_FRAME_HEADER_2;
+ (void)memcpy_s(hisignallingMsg.hisignallingMsgBuf, dataLen, buf, dataLen);
+ hisignallingMsg.endOfFrame = HISIGNALLING_MSG_FRAME_TAIL;
+
+ hisignallingPackageLen = HisignallingDataPackage(&hisignallingMsg, dataLen, hisignallingSendBuf);
+ if (!hisignallingPackageLen) {
+ HISIGNALLING_LOG_ERROR("hisignaling_data_package failed\r\n");
+ return HI_ERR_FAILURE;
+ }
+ if (*hisignallingSendBuf == NULL) {
+ HISIGNALLING_LOG_ERROR("hisignal send buf is null!\r\n");
+ return HI_ERR_FAILURE;
+ }
+ writeDataLen = IoTUartWrite(HI_UART_IDX_1, hisignallingSendBuf, hisignallingPackageLen);
+ if (!writeDataLen) {
+ HISIGNALLING_LOG_ERROR("hi_uart_write failed\r\n");
+ return HI_ERR_FAILURE;
+ }
+ return HI_ERR_SUCCESS;
+}
+
+int SetUartReceiveFlag(void)
+{
+ return recConfig.g_uartReceiveFlag;
+}
+
+hi_void *HisignallingMsgHandle(char *param)
+{
+ unsigned char *recBuff = NULL;
+ int len;
+
+ while (1) {
+ /*g_sendUartBuff清零*/
+ (void)memset_s(g_sendUartBuff, sizeof(g_sendUartBuff) / sizeof(g_sendUartBuff[0]),
+ 0x0, sizeof(g_sendUartBuff)/sizeof(g_sendUartBuff[0]));
+ /*GetUartConfig得到data的flag和length*/
+ if (GetUartConfig(UART_RECEIVE_FLAG) == HI_TRUE) {
+ /* 接收数据 */
+ HisignallingMsgReceive(GetUartReceiveMsg(), GetUartConfig(UART_RECVIVE_LEN));
+ /* 回显数据组包 */
+ if (GetUartConfig(UART_RECVIVE_LEN) > (HISGNALLING_MSG_CRC32_LEN + HISIGNALLING_MSG_HEADER_TAIL_LEN)) {
+ len = GetUartConfig(UART_RECVIVE_LEN);
+ recBuff = GetUartReceiveMsg();
+ for (int i = 0; i < len ; i++ ){
+ HISIGNALLING_LOG_INFO("0x%x", recBuff[i]);
+ }
+ printf("end\n");
+ (void)memcpy_s(g_sendUartBuff,
+ (GetUartConfig(UART_RECVIVE_LEN) - HISGNALLING_MSG_CRC32_LEN - HISIGNALLING_MSG_HEADER_TAIL_LEN),
+ &recBuff[HISGNALLING_MSG_FRAME_HEADER_LEN],
+ (GetUartConfig(UART_RECVIVE_LEN) - HISGNALLING_MSG_CRC32_LEN - HISIGNALLING_MSG_HEADER_TAIL_LEN));
+ /* 接收到Hi3516DV300数据后,发送回显 */
+ HisignallingMsgSend(g_sendUartBuff,
+ (GetUartConfig(UART_RECVIVE_LEN) - HISGNALLING_MSG_CRC32_LEN - HISIGNALLING_MSG_HEADER_TAIL_LEN));
+ }
+ (void)SetUartRecvFlag(UART_RECV_FALSE);
+ ResetUartReceiveMsg();
+ }
+ TaskMsleep(HISGNALLING_FREE_TASK_TIME);
+ }
+}
+
+hi_u32 HisignalingMsgTask(hi_void)
+{
+ hi_u32 ret = 0;
+ IoTGpioInit(LED_TEST_GPIO);
+ IoTGpioSetDir(LED_TEST_GPIO, IOT_GPIO_DIR_OUT);
+ osThreadAttr_t hisignallingAttr = {0};
+
+ hisignallingAttr.stack_size = HISIGNALLING_MSG_TASK_STACK_SIZE;
+ hisignallingAttr.priority = HISIGNALLING_MSG_TASK_PRIO;
+ hisignallingAttr.name = (hi_char*)"hisignal msg task";
+
+ if (osThreadNew((osThreadFunc_t)HisignallingMsgHandle, NULL, &hisignallingAttr) == NULL) {
+ HISIGNALLING_LOG_ERROR("Failed to create hisignaling msg task\r\n");
+ return HI_ERR_FAILURE;
+ }
+ return HI_ERR_SUCCESS;
+}
+//SYS_RUN(HisignalingMsgTask);
diff --git a/src/applications/sample/wifi-iot/app/core/hisignalling_protocol.h b/src/applications/sample/wifi-iot/app/core/hisignalling_protocol.h
new file mode 100644
index 0000000..efe68fa
--- /dev/null
+++ b/src/applications/sample/wifi-iot/app/core/hisignalling_protocol.h
@@ -0,0 +1,207 @@
+/*
+ * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HISIGNALLING_PROTOCOL_H
+#define HISIGNALLING_PROTOCOL_H
+#include
+#include
+#include
+#include
+#include
+/**
+* @brief : hisignalling Macro definition
+*/
+#define HISIGNALLING_MSG_HEADER_LEN (1)
+#define HISGNALLING_MSG_FRAME_HEADER_LEN (2)
+#define HISIGNALLING_MSG_HEADER_TAIL_LEN (3)
+#define HISGNALLING_MSG_CRC32_LEN (4)
+#define HISIGNALLING_MSG_PAYLOAD_INDEX (5)
+#define HISGNALLING_FREE_TASK_TIME (20)
+#define HISIGNALLING_MSG_TASK_PRIO (28)
+#define HISIGNALLING_UART_MSG_LEN (32)
+#define HISIGNALLING_MSG_BUFF_LEN (512)
+#define HISIGNALLING_MSG_TASK_STACK_SIZE (4096)
+
+/* hisgnalling protocol frame header and tail */
+#define HISIGNALLING_MSG_FRAME_HEADER_1 ((hi_u8)0xAA)
+#define HISIGNALLING_MSG_FRAME_HEADER_2 ((hi_u8)0x55)
+#define HISIGNALLING_MSG_FRAME_TAIL ((hi_u8)0xFF)
+/**
+* @brief Adapter plate selection
+* 使用时选择打开宏,使用外设扩展板打开#define BOARD_SELECT_IS_EXPANSION_BOARD这个宏
+* 使用Robot板自己定义#define BOARD_SELECT_IS_ROBOT_BOARD这个宏,注释掉#define BOARD_SELECT_IS_EXPANSION_BOARD
+**/
+
+#define BOARD_SELECT_IS_EXPANSION_BOARD
+#ifdef BOARD_SELECT_IS_EXPANSION_BOARD
+#define EXPANSION_BOARD
+#else
+#define ROBOT_BOARD
+#endif
+/**
+ * @brief:this defines for the log module, and HISIGNALING_LOG_TRACE/HISIGNALING_LOG_DEBUG...
+ * will not participate the compile in the release version
+ * */
+typedef enum {
+ HISIGNALLING_LEVEL_TRACE = 0,
+ HISIGNALLING_LEVEL_DEBUG,
+ HISIGNALLING_LEVEL_INFO,
+ HISIGNALLING_LEVEL_WARN,
+ HISIGNALLING_LEVEL_ERROR,
+ HISIGNALLING_LEVEL_FATAL,
+ HISIGNALLING_LEVEL_MAX
+} HisignallingLogType;
+/**
+ * @brief: use this function to get the hisignalling log level name
+ *
+ * @parameter[in]:level, the level to get
+ *
+ * @return: the mapped level name
+ * */
+const char *HisignallingLevelNum (HisignallingLogType hisignallingLevel);
+/**
+ * @brief: this is a weak function ,and you could rewrite one
+ *
+ * @param fmt: same use as the fmt for printf
+ *
+ * @param unfixed: same use for printf
+ *
+ * @return: don't care about it
+ *
+ * @attention: and the components should not call this function directly, you'd better
+ *
+ * call HISIGNALING_LOG groups
+ *
+ * */
+#define HISIGNALLING_PRINT(fmt, ...) \
+ do \
+ { \
+ printf(fmt, ##__VA_ARGS__); \
+ } while (0)
+
+#define HISIGNALLING_LOG(level, fmt, ...) \
+ do \
+ { \
+ HISIGNALLING_PRINT("<%s>, <%s>, <%d> "fmt" \r\n", \
+ HisignallingLevelNum((level)), __FUNCTION__, __LINE__, ##__VA_ARGS__); \
+ } while (0)
+
+#define HISIGNALLING_LOG_TRACE(fmt, ...) \
+ do \
+ { \
+ HISIGNALLING_LOG (HISIGNALLING_LEVEL_TRACE, fmt, ##__VA_ARGS__); \
+ } while (0)
+
+#define HISIGNALLING_LOG_DEBUG(fmt, ...) \
+ do \
+ { \
+ HISIGNALLING_LOG (HISIGNALLING_LEVEL_DEBUG, fmt, ##__VA_ARGS__); \
+ } while (0)
+
+#define HISIGNALLING_LOG_INFO(fmt, ...) \
+ do \
+ { \
+ HISIGNALLING_LOG (HISIGNALLING_LEVEL_INFO, fmt, ##__VA_ARGS__); \
+ } while (0)
+
+#define HISIGNALLING_LOG_WARN(fmt, ...) \
+ do \
+ { \
+ HISIGNALLING_LOG (HISIGNALLING_LEVEL_WARN, fmt, ##__VA_ARGS__); \
+ } while (0)
+
+#define HISIGNALLING_LOG_ERROR(fmt, ...) \
+ do \
+ { \
+ HISIGNALLING_LOG (HISIGNALLING_LEVEL_ERROR, fmt, ##__VA_ARGS__); \
+ } while (0)
+
+#define HISIGNALLING_LOG_FATAL(fmt, ...) \
+ do \
+ { \
+ HISIGNALLING_LOG (HISIGNALLING_LEVEL_FATAL, fmt, ##__VA_ARGS__); \
+ } while (0)
+/**
+ * @brief: use this hisignalling Transmission protocol frame format
+ *
+ * @param frameHeader: Transmission protocol frame header
+ *
+ * @param hisignallingMsgBuf: Transmission protocol frame buffer
+ *
+ * @param hisigallingMsgLen: Transmission protocol frame buffer len
+ *
+ * @param endOfFrame: Transmission protocol frame tail
+ *
+ * @param hisignallingCrc32Check: Transmission protocol crc32 check
+ *
+ * */
+typedef struct {
+ hi_u8 frameHeader[HISGNALLING_MSG_FRAME_HEADER_LEN];
+ hi_u8 hisignallingMsgBuf[HISIGNALLING_MSG_BUFF_LEN];
+ hi_u32 hisigallingMsgLen;
+ hi_u8 endOfFrame;
+ hi_u32 hisignallingCrc32Check;
+}HisignallingProtocalType;
+/**
+ * @brief: use this hisignalling return type
+ *
+ * @param HISIGNALLING_RET_VAL_CORRECT: return type is correct
+ *
+ * @param HISIGNALLING_RET_VAL_ERROR: return type is error
+ *
+ * @param HISIGNALLING_RET_VAL_ERROR: return type is unknown type
+ * */
+typedef enum {
+ HISIGNALLING_RET_VAL_CORRECT = 0,
+ HISIGNALLING_RET_VAL_ERROR,
+ HISGNALLING_RET_VAL_MAX
+}HisignallingErrorType;
+/**
+ * @brief: use this hisignalling sample:Access peripheral enumeration type
+ *
+ * @param MOTOR_GO_FORWARD: peripheral motor go forward
+ *
+ * @param MOTOR_GO_BACK: peripheral motor go back
+ *
+ * @param STEERING_ENGINE_MOVEMENT/STEERING_ENGINE_AND_MOTOR_MOVEMENT/STEERING_ENGINE_AND_MOTOR_STOP
+ * the same use for peripheral
+ * */
+typedef enum {
+ MOTOR_GO_FORWARD = 0,
+ MOTOR_GO_BACK,
+ STEERING_ENGINE_MOVEMENT,
+ STEERING_ENGINE_AND_MOTOR_MOVEMENT,
+ STEERING_ENGINE_AND_MOTOR_STOP,
+ TRASH_CAN_LID_OPEN,
+ TRASH_CAN_LID_COLSE
+}HisignallingDataType;
+/**
+* @brief:hisignalling protocal Function declaration
+**/
+hi_u32 hisignallingMsgTask(hi_void);
+/**
+* @brief:hisignalling uart message receive API
+* @param buf: uart receive buffer
+* @param len: uart receive buffer len
+*/
+HisignallingErrorType hisignallingMsgReceive(hi_u8 *buf, hi_u32 len);
+/**
+* @brief:hisignalling uart send API
+* @param buf: uart message send buffer
+* @param len: uart message send buffer len
+*/
+hi_u32 hisignallingMsgSend(hi_void *buf, hi_u32 dataLen);
+int SetUartReceiveFlag(void);
+#endif /* HISIGNALING_PROTOCOL_H */
\ No newline at end of file
diff --git a/src/applications/sample/wifi-iot/app/core/iot_config.h b/src/applications/sample/wifi-iot/app/core/iot_config.h
new file mode 100644
index 0000000..b307f05
--- /dev/null
+++ b/src/applications/sample/wifi-iot/app/core/iot_config.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IOT_CONFIG_H
+#define IOT_CONFIG_H
+
+//
+#include
+#include
+#include
+#include "md.h"
+#include "md_internal.h"
+
+#define CN_HMAC256_LEN_MAX (65)
+#define CN_HMAC256_LEN 32
+#define RIGHT_MOVE_BIT_4 (4)
+#define NUMBER_9 (9)
+#define DECIMAL_BASE (10)
+#define STRING_LEN_TIMES (2)
+#define LEN_TIMES (2)
+#define OFFSET (1)
+// make a byte to 2 ascii hex
+static int byte2hexstr(unsigned char *bufin, int len, char *bufout)
+{
+ int i = 0;
+ unsigned char tmp_l = 0x0;
+ unsigned char tmp_h = 0;
+ if ((bufin == NULL)||(len <= 0)||(bufout == NULL)) {
+ return -1;
+ }
+ for (i = 0; i < len; i++) {
+ tmp_h = (bufin[i] >> RIGHT_MOVE_BIT_4) & 0X0F;
+ tmp_l = bufin[i] & 0x0F;
+ bufout[STRING_LEN_TIMES * i] = (tmp_h > NUMBER_9) ?
+ (tmp_h - DECIMAL_BASE + 'a'):(tmp_h +'0');
+ bufout[STRING_LEN_TIMES * i + OFFSET] = (tmp_l > NUMBER_9) ?
+ (tmp_l - DECIMAL_BASE + 'a'):(tmp_l +'0');
+ }
+ bufout[STRING_LEN_TIMES * len] = '\0';
+
+ return 0;
+}
+
+int HmacGeneratePwd(const unsigned char *content, int contentLen, const unsigned char *key,
+ int keyLen, unsigned char *buf)
+{
+ int ret = -1;
+ mbedtls_md_context_t mbedtls_md_ctx;
+ const mbedtls_md_info_t *md_info;
+ unsigned char hash[CN_HMAC256_LEN];
+
+ if ((key == NULL)||(content == NULL)||(buf == NULL)||
+ (keyLen == 0)||(contentLen == 0)||
+ (CN_HMAC256_LEN_MAX < (CN_HMAC256_LEN * LEN_TIMES + OFFSET))) {
+ return ret;
+ }
+
+ md_info = mbedtls_md_info_from_type(MBEDTLS_MD_SHA256);
+ if ((md_info == NULL)||((size_t)md_info->size > CN_HMAC256_LEN)) {
+ return ret;
+ }
+
+ mbedtls_md_init(&mbedtls_md_ctx);
+ ret = mbedtls_md_setup(&mbedtls_md_ctx, md_info, 1);
+ if (ret != 0) {
+ mbedtls_md_free(&mbedtls_md_ctx);
+ return ret;
+ }
+
+ (void)mbedtls_md_hmac_starts(&mbedtls_md_ctx, key, keyLen);
+ (void)mbedtls_md_hmac_update(&mbedtls_md_ctx, content, contentLen);
+ (void)mbedtls_md_hmac_finish(&mbedtls_md_ctx, hash);
+
+ //
+
+static EnIotLogLevel gIoTLogLevel = EN_IOT_LOG_LEVEL_TRACE;
+static const char *gIoTLogLevelNames[] = {
+ "TRACE",
+ "DEBUG",
+ "INFO ",
+ "WARN ",
+ "ERROR",
+ "FATAL"
+};
+
+int IoTLogLevelSet(EnIotLogLevel level)
+{
+ int ret = -1;
+ if (level < EN_IOT_LOG_LEVEL_MAX) {
+ gIoTLogLevel = level;
+ ret = 0;
+ }
+ return ret;
+}
+
+EnIotLogLevel IoTLogLevelGet(void)
+{
+ return gIoTLogLevel;
+}
+
+const char *IoTLogLevelGetName(EnIotLogLevel logLevel)
+{
+ if (logLevel >= EN_IOT_LOG_LEVEL_MAX) {
+ return "NULL ";
+ } else {
+ return gIoTLogLevelNames[logLevel];
+ }
+}
diff --git a/src/applications/sample/wifi-iot/app/core/iot_log.h b/src/applications/sample/wifi-iot/app/core/iot_log.h
new file mode 100644
index 0000000..a0532b7
--- /dev/null
+++ b/src/applications/sample/wifi-iot/app/core/iot_log.h
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef IOT_LOG_H_
+#define IOT_LOG_H_
+/**
+ * @brief:this defines for the log module,
+ * and IOT_LOG_TRACE/IOT_LOG_DEBUG will not participate the compile in the release version
+ *
+ *
+ * */
+typedef enum {
+ // < this is used as the trace function,like the function enter and function out
+ EN_IOT_LOG_LEVEL_TRACE = 0,
+ // < this is used as the debug, you could add any debug as you wish
+ EN_IOT_LOG_LEVEL_DEBUG,
+ // < which means it is import message, and you should known
+ EN_IOT_LOG_LEVEL_INFO,
+ // < this is used as the executed result,which means the status is not what we expected
+ EN_IOT_LOG_LEVEL_WARN,
+ // < this is used as the executed result,which means the status is not what we expected
+ EN_IOT_LOG_LEVEL_ERROR,
+ // < this is used as the parameters input for the api interface, which could not accepted
+ EN_IOT_LOG_LEVEL_FATAL,
+ EN_IOT_LOG_LEVEL_MAX,
+}EnIotLogLevel;
+/**
+ * @brief:use this function to get the current output log
+ *
+ * @return: the current output mask log, defined by en_iot_log_level_t
+ * */
+EnIotLogLevel IoTLogLevelGet(void);
+/**
+ * @brief: use this function to get the debug level name
+ *
+ * @parameter[in]:level, the level to get
+ *
+ * @return: the mapped level name
+ * */
+const char *IoTLogLevelGetName(EnIotLogLevel logLevel);
+/**
+ * @brief:use this function to set the current output log
+ *
+ * @parameter[in] level:defined by en_iot_log_level_t
+ *
+ * @return: 0 success while -1 failed
+ * */
+int IoTLogLevelSet(EnIotLogLevel level);
+/*
+ * @brief: this is a weak function ,and you could rewrite one
+ *
+ * @param fmt: same use as the fmt for printf
+ *
+ * @param unfixed: same use for printf
+ *
+ * @return: don't care about it
+ *
+ * @attention: and the components should not call this function directly, you'd better
+ *
+ * call IOT_LOG groups
+ *
+ * */
+#ifndef IOT_PRINT
+#define IOT_PRINT(fmt, ...) \
+ do \
+ { \
+ printf(fmt, ##__VA_ARGS__); \
+ }while (0)
+#endif
+
+#ifdef CONFIG_LINKLOG_ENABLE
+
+#define IOT_LOG(level, fmt, ...) \
+ do \
+ { \
+ IOT_PRINT("[%s][%s] " fmt "\r\n", \
+ IoTLogLevelGetName((level)), __FUNCTION__, ##__VA_ARGS__); \
+ } while (0)
+
+#define IOT_LOG_TRACE(fmt, ...) \
+ do \
+ { \
+ if ((EN_IOT_LOG_LEVEL_TRACE) >= IoTLogLevelGet()) \
+ { \
+ IOT_LOG(EN_IOT_LOG_LEVEL_TRACE, fmt, ##__VA_ARGS__); \
+ } \
+ } while (0)
+
+#define IOT_LOG_DEBUG(fmt, ...) \
+ do \
+ { \
+ if ((EN_IOT_LOG_LEVEL_DEBUG) >= IoTLogLevelGet()) \
+ { \
+ IOT_LOG(EN_IOT_LOG_LEVEL_DEBUG, fmt, ##__VA_ARGS__); \
+ } \
+ } while (0)
+
+#else
+#define IOT_LOG(level, fmt, ...)
+#define IOT_LOG_TRACE(fmt, ...)
+#define IOT_LOG_DEBUG(fmt, ...)
+#endif
+
+#define IOT_LOG_TRACE(fmt, ...) IOT_LOG(EN_IOT_LOG_LEVEL_TRACE, fmt, ##__VA_ARGS__)
+#define IOT_LOG_INFO(fmt, ...) IOT_LOG(EN_IOT_LOG_LEVEL_INFO, fmt, ##__VA_ARGS__)
+#define IOT_LOG_WARN(fmt, ...) IOT_LOG(EN_IOT_LOG_LEVEL_WARN, fmt, ##__VA_ARGS__)
+#define IOT_LOG_ERROR(fmt, ...) IOT_LOG(EN_IOT_LOG_LEVEL_ERROR, fmt, ##__VA_ARGS__)
+#define IOT_LOG_FATAL(fmt, ...) IOT_LOG(EN_IOT_LOG_LEVEL_FATAL, fmt, ##__VA_ARGS__)
+
+#endif /* IOT_LOG_H_ */
\ No newline at end of file
diff --git a/src/applications/sample/wifi-iot/app/core/iot_main.c b/src/applications/sample/wifi-iot/app/core/iot_main.c
new file mode 100644
index 0000000..8bdb873
--- /dev/null
+++ b/src/applications/sample/wifi-iot/app/core/iot_main.c
@@ -0,0 +1,333 @@
+/*
+ * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * STEPS:
+ * 1, CONNECT TO THE IOT SERVER
+ * 2, SUBSCRIBE THE DEFAULT TOPIC
+ * 3, WAIT FOR ANY MESSAGE COMES OR ANY MESSAGE TO SEND
+*/
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include "iot_config.h"
+#include "iot_log.h"
+#include "iot_hmac.h"
+#include "ohos_init.h"
+#include "cmsis_os2.h"
+#include "iot_watchdog.h"
+#include "MQTTClient.h"
+#include "iot_errno.h"
+#include "iot_main.h"
+#include "iot_gpio.h"
+
+
+// < this is the configuration head
+#define CN_IOT_SERVER "tcp://106.55.124.154:1883" // Tencent iot cloud address
+#define CONFIG_COMMAND_TIMEOUT 10000L
+#define CN_KEEPALIVE_TIME 50
+#define CN_CLEANSESSION 1
+#define CN_HMAC_PWD_LEN 65 // < SHA256 IS 32 BYTES AND END APPEND '\0'
+#define CN_EVENT_TIME "1970000100"
+#define CN_CLIENTID_FMT "%s_0_0_%s" // < This is the cient ID format, deviceID_0_0_TIME
+#define CN_QUEUE_WAITTIMEOUT 1000
+#define CN_QUEUE_MSGNUM 16
+#define CN_QUEUE_MSGSIZE (sizeof(hi_pvoid))
+
+#define CN_TASK_PRIOR 28
+#define CN_TASK_STACKSIZE 0X2000
+#define CN_TASK_NAME "IoTMain"
+#define Signal_LED_IO 12
+
+typedef enum {
+ EN_IOT_MSG_PUBLISH = 0,
+ EN_IOT_MSG_RECV,
+}EnIotMsg;
+
+typedef struct {
+ EnIotMsg type;
+ int qos;
+ const char *topic;
+ const char *payload;
+}IoTMsg_t;
+
+typedef struct {
+ bool stop;
+ unsigned int conLost;
+ unsigned int queueID;
+ unsigned int iotTaskID;
+ fnMsgCallBack msgCallBack;
+ MQTTClient_deliveryToken tocken;
+}IotAppCb_t;
+static IotAppCb_t gIoTAppCb;
+
+static const char *gDefaultSubscribeTopic[] = {
+ /* Tencent iot cloud topic */
+ "YT32IOSCAL/Hi38611_mqtt/data",
+ "YT32IOSCAL/Hi38611_mqtt/event",
+ "YT32IOSCAL/Hi38611_mqtt/control",
+};
+
+#define CN_TOPIC_SUBSCRIBE_NUM (sizeof(gDefaultSubscribeTopic) / sizeof(const char *))
+static int MsgRcvCallBack(char *context, char *topic, int topicLen, MQTTClient_message *message)
+{
+ IoTMsg_t *msg;
+ char *buf;
+ unsigned int bufSize;
+ int topiLen = topicLen;
+
+ if (topiLen == 0) {
+ topiLen = strlen(topic);
+ }
+ bufSize = topiLen + 1 + message->payloadlen + 1 + sizeof(IoTMsg_t);
+ buf = hi_malloc(0, bufSize);
+ if (buf != NULL) {
+ msg = (IoTMsg_t *)buf;
+ buf += sizeof(IoTMsg_t);
+ bufSize -= sizeof(IoTMsg_t);
+ msg->qos = message->qos;
+ msg->type = EN_IOT_MSG_RECV;
+ (void)memcpy_s(buf, bufSize, topic, topiLen);
+ buf[topiLen] = '\0';
+ msg->topic = buf;
+ buf += topiLen + 1;
+ bufSize -= (topiLen + 1);
+ (void)memcpy_s(buf, bufSize, message->payload, message->payloadlen);
+ buf[message->payloadlen] = '\0';
+ msg->payload = buf;
+ IOT_LOG_DEBUG("RCVMSG:QOS:%d TOPIC:%s PAYLOAD:%s\r\n", msg->qos, msg->topic, msg->payload);
+ if (IOT_SUCCESS != osMessageQueuePut(gIoTAppCb.queueID, &msg, 0, CN_QUEUE_WAITTIMEOUT)) {
+ IOT_LOG_ERROR("Wrie queue failed\r\n");
+ hi_free(0, msg);
+ }
+ }
+
+ MQTTClient_freeMessage(&message);
+ MQTTClient_free(topic);
+ return 1;
+}
+
+// < when the connect lost and this callback will be called
+static void ConnLostCallBack(char *context, char *cause)
+{
+ IOT_LOG_DEBUG("Connection lost:caused by:%s\r\n", cause == NULL? "Unknown" : cause);
+ return;
+}
+
+static int MqttProcessQueueMsg(MQTTClient client, IoTMsg_t *msg, MQTTClient_message pubMsg)
+{
+ int ret = 0;
+
+ switch (msg->type) {
+ case EN_IOT_MSG_PUBLISH:
+ pubMsg.payload = (void *)msg->payload;
+ pubMsg.payloadlen = (int)strlen(msg->payload);
+ pubMsg.qos = msg->qos;
+ pubMsg.retained = 0;
+ ret = MQTTClient_publishMessage(client, msg->topic, &pubMsg, &gIoTAppCb.tocken);
+ if (ret != MQTTCLIENT_SUCCESS) {
+ IOT_LOG_ERROR("MSGSEND:failed\r\n");
+ }
+ IOT_LOG_DEBUG("MSGSEND:SUCCESS\r\n");
+ gIoTAppCb.tocken++;
+ break;
+ case EN_IOT_MSG_RECV:
+ if (gIoTAppCb.msgCallBack != NULL) {
+ gIoTAppCb.msgCallBack(msg->qos, msg->topic, msg->payload); /*接受信息并进行相应的操作,函数体在IoTSetMsgCallback中定义*/
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+//