Steps for device access to Alibaba IoT cloud

Open the SDK download link in the browser
https://help.aliyun.com/document_detail/42648.html?spm=a2c4g.11186623.6.576.696c3f691yLvtj
Insert picture description hereselect JAVA SDK
Insert picture description here

Find the JAVA SDK DEMO download
Insert picture description here

Unzip the DEMO source code, import this maven project with eclipse, you need to connect to the external network to
configure Ali's Internet of Things devices, open
https://iot.console.aliyun.com/lk/vpc/instance?spm=5176.cniot.0.0 with a browser .2e8111faI7UO4P
Click Device Management -> Products
Insert picture description here

Create a new product,
add two attributes and an event
Insert picture description here

Edit the physical model of the product
Insert picture description here

After editing, click the publish button to publish the product
Insert picture description here

Add a new device to the
device The main connection parameters of the new device are:
Insert picture description here

These three parameters can be found in the device properties:
Insert picture description here

Device certificate
Modify the device configuration under JavaLinkKitDemo: device_id.json, open ThingTemplate.java and run the main function:
Insert picture description here

Run according to java application, need to
connect to the Internet to test the IoT device successfully connect to Alibaba Cloud
Insert picture description here

The management console device status is online.
Edit the attribute report on line 106 of ThingTemplate.java, add two custom attribute report programs and an event report program, and call them periodically.

                //属性上报
                  handlePropertySet("MicSwitch", new ValueWrapper.IntValueWrapper(1));
                  int myi=0;
                  int tmpMicSwitch=0;
                  while(myi<100000) {
    
    
                	  myi++;
                	  try {
    
    
                          Thread.sleep(2000);
                      } catch (InterruptedException e) {
    
    
                          e.printStackTrace();
                      }
                	  if(myi%2==1) {
    
    
                		  handlePropertySet("MicSwitch", new ValueWrapper.IntValueWrapper(1));
                		  handlePropertySet("hue", new ValueWrapper.IntValueWrapper(myi+100));
                	  }else {
    
    
                		  handlePropertySet("MicSwitch", new ValueWrapper.IntValueWrapper(0));
                		  //事件上报
                		  Map<String,ValueWrapper> values = new HashMap<>();
                          //values.put("eventValue",new ValueWrapper.IntValueWrapper(0));
                          OutputParams outputParams = new OutputParams(values);
                          //事件上报
                          handleEventSet("Offline_alarm",outputParams);
                	  }
                  }

Re-run ThingTemplate.java to view the data reported by the IoT device in the Alibaba device log and the properties and events of the object model:
Insert picture description here

View object model data
Insert picture description here

View event
Insert picture description here

View log

Guess you like

Origin blog.csdn.net/weloveut/article/details/108165057