developing-the-first-example-program-running-on-hi3861.md 6.6 KB
Newer Older
W
wenjun 已提交
1 2
# Developing the First Example Program Running on Hi3861<a name="EN-US_TOPIC_0000001053302600"></a>

N
NEEN 已提交
3
-   [Building](#section191121332125319)
[
[yang] 已提交
4 5 6 7
-   [Burning Images](#section1610612214150)
-   [Connecting WLAN Module to the Internet](#section168257461059)

This example shows how to connect the WLAN module to the gateway using attention \(AT\) commands.
W
wenjun 已提交
8

N
NEEN 已提交
9
## Building<a name="section191121332125319"></a>
W
wenjun 已提交
10

Y
yangni 已提交
11 12
This section describes how to perform the WLAN module building on a Linux server.

N
NEEN 已提交
13
If the Linux environment is installed using Docker, perform the building by referring to  [Using Docker to Prepare the Build Environment](../get-code/acquiring-tools.md). If the Linux environment is installed using a software package, perform the following steps:
W
wenjun 已提交
14

[
[yang] 已提交
15
1.  Open the HUAWEI DevEco Device Tool and choose  **View**  \>  **Terminal**.
W
wenjun 已提交
16 17 18 19

    **Figure  1**  Starting the IDE terminal tool<a name="fig1975813338510"></a>  
    

N
NEEN 已提交
20
    ![](figures/1.png)
W
wenjun 已提交
21

N
NEEN 已提交
22
    On the  **TERMINAL**  panel, run the ssh command, for example,  **ssh** **_user_@_ipaddr_**, to connect to the Linux server.
W
wenjun 已提交
23

N
NEEN 已提交
24
    **Figure  2**  TERMINAL panel<a name="fig91165301546"></a>  
W
wenjun 已提交
25 26
    

N
NEEN 已提交
27
    ![](figures/2.png)
W
wenjun 已提交
28

N
NEEN 已提交
29
2.  Go to the root directory of the code, run the  **hb set**  and  **.**  commands on the  **TERMINAL**  panel, and select the  **wifiiot\_hispark\_pegasus**  version.
N
NEEN 已提交
30 31 32 33

    **Figure  3**  Selecting the target build version<a name="fig17727115215612"></a>  
    

N
NEEN 已提交
34
    ![](figures/3.png)
N
NEEN 已提交
35 36

3.  Run the  **hb build**  command to start building.
W
wenjun 已提交
37

N
NEEN 已提交
38
    **Figure  4**  Running commands on the TERMINAL panel<a name="fig5493164414573"></a>  
W
wenjun 已提交
39 40
    

N
NEEN 已提交
41
    ![](figures/4.png)
W
wenjun 已提交
42

N
NEEN 已提交
43 44 45 46
4.  Check whether the building is successful. If yes,  **wifiiot\_hispark\_pegasus build success**  will be displayed, as shown in the following figure.

    **Figure  5**  Successful building<a name="fig1262101218463"></a>  
    
W
wenjun 已提交
47

N
NEEN 已提交
48
    ![](figures/5.png)
W
wenjun 已提交
49

N
NEEN 已提交
50
5.  Check whether the following files are generated in the  **./out/wifiiot/**  directory.
[
[yang] 已提交
51 52

    ```
N
NEEN 已提交
53
    ls -l out/hispark_pegasus/wifiiot_hispark_pegasus/
[
[yang] 已提交
54
    ```
W
wenjun 已提交
55

N
NEEN 已提交
56
    **Figure  6**  Directory for storing the generated files<a name="fig38521346164618"></a>  
W
wenjun 已提交
57 58
    

N
NEEN 已提交
59
    ![](figures/3-0.png)
W
wenjun 已提交
60 61 62 63


## Burning Images<a name="section1610612214150"></a>

[
[yang] 已提交
64
You can use the DevEco tool to perform the image burning of the Hi3861 WLAN module. For details about how to use the tool, see  [HUAWEI DevEco Device Tool User Guide](https://device.harmonyos.com/en/docs/ide/user-guides/service_introduction-0000001050166905).
W
wenjun 已提交
65

N
NEEN 已提交
66 67
1.  Connect the PC and the target development board through the USB port. For details, please refer to  [Introduction to the Hi3861 Development Board](https://device.harmonyos.com/en/docs/start/introduce/oem_wifi_start_des-0000001050168548).
2.  <a name="en-us_topic_0000001056563976_li848662117291"></a>Open Device Manager, then check and record the serial port number corresponding to the development board.
W
wenjun 已提交
68

N
NEEN 已提交
69 70
    >![](public_sys-resources/icon-note.gif) **NOTE:** 
    >If the serial port number is not displayed correctly, follow the steps described in  [Installing the Serial Port Driver on the Hi3861 Series Development Boards](https://device.harmonyos.com/cn/docs/ide/user-guides/hi3861-drivers-0000001058153433).
W
wenjun 已提交
71

N
NEEN 已提交
72
    ![](figures/en-us_image_0000001073388838.png)
W
wenjun 已提交
73

N
NEEN 已提交
74
3.  Open DevEco Device Tool and go to  **Projects**  \>  **Settings**.
W
wenjun 已提交
75

N
NEEN 已提交
76
    ![](figures/en-us_image_0000001078404538.png)
W
wenjun 已提交
77

N
NEEN 已提交
78
4.  On the  **hi3861**  tab page, set the programming options.
W
wenjun 已提交
79

N
NEEN 已提交
80 81 82
    -   **upload\_port**: Select the serial port number obtained in step  [2](#en-us_topic_0000001056563976_li848662117291).
    -   **upload\_protocol**: Select the programming protocol  **burn-serial**.
    -   **upload\_partitions**: Select the file to be programmed.  **hi3861\_app**  is selected by default.
W
wenjun 已提交
83

N
NEEN 已提交
84
    ![](figures/en-us_image_0000001078244328.png)
W
wenjun 已提交
85

N
NEEN 已提交
86
5.  Modify the settings of the  **hi3861\_app**  file. In general cases, you can leave the fields at their default settings. To change the default settings, select the target item in the  **New Option**  field first.
W
wenjun 已提交
87

N
NEEN 已提交
88
    ![](figures/en-us_image_0000001120802173.png)
W
wenjun 已提交
89

N
NEEN 已提交
90
6.  When you finish modifying, click  **Save**  in the upper right corner.
W
wenjun 已提交
91

N
NEEN 已提交
92
    ![](figures/en-us_image_0000001078313582.png)
W
wenjun 已提交
93

N
NEEN 已提交
94
7.  Open the project file. In the DevEco Device Tool window, go to  **PROJECT TASKS**  \>  **env:hi3861**  \>  **Upload**  to start programming.
W
wenjun 已提交
95

N
NEEN 已提交
96
    ![](figures/en-us_image_0000001120802383.png)
W
wenjun 已提交
97

N
NEEN 已提交
98
8.  When the following information is displayed, press the RST button on the development board to restart it.
W
wenjun 已提交
99

N
NEEN 已提交
100
    ![](figures/en-us_image_0000001074285712.png)
W
wenjun 已提交
101

N
NEEN 已提交
102 103 104
9.  Start programming. When the following message is displayed, it indicates that the programming is successful.

    ![](figures/en-us_image_0000001074445364.png)
W
wenjun 已提交
105 106


N
NEEN 已提交
107
## Connecting WLAN Module to the Internet<a name="section168257461059"></a>
W
wenjun 已提交
108

N
NEEN 已提交
109
After completing version building and burning, do as follows to connect the WLAN module to the Internet using AT commands.
W
wenjun 已提交
110

N
NEEN 已提交
111
1.  Click the icon of  **DevEco: Serial Monitor**  at the bottom of DevEco Studio to keep the connection between the Windows workstation and the WLAN module.
W
wenjun 已提交
112

N
NEEN 已提交
113 114
    **Figure  7**  Opening the DevEco serial port<a name="fig12489182991119"></a>  
    
N
NEEN 已提交
115

N
NEEN 已提交
116
    ![](figures/5-1.png)
W
wenjun 已提交
117

N
NEEN 已提交
118
2.  Reset the WLAN module. The message  **ready to OS start**  is displayed on the  **TERMINAL**  panel, indicating that the WLAN module is started successfully.
W
wenjun 已提交
119

N
NEEN 已提交
120
    **Figure  8**  Successful resetting of the WLAN module <a name="fig496084516332"></a>  
N
NEEN 已提交
121 122
    

N
NEEN 已提交
123
    ![](figures/6.png)
W
wenjun 已提交
124

N
NEEN 已提交
125
3.  Run the following AT commands in sequence via the DevEco serial port terminal to start the STA mode, connect to the specified AP, and enable Dynamic Host Configuration Protocol \(DHCP\).
W
wenjun 已提交
126 127

    ```
N
NEEN 已提交
128 129 130 131 132 133
    AT+STARTSTA                             # Start the STA mode.
    AT+SCAN                                 # Scan for available APs.
    AT+SCANRESULT                           # Display the scanning result.
    AT+CONN="SSID",,2,"PASSWORD"            # Connect to the specified AP. (SSID and PASSWORD represent the name and password of the hotspot to be connected, respectively.)
    AT+STASTAT                              # View the connection result.
    AT+DHCP=wlan0,1                         # Request the IP address of wlan0 from the AP using DHCP.
N
NEEN 已提交
134 135
    ```

N
NEEN 已提交
136
4.  Check whether the WLAN module is properly connected to the gateway, as shown in the following figure.
N
NEEN 已提交
137 138

    ```
N
NEEN 已提交
139 140
    AT+IFCFG                                # View the IP address assigned to an interface of the module.
    AT+PING=X.X.X.X                         # Check the connectivity between the module and the gateway. Replace X.X.X.X with the actual gateway address.
W
wenjun 已提交
141 142
    ```

N
NEEN 已提交
143
    **Figure  9**  Successful networking of the WLAN module<a name="fig1166371318339"></a>  
N
NEEN 已提交
144
    
W
wenjun 已提交
145

N
NEEN 已提交
146
    ![](figures/截图.png)
W
wenjun 已提交
147 148