Micro-channel networking platform to connect small control device Clouds Ali (IOT) three

Post navigation:
micro-channel small program to connect Ali cloud of Things platform handling equipment (IOT) cloud on a device
micro-channel small program to connect Ali cloud of Things platform handling equipment (IOT) two micro-channel applet development (a)
micro-channel small program to connect Ali Clouds networking platform handling equipment (IOT) three small micro-channel application development (b)


The first two, we have the equipment and the preparation of the cloud operating sdk for access to Ali cloud platform cloud Things API. This one we will use to access the sdk we write good things Ali cloud cloud platform API. In order to achieve access to device information, and the first to call for the services we add the device to realize the device sends commands.

Small micro-channel program development (II)

Things Ali cloud cloud platform API

We can Ali cloud platform things official document viewing to the list of cloud API. This example focuses on using QueryDevicePropertyStatus (get device attributes snapshots) and InvokeThingService (calling equipment service) two interfaces for presentation.

Activate the device

Without activation device is unable to obtain the status of the device. In front of the cloud on the device did not activate the device. Device activation means that the device is first connected to the platform by Ali cloud Things MQTT channels or HTTPS channel. After activating the device appears offline. Refer to the specific device to access official documents . There are many languages to choose from access.


I am using c # .net core language to build a cross-platform program simulates a device has been activated, the effect is as follows.

Things internet connection attribute value acquisition device

1. See API required parameters

The second IOT encapsulated internet access sdk Drive device attribute value acquisition API 2. previously. Because the length of the relationship I do not speak all the source code posted. Need the source code of a small partner, please click on the link to download the source code

var that = this
    aliSdk.request({
        Action: "QueryDevicePropertyStatus",
        ProductKey: app.globalData.productKey,
        DeviceName: app.globalData.deviceName
      }, {
        method: "POST"
      },
      (res) => {
        console.log("success")
        console.log(res) //查看返回数据
        if (res.data.Code) {
          console.log(res.data.ErrorMessage)
          wx.showToast({
            title: '设备连接失败',
            icon: 'none',
            duration: 1000,
            complete: () => {}
          })
          that.setPropertyData(null)
        } else {
          that.setPropertyData(res.data.Data.List.PropertyStatusInfo)
        }
      },
      (res) => {
        console.log("fail")
        wx.showToast({
          title: '网络连接失败',
          icon: 'none',
          duration: 1000,
          complete: () => {}
        })
        this.setPropertyData(null)
      },
      (res) => {
        console.log("complete")
      })

Things can see the platform returned the following results Response.

Interface display device data acquired from the API to the cloud.

Equipment service calls, the notification device to open the device on or off

1. Check the parameters used to call the API

2. Use the sdk call our first article for the device set of services.

var that = this
    //防止重复点击
    that.setData({
      buttonDisabled: true
    })
    
    aliSdk.request({
        Action: "InvokeThingService",
        ProductKey: app.globalData.productKey,
        DeviceName: app.globalData.deviceName,
        Identifier: that.data.openedDevice ? "CloseDevice" : "OpenDevice",
        Args: "{}" //无参服务,所以传空
      }, {
        method: "POST"
      },
      (res) => {
        console.log("success")
        console.log(res) //查看返回response数据
        that.setData({
          openedDevice: !that.data.openedDevice
        })
      },
      (res) => {
        console.log("fail")
        wx.showToast({
          title: '网络连接失败',
          icon: 'none',
          duration: 1000,
          complete: () => {}
        })
      },
      (res) => {
        console.log("complete")
        that.setData({
          buttonDisabled: false
        })
      })

Things returned Response platform following results can be seen as the true success is to call a success.

Let's look at the things that the log platform successfully call the service.

Click MessageID can see specific information about

the call is successful, if the device is connected to subscribe to the Internet of Things platform Topic, then the platform will be automatically issued This command to the device, the device can run it. Please fingertips as I like the point of a full set of applet source code on top of the resources in the article.
Thus micro-channel connection applet Ali cloud Things platform device data acquisition and control device has been achieved. Things Ali cloud platform, there are many powerful features, such as internal circulation RDS data, the server subscription data, etc., in which I will not give you one demonstrates, if you're interested you can try to do it yourself.

The way to our company's official website did advertise, intelligent software and hardware requirements or holographic display can look at the needs of small partners.

Post navigation:
micro-channel small program to connect Ali cloud of Things platform handling equipment (IOT) cloud on a device
micro-channel small program to connect Ali cloud of Things platform handling equipment (IOT) two micro-channel applet development (a)
micro-channel small program to connect Ali Clouds networking platform handling equipment (IOT) three small micro-channel application development (b)

Released five original articles · won praise 4 · Views 1884

Guess you like

Origin blog.csdn.net/weixin_42852371/article/details/105083684