Achievement display

1. Overall display

2. Touch the touchless distribution network

3. Alarm

Introduction

At present, the harm caused by gas leakage to residents' lives still occurs from time to time, but I believe that the Internet of Everything can effectively avoid such harm, so I designed a gas detection device based on OpenHarmony. The detection system can monitor the smoke concentration in the environment in real time, and when the carbon monoxide concentration exceeds the standard, it can send an alarm to the user in time. After the digital butler touches the network and cooperates with the digital butler application, the user can remotely configure the alarm threshold of the intelligent gas detection system, and remotely receive the alarm information of the intelligent gas detection system. In order to realize the timely alarm to the danger, deal with it in time, and protect the safety of the home.
1. Interaction method <br>As shown below, the overall scheme framework of the intelligent gas detection system can be divided into three parts: intelligent gas detection system equipment, digital housekeeper application, and cloud platform. The equipment end of the intelligent gas detection system communicates with the Huawei IOT IoT platform according to the MQTT protocol. When the concentration of carbon monoxide at the monitoring site of the intelligent gas system changes, the device reports the data to the cloud platform and finally synchronizes it to the digital housekeeper. When the concentration of carbon monoxide exceeds the threshold, an alarm will be issued, and the alarm information will also be reported to the cloud platform and finally synchronized to the digital housekeeper. Butler; when the user adjusts the alarm system threshold through the digital butler, the command data is first sent to the cloud platform, and then sent to the device side by the cloud platform.

2. The following figure is a more detailed frame diagram

materials needed

1. The basic environment <br> consists of a Windows workbench and a Linux compilation server. The Windows workbench can access the Linux compilation server through samba service or ssh. Among them, the Windows workbench is used for burning and code editing, and the Linux compilation server is used to compile the OpenHarmony code. In order to simplify the steps, the Linux compilation server recommends installing Ubuntu20.04.
Still need to download
VMware Workstation 16 Player
MobaXterm
RaiDrive
HiBurn
Link:
https://gitee.com/bearpi/bearpi-hm_nano/blob/master/applications/BearPi/BearPi-HM_Nano/docs/quick-start/BearPi-HM_Nano%E5%8D%81%E5%88%86%E9% 92%9F%E4%B8%8A%E6%89%8B.md
2. Hardware Preparation <br>Carbon Monoxide Gas Sensor (MQ7)
The bearpi_hm_nano development baseboard of the bear pie is pre-installed with a HarmonyOS mobile phone. We use the bearpi_hm_nano development base plate of the bear pie + MQ7 sensor expansion board to simulate the intelligent gas detection equipment. Obtain the carbon monoxide concentration value of the sensor through the ADC interface, and use the GPIO to control the buzzer to give an alarm; the reset button controls the device to restart; the reset button combined with the control button can clear the saved distribution network information. The specific operation: first press the control button F2, then press Press the reset button; through the NFC module, the device can quickly configure the network by touching the device;
3. Connection method <br>The connection between the bear pie nano universal base plate and the carbon monoxide gas sensor is shown in the physical picture, and the specific details are as follows:
Bear Pi nano universal baseboard V3.3 Pin to carbon monoxide gas sensor VCC Pin;
The bear pie nano universal base plate GND Pin is connected to the carbon monoxide gas sensor GND Pin;
Bear Pi nano universal baseboard GPIO_13 Pin to carbon monoxide gas sensor AO Pin;
4. Real pictures

Configure the environment to download the source code

Environment Configuration Install and configure Python

  1. Open a Linux terminal.
  2. Enter the following command to check the python version number, you need to use python3.7 or above, otherwise refer to
    https://gitee.com/openharmony/docs/blob/OpenHarmony_1.0.1_release/en-us/device-dev/quick-start/%E6%90%AD%E5%BB%BA%E7%B3%BB% E7%BB%9F%E5%9F%BA%E7%A1%80%E7%8E%AF%E5%A2%83.md
    python3 –version
  3. Install and upgrade the Python package management tool (pip3).
 sudo apt-get install python3-setuptools python3-pip -y
sudo pip3 install --upgrade pip

install hb

  1. Run the following command to install hb
    python3 -m pip install --user ohos-build
  2. Set environment variables
 vim ~/.bashrc
   将以下命令拷贝到.bashrc文件的最后一行,保存并退出。
   export PATH=~/.local/bin:$PATH
   执行如下命令更新环境变量。
   source ~/.bashrc
  1. Execute "hb -h", if the following information is printed, the installation is successful.
 usage: hb
   OHOS build system
   positional arguments:
     {build,set,env,clean}
       build               Build source code
       set                 OHOS build settings
       env                 Show OHOS build env
       clean               Clean output
 
   optional arguments:
     -h, --help            show this help message and exit

Configuring 3861 Development Environment Preparation <br>After setting up the basic development environment on the Linux compilation server, you need to install OpenHarmony to compile the development environment specific to the Hi3861 platform.
Install and compile dependent basic software
sudo apt-get install -y build-essential gcc g++ make zlib* libffi-dev
Install Scons

  1. Open a Linux terminal.
  2. Run the following command to install the Scons installation package.
    python3 -m pip install scons
  3. Run the following command to check if the installation is successful. If the installation is successful, the query result is shown in the following figure.
    scons -v
    The following figure shows the successful installation of Scons interface, the version requires 3.0.4 or above

    install python module
    sudo pip3 install setuptools kconfiglib pycryptodome ecdsa six --upgrade --ignore-installed six
    Install gcc_riscv32 (WLAN module class compilation toolchain)
  4. Open a Linux terminal.
  5. Download the gcc_riscv32 image
    https://repo.huaweicloud.com/harmonyos/compiler/gcc_riscv32/7.3.0/linux/gcc_riscv32-linux-7.3.0.tar.gz
  6. Set the environment variable to extract the archive to the root directory
    tar -xvf gcc_riscv32-linux-7.3.0.tar.gz -C ~
    Set environment variables.
    vim ~/.bashrc
    Copy the following command to the last line of the .bashrc file, save and exit.
    export PATH=~/gcc_riscv32/bin:$PATH
    Take effect of environment variables.
    source ~/.bashrc
  7. Enter the following command on the command line. If the compiler version number is displayed correctly, the compiler installation is successful.
    riscv32-unknown-elf-gcc -v
    Code download & compilation preparation
    1. Download the code cloud tool
    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

2. Code download Special attention for OpenHarmony code download: please download OpenHarmony 1.0.1 version, and will update to support other versions of OpenHarmony in the future
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'

Device side code download specific warehouse address:
https://gitee.com/openharmony-sig/knowledge_demo_smart_home/
Download method 1: Directly download the corresponding zip package file of the warehouse Download method 2: After forking the knowledge_demo_smart_home warehouse, use the git command to download
git clone git@gitee.com :xxxxxxx/knowledge_demo_smart_home.git // Where xxxxxxx is the account name after fork.
Prepare <br>code copy before compiling

 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 directory structure after integration and modification is as follows:

Device-side code compilation and burning

1. Compile and compile the command:
In the OpenHarmony directory hb set If it is the first compilation, type "./" in the Input code path command line to specify the OpenHarmony project compilation root directory and press Enter.
As shown in the figure below, use the up and down keys on the keyboard to select the intelligent gas detection system

build // If you need full compilation, you can add the -f option

  1. Burn the compiled code in

    Open the smart_co_detection file to see the compiled code

    Map the files on Linux to windows through the RaiDrive tool, then burn Hi3861_wifiiot_app_allinone.bin to the development board through HiBurn, and link the development board to the computer through Type-c. Right-click the computer, click Device Manager, and click the port to view the development board Connect to a port on your computer.

    Open HiBurn Set Port Set COM to the port viewed in the previous step

    Click Setting to set the parameter to set Baud to 115200

    Click Select file to select the compiled code, and burn Hi3861_wifiiot_app_allinone.bin to the development board. Click Auto burn, click Connect, and then click the reset button of the development board to wait for the burning to complete.

    Build a digital butler service

    1. Prepare the deployment environment
    Ubuntu18.04.4
    Mysql5.7
    https://blog.csdn.net/goog_man/article/details/108696063
    RabbitMQ:
    https://blog.csdn.net/weixin_33824363/article/details/92254998
    Maven3.6.3: Ubuntu18.04 installation Maven tutorial
    Jdk8: sudo apt-get install openjdk-8-jdk
    2. Apply for HUAWEI CLOUD AK/Sk
    https://activity.huaweicloud.com/newyear_promotion/index.html?utm_source=baidu&utm_medium=brand&utm_campaign=10056&utm_content=&utm_term=&utm_adplace=AdPlace024711
    Log in to HUAWEI CLOUD→Click Console→My Credentials→Access Key→Add Access Key


    3. Get APPID
    Device access → resource space → APPID

    4. Create a product


    After creating the product, click View and then click Custom Model

    View the specific configuration content
    https://gitee.com/openharmony-sig/knowledge_demo_smart_home/blob/master/profile/%E6%99%BA%E8%83%BD%E7%85%A4%E6%B0%94%E6%A3%80 %E6%B5%8B%E7%B3%BB%E7%BB%9Fprofile%E5%AE%9A%E4%B9%89.md
    5. Add rules

    6. Preset AMQP


    7. Open the digital butler to modify the configuration file
    server\distschedule-core\src\main\resources\application-local.properties

    8. Add sql file server\distschedule-dao\src\main\resources\db\migration
    Add at the end (Database V1__CreateTables) add content
    INSERT INTO device_type ( name , name_en , service_id , product_id , category )
    values ('Carbon Monoxide Gas Alarm', 'coSensation', 'SmartCoSensation', '61de758bc7fb24029b0be6f0', 3);
    9. Compile <br> into the directory
    cd knowledge_demo_smart_home/Server
    mvn clean package -Dmaven.test.skip=true
    The executable jar is packaged in
    knowledge_demo_smart_home/Server/distschedule-core/target/distschedule-core-1.0.0-SNAPSHOT.jar
    10. Start the service <br>Activate the local profile through the environment variable
    export SPRING_PROFILES_ACTIVE=local # Activate local
    Start command (modify according to the directory on your own virtual machine, use absolute path)
    java -jar /opt/distschedule-core-1.0.0-SNAPSHOT.jar --spring.profiles.active=local
    11. Check whether it is successful <br>successfully visit the following URL
    http://127.0.0.1:8080/distschedule-api/swagger-ui/index.html

    The digital housekeeper application runs on the real machine, and the network is distributed without any touch.
    https://gitee.com/openharmony-sig/knowledge_demo_smart_home/tree/master/FA/DistSchedule/docs/%E5%AD%A6%E7%94%9F%E5%85%9A%E4%B8%8A%E6 %89%8B%E6%95%B0%E5%AD%97%E7%AE%A1%E5%AE%B6

Summarize

The project theme comes from the OpenHarmony open source developer growth program. The whole process is still relatively complex, requiring the writing of the device-side code, the implementation of the FA-side code, the configuration of Huawei Cloud, and the construction of the digital butler server. During this process, I came into contact with many new knowledge points, such as quick network configuration with a touch, running on a real machine, and experiencing HUAWEI CLOUD-related operations, etc. OpenHarmony still needs many developers to build together in the future, let's work hard to promote the development of OpenHarmony!
OpenHarmony open source address:
https://gitee.com/openharmony?_from=gitee_search
The project open source address:
https://gitee.com/openharmony-sig/knowledge_demo_smart_home/tree/master/dev/docs/smart_co_detection


OpenHarmony开发者
160 声望1.1k 粉丝

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