project instruction

Based on OpenAtom OpenHarmony (hereinafter referred to as "OpenHarmony"), digital housekeeper develops dormitory whole house intelligence, realizes touch to open doors, touch to turn on lights, touch to turn on fans and smoke detection. Because the development process of each project is generally similar, this article mainly takes Touch Touch Door as an example to introduce how to implement the functions we want on the basis of the existing OpenHarmony open source code.
Equipment that needs to be prepared in advance: a mobile phone equipped with HarmonyOS system, API 6+; a motherboard equipped with Hi3861 module, not limited to HiSpark and bear pie kits; 7.4V battery, a servo, and several wires. The final touch to open the door, turn on the lights, and the fan effect is as follows:

The three data flows of smart desk lamp and fan (including door lock), digital housekeeper application, and cloud platform are shown in the figure below. The digital housekeeper application sends device control commands such as wind speed and brightness adjustment to the cloud platform, and the cloud platform sends it to the designated device. At the same time, devices such as fans and desk lamps report the current status to the cloud platform, and the cloud platform sends it to the digital housekeeper application to realize user visualization operations. , real-time control of smart devices.

Development process <br>The project mainly includes: ①Building the device-side development environment, ②Digital housekeeper installation, ③Configuring NFC tags, ④Practical verification, a total of four parts. The key links in the development process are shown in the following figure. The overall idea is to prepare the software and hardware environment, write business codes, and burn test. If you encounter problems during development, you can refer to this figure for troubleshooting.

The development environment is mainly divided into two parts: the device-end environment and the digital housekeeper. The device side uses the latest version of DevEco Device Tools, which is developed on the ubuntu platform. In this project, the tool is used to edit the source code and download the binary files; the digital housekeeper uses DevEco Studio Beta3.1 and above to develop on the windows platform.

Build a device-side development environment

DevEco Device Tools Construction <br>The first step is to build a device-side development environment in the Ubuntu20.04 system, which supports one-stop development of source code editing, compiling, and downloading. Build DevEco Device Tools on the Ubuntu system, and refer to the development environment preparation for the detailed construction process ( https://docs.openharmony.cn/pages/v3.1/zh-cn/device-dev/quick-start/quickstart-ide-lite- env-setup-win-ubuntu.md/ ).
The second step is to install the compilation toolchain, the Hi3861V100 development board Ubuntu environment toolchain download link gn, ninja, gcc_riscv32.

The rest refer to Toolchain Management. After adding the tool, the picture is as follows:

Ubuntu environment compilation tool preparation

 // A.基础依赖         sudo apt-get install -y build-essential gcc g++ make zlib* libffi-dev  // -安装 scons  python3 -m pip install scons  // -查看版本,3.0.4以上  scons -v // B.安装python模块  sudo pip3 install setuptools kconfiglib pycryptodome ecdsa six --upgrade --ignore-installed six// C.添加gcc_riscv32(WLAN模组类编译工具链) 在安装DevEco Device Tools时已经下载  // -解压到根目录  tar -xvf gcc_riscv32-linux-7.3.0.tar.gz -C ~  // -添加环境变量  vim ~/.bashrc  // -最后一行加入:export PATH=~/gcc_riscv32/bin:$PATH  // -确认安装是否正常,有返回版本号即可。riscv32-unknown-elf-gcc -v

Device side source code download
The first step is to install the code cloud tool

 cd ~
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

The second step is to obtain the source code. OpenHarmony version 1.0.1

 mkdir ~/OpenHarmony1.01
cd ~/OpenHarmony1.01
repo init -u git@gitee.com:openharmony/manifest.git -b OpenHarmony_1.0.1_release --no-repo-verify
repo sync -c
repo forall -c 'git lfs pull'

Obtain relevant product solutions and copy them to the source code. The specific operations are as follows:

 //下载产品解决方案到ubuntu,解压在非中文路径下即可。下载链接为:
https://gitee.com/openharmony-sig/knowledge_demo_smart_home 
//拷贝解决方案
cp -rfa  ~/knowledge_demo_smart_home/dev/device/bearpi  ~/OpenHarmony1.01/device/ 
cp -rfa  ~/knowledge_demo_smart_home/dev/team_x  ~/OpenHarmony1.01/vendor/
cp -rfa  ~/knowledge_demo_smart_home/dev/third_party/iot_link  ~/OpenHarmony1.01/third_party/

The third step (optional, if using the HiSpark kit, it needs to be modified)

 //1.修改usr_config.mk 文件
路径:device/hisilicon/hispark_pegasus/sdk_liteos/build/config/usr_config.mk
使能如下配置项
CONFIG_I2C_SUPPORT=y
CONFIG_PWM_SUPPORT=y
//2.修改wifiservice 文件夹 
路径:device/hisilicon/hispark_pegasus/hi3861_adapter/hals/communication/wifi_lite/wifiservice/source/wifi_hotspot.c
EnableHotspot函数中屏蔽如下字段
139行     //if (SetHotspotIpConfig() != WIFI_SUCCESS) {
140行     //    return ERROR_WIFI_UNKNOWN;
141行     //}
//3.DispatchConnectEvent函数下 屏蔽StaSetWifiNetConfig相关代码行
路径:device/hisilicon/hispark_pegasus/hi3861_adapter/hals/communication/wifi_lite/wifiservice/source/wifi_device.c
239行         //StaSetWifiNetConfig(HI_WIFI_EVT_CONNECTED);
260行        //StaSetWifiNetConfig(HI_WIFI_EVT_DISCONNECTED);

The fourth step , to install the ohos-build tool needs to be compiled with ohos-build 0.2.0 version. In the root directory of the OpenHarmony 1.0.1 source code, execute:

 pip3 install build/lite
// 添加环境变量
vim ~/.bashrc
export PATH=~/.local/bin:$PATH
source ~/.bashrc
// 然后执行
hb -h

Return the following information for correct installation:

The fifth step , open the project Open the DevEco Device Tools under Visual Studio Code, import the 1.0.1 project and select the corresponding development board. Open the terminal, cd to the source code path, execute hb set, select smart_lamp, and then execute hb build to compile.

Generating Hi3861_wifiiot_app_allinone.bin under ~/openharmony1.01/out/bearpi_hm_nano/smart_lamp shows that everything is operating normally. If you encounter problems such as uninstall clang, not found gn, ninja, etc., you need to configure environment variables and check whether ohos-build is version 0.2.0. Specifically, you can refer to the following measures summarized by individuals:

The sixth step , burn the binary file to connect the development board to the computer USB, click on the configuration project in DevEco Device Tools, and set the serial port number, as shown in the following figure:

Then copy the Hi3861_wifiiot_app_allinone.bin generated in the fifth step to ~/openharmony1.01/out/hispark_pegasus/wifiiot_hispark_pegasus [because the tool downloads the bin file in this path by default] Click upload under Project Task, and press reset on the board. Burnable.

device-side compilation

In Section 1.3, we just put the open source code in our notebook. To realize the door opening, we need to add our own business code. For example, the door lock needs to use the servo, and I modified it based on the smart_lamp solution. The specific operations are as follows:
The first step, add servo control <br>Open the vendor/team_x/smart_lamp/demo_smartlamp/E53_SC1/E53_SC1.c file that operates GPIO and add the following functions:

 /* @brief  Servo  control *
 @param angle  input value: 0-200 *              
*/
void My_servo(int angle)
{       
     int j=0;   
     int k=20000/200; //实际应该是20000/180
     angle = k*angle;   
     for (j=0;j<5;j++)
      {     
           GpioSetOutputVal(servoID, 1);        
           hi_udelay(angle); //angle ms     
           GpioSetOutputVal(servoID, 0);        
           hi_udelay(20000-angle);//    
       }//20ms 控制舵机

The second step , add a statement to initialize GPIO 10

 #define SERVO_1_GPIO 10
int E53SC1_InitMainLed(void)
{
    IoTGpioInit(CN_MAIN_LED_GPIO);
    IoTGpioSetFunc(CN_MAIN_LED_GPIO, CN_MAIN_LED_GPIO_FUNC);
    IoTGpioSetDir(CN_MAIN_LED_GPIO, IOT_GPIO_DIR_OUT);
    IoTPwmInit(CN_MAIN_LED_PWDOUT);
    
    IoTGpioInit(SERVO_1_GPIO);
    IoTGpioSetFunc(SERVO_1_GPIO,  IOT_GPIO_FUNC_GPIO_10_GPIO);
    IoTGpioSetDir(SERVO_1_GPIO,  IOT_GPIO_DIR_OUT);
    return 0;
}

The third step , add business code

 int E53SC1_SetMainLed(int status, int dutyCycle)
{
    int ret = 0;
    if (status == CN_BOARD_SWITCH_ON) {
        ret = IoTPwmStart(CN_MAIN_LED_PWDOUT, dutyCycle, CN_MAIN_LED_FRE);
        My_servo(1000); //开门
    } else {
        ret = IoTPwmStop(CN_MAIN_LED_PWDOUT);
        My_servo(10000); //上锁
    }
    RaiseLog(LOG_LEVEL_INFO, "status=%d, dutyCycle=%d, ret = %d", status, dutyCycle, ret);
    return 0;
}

The fourth step, compile and download <br>Refer to the fifth and sixth steps in Section 1.3, and compile directly without importing the project again. Because I am using an ubuntu physical machine, I specially installed DevEco Device tools for one-stop development. OpenHarmony 2.0 and 3.0 versions can be compiled without hb tools. After the burning is completed, press the reset button of the board, and the mobile phone can find the WIFI signal teamX-Lamp01 sent by the module.

Digital butler installation

DevEco Studio Installation <br>The first step is to download and install DevEco Studio. After installation, configure the Windows environment variables (reference: https://docs.openharmony.cn/pages/v3.1/zh-cn/application-dev/ quick-start/start-overview.md/ ). The second step is to open the SDK Manager under the DevEco Studio settings. To install the SDK (API6), everything in the red box needs to be downloaded. It is worth noting that the OpenHarmony SDK will be downloaded when the Studio is installed in the first step. The SDK in the second step is different and cannot be in the same path, otherwise the original one will be replaced.

Digital butler APP source code acquisition

The digital housekeeper is compiled and installed on the mobile phone on the windows platform. The download link is: https://gitee.com/openharmony-sig/knowledge_demo_smart_home After downloading, unzip it in a non-Chinese path.

图片

Use DevEco Studio to open the digital housekeeper, the path is as follows:

图片

图片

Digital butler APP installation

The first step, click on your profile picture in the upper right corner and log in

图片

The second step , enter the AGC platform AGC (AppGallery Connect) address: https://developer.huawei.com/consumer/cn/service/josp/agc/index.html#/

图片

The third step is to create a project on the AGC platform, and then create an application

图片

图片

图片

Get the configuration as shown:

图片

The fourth step , go back to the project opened by DevEco Studio in the previous section, and modify three places. The specific paths are as follows:
./entry/src/config.json
./netconfig/src/main/config.json
./netconfig/src/main/js/default/pages/index/index.js

图片

图片

图片

The fifth step , automatic signature.
First connect your phone to the computer, open developer options -> enable USB debugging -> agree to debugging and then open DevEco Studio's file–Project Structure–Project–Signing Configs–automatically generate signing as shown below:

图片

The sixth step , compile and download.
Click on entry, enter debug configuration, check deploy multi haps packages under entry, and exit after confirmation. Because the digital housekeeper contains two modules, entry and netconfig, they must be installed at the same time.

图片

图片

Step 7 : Install the Digital Butler APP and click Run. After a while, the Digital Butler APP will appear on your phone, enter your phone number, and log in.

Configure NFC tags

Apply for product ID
Use the phone equipped with HarmonyOS, log in to your Huawei account, download and install the app commissioning assistant in the Huawei AppGallery, open and select NFC, and then apply.

图片

registration service
The first step is to log in to the Huawei Developer Alliance https://developer.huawei.com/consumer/cn/ , click the management center, and create an atomic service.

图片

The second step is to fill in according to the prompts. On the label configuration page, fill in the Product ID model 00 applied for in the application commissioning assistant. On the FA configuration page, be sure to check the package name written by yourself in the fourth step of Section 2.3. The module name is entry, and the added device is com.example.distschedule.AddDeviceAbility:

图片

The third step is to create a test and fill in the mobile phone number corresponding to the Huawei account.

图片

Write the tag <br> to open the application commissioning assistant, select the ID you applied for before, and fill in the following data in the custom box:
1246128c7b60ad1ed0286680f19206Lamp01308123456784011512teamX-Lamp01

图片

More device NFC tags

Practical verification

Door lock <br>Opening the door requires a simple device, there is a design before, refer to the hi3861 web terminal to open the door.

图片

The circuit is simple, the 7.4v power supply is bucked and regulated to supply power to the module and the servo respectively.

图片

Connect the mobile phone to wifi, turn on the NFC switch, and touch the label to evoke the atomization interface (cannot use the campus network, which will cause the device to fail to connect). The test effect is as follows:

图片

small fan
When hb set, you need to compile smart_fan. After downloading the source code, write the NFC tag.
1246150601d88056b027dd2ca47205Fan01308123456784011511teamX-Fan01
The drive circuit of the fan on hand is shown in the figure below, and the PWM controls the wind speed:

图片

Table lamp <br>First of all, it needs an electromagnetic relay, 5V charging head, which can supply power to the module and the table lamp at the same time (parallel). Initialize GPIO 9 as output in the lamp source code, and connect the signal terminal of the relay to GPIO 9. When the light is on, connect the NC-COM terminal of the relay and disconnect the NO-COM.

图片

图片

Epilogue

In essence, the above cases are still using the existing solution, the server implementation of the digital housekeeper, and even the operation UI of opening the door is a desk lamp. Although the icon can be modified in the digital housekeeper, the essence has not changed. The purpose of this tutorial is to record An introduction to the development of Digital Butler Touch, and add your own solutions and servers as a reference later. Learning reference link:

Equipment Development Fundamentals Course
https://www.openharmony.cn/courses?id=5#equipment
Application Development Department Courses
https://www.openharmony.cn/courses?id=5#application
Digital Butler Quick Start
https://gitee.com/openharmony-sig/knowledge_demo_smart_home/blob/master/dev/docs/quick_start/README.md

图片


OpenHarmony开发者
160 声望1.1k 粉丝

OpenHarmony是由开放原子开源基金会(OpenAtom Foundation)孵化及运营的开源项目,


引用和评论

0 条评论