Quickly build smart home applications based on HaaS 100

This article describes in detail how to quickly access Alibaba Cloud IoT based on the HaaS platform to build smart life application scenarios.

 

1. Equipment-side environment construction

Refer to HaaS 100 to get started quickly .

 

2. Cloud configuration

Log in to the Smart Life IoT platform ( https://living.aliyun.com/ ). For users who have not registered an Alibaba Cloud account, please complete the account registration first.

 

2.1, create a project

As shown in the figure below, click on the upper right corner to create a new project.

image.png

2.2, create a product

After the project is created, create a new product.

image.png

 

2.2.1, product type selection

As shown in the figure below, instructions for filling in information when creating the product:

1. Product name, just fill in as you like;

2. For the category, the smart life platform provides object models that cover most of the product categories in the industry. Here, we use the HaaS development board to simulate smart lights, so choose "Electrical Lighting/Lights";

3. Node type, direct connection device, select "device";

4. Direct connection, select non-gateway access;

5. We use HaaS Wi-Fi network access, select "WiFi" as the connection method;

6. Data format, select "ICA" which is Alink Json format, or raw data format (the device does not understand the specific user protocol, you need to set the js script on the cloud platform to convert the binary protocol to the ICA protocol);

7. The device does not support ID2 authentication by default, select "No".

   image.png

2.2.2, improve product information

As shown below:

1. Check the use of public version APP to control the product;

2. Improve the configuration settings of the exclamation mark on the left, and press confirm for the default settings;

image.png

3. It should be noted that click on the configuration network guide page to customize the network configuration settings;

image.png

4. Create a device and copy its triple information.

image.png

image.png

5. Copy the product key at the same time, which is used to configure the device side network configuration:

image.png

6. Complete the development:

image.png

7. Install the mobile app, scan the QR code as shown in the figure to download the cloud smart app:

image.png

 

At this point, the cloud configuration is complete.

 

3. Device configuration

1. Modify the quaternion information in the code application/example/linkkit_demo/linkkit_example_solo.c on the terminal, as shown in the figure below, where the quaternion information is obtained from chapter 2.2.2.

image.png

2. Modify the attribute setting callback function. You can add your own code to this function, such as controlling IO operations according to cloud attributes:

image.png

2. Compile

aos make linkkit_demo@haas100 -c config
aos make 

3. Follow the instructions in Chapter 1 to burn the firmware.

4. End-cloud joint debugging

4.1. Network distribution and binding

4.1.1 Equipment distribution network

1. Configure the network through the command line, and enter the following commands through the serial port to complete the network configuration:

netmgr -t wifi -c {ssid} {password}

Key log:

ssid=aos_test_01
ip_address=192.168.18.109
address= 0:80:3d:64: 8:77
wpa_state=COMPLETED

After obtaining the IP address, the program will immediately start linkkit to connect to the cloud; key logs of connecting to the cloud:

[Jan 01 00:00:11.613]<I>HAL_TLS  ok
[Jan 01 00:00:11.613]<I>HAL_TLS   . Setting up the SSL/TLS structure...
[Jan 01 00:00:11.613]<I>HAL_TLS  ok
[Jan 01 00:00:11.614]<I>HAL_TLS Performing the SSL/TLS handshake...
[Jan 01 00:00:11.731]<I>HAL_TLS  ok
[Jan 01 00:00:11.731]<I>HAL_TLS   . Verifying peer X.509 certificate..
[Jan 01 00:00:11.731]<I>HAL_TLS certificate verification result: 0x00
[Jan 01 00:00:11.731]<I>MQTT connect params: MQTTVersion=4, clientID=a1Oi7Q7h3LV.haas_01|timestamp=2524608000000,_v=sdk-c-3.0.1,securemode=2,signmethoV
[Jan 01 00:00:11.772]<I>MQTT mqtt connect success!

So far, the device has completed the network configuration and connected to the smart life platform using the triple (product key/device name/device secret) created by ourselves.

Note : The APP network distribution function of the HaaS100 development board is still under development, please continue to pay attention to code updates.

 

4.1.2 Binding of device and cloud smart APP

Open the cloud smart APP installed in step 2.2 to ensure that the mobile phone and the device are connected to the same APP. Click the red "+" button in the upper right corner to start the device search.

image.png

Find the device after a few seconds, as shown in the figure below, click Finish.

image.png

The binding is now complete.

 

4.2, control test

After the device is bound, enter the following page, and you can click on different modules in the figure to issue commands. At the same time, pay attention to the device log printing.

image.png

Typical log:

[Jan 01 00:02:12.197]<I>MQTT Downstream Topic: '/sys/a1Oi7Q7h3LV/haas_01/thing/service/property/set'
[Jan 01 00:02:12.197]<I>MQTT Downstream Payload:

< {
<     "method":"thing.service.property.set", 
<     "id":"575303451", 
<     "params":{ 
<         "HSVColor":{ 
<             "Saturation":84, 
<             "Value":5, 
<             "Hue":232 
<         }
<     },
<     "version":"1.0.0" 
< }

[Jan 01 00:02:12.198]<I>DM thing/service/property/set
[Jan 01 00:02:12.198]<I>DM Send URI: /sys/a1Oi7Q7h3LV/haas_01/thing/service/property/set_reply, Payload: {"id":"575303451","code":200,"data":{}}
[Jan 01 00:02:12.200]<I>MQTT Upstream Topic: '/sys/a1Oi7Q7h3LV/haas_01/thing/service/property/set_reply'
[Jan 01 00:02:12.200]<I>MQTT Upstream Payload:

> {
>     "id":"575303451", 
>     "code":200, 
>     "data":{ 
>     }
> }

Of course, you can also add your own code in the callback function issued by the attribute or service to complete more functions, such as controlling the IO port to operate real peripherals.

Stay tuned for the follow-up HaaS example introduction.

Guess you like

Origin blog.csdn.net/HaaSTech/article/details/109955059