天天看点

小程序无需编程,体验IoT物联网平台-物模型开发

产品推荐:阿里云物联网开发者工具( IoT Studio ), 立刻免费体验吧!

 微信小程序码

小程序无需编程,体验IoT物联网平台-物模型开发

1. 准备工作

1.1 注册阿里云账号

浏览器打开 

https://aliyun.com

 ,开通阿里云账号,并通过支付宝实名认证。[](

https://www.aliyun.com)

/>

小程序无需编程,体验IoT物联网平台-物模型开发

1.2 免费开通IoT物联网平台

在产品分类,找到物联网平台,进入产品官网,立即开通。

https://aliyun.com/product/iot
小程序无需编程,体验IoT物联网平台-物模型开发

2. 控制台操作步骤

2.1 创建产品

 进入物联网平台的控制台,创建产品。自定义品类,数据传输JSON格式

小程序无需编程,体验IoT物联网平台-物模型开发

2.2 产品功能定义

在产品详情页面的功能定义选项卡,创建产品物模型。

小程序无需编程,体验IoT物联网平台-物模型开发

这里我们可以导入附录里的物模型。

点击获取

 完整物模型JSON,导入前需要替换对应的产品productKey。

物模型导入成功如下:

小程序无需编程,体验IoT物联网平台-物模型开发

2.3 注册设备

在产品下注册设备,获得身份三元组,如下图。

小程序无需编程,体验IoT物联网平台-物模型开发

3. 微信小程序操作                  

3.1 设备上线

我们打开微信,扫描小程序码,进入小程序。输入设备身份三元组,点击设备上线。如下图,可以看到设备状态为在线,小程序log和设备详情页面 最后上线时间一致。

小程序无需编程,体验IoT物联网平台-物模型开发

3.2 上报数据

在小程序界面,点击数据上报,我们看到模拟器上报了当前湿度,温度值。在控制台设备日志也可以查到本次消息详情,如下图。

小程序无需编程,体验IoT物联网平台-物模型开发

同时,在设备详情的运行状态,也能实时看到设备上报的数据。

小程序无需编程,体验IoT物联网平台-物模型开发

3.3 订阅主题和数据下行

在小程序界面,点击 订阅主题,然后我们再去控制台,设备详情页面的 Topic列表,找到对应的topic,点击发布消息。在发布消息页面,填写消息内容,点击确认。我们就会看到在小程序端展示推送消息,如下图。

小程序无需编程,体验IoT物联网平台-物模型开发

同时在设备下行日志,也可以看到完整的下行消息。

小程序无需编程,体验IoT物联网平台-物模型开发

3.4 物模型-服务调用

在控制台的在线调试界面,我们选中小程序设备,选中功能 开灯(switch),输入参数{"status":"on"},点击发送命令。小程序的灯,就会变亮。如下图。

{"status":"on"} //status选项有:on ,off ,blue ,green           
小程序无需编程,体验IoT物联网平台-物模型开发

在设备详情的服务调用选项卡,也可以看到服务调用记录。如下图。

小程序无需编程,体验IoT物联网平台-物模型开发

3.4 物模型-事件上报

我们在小程序界面点击告警,就会生成一条事件告警,上报当前的温度。如下图。

小程序无需编程,体验IoT物联网平台-物模型开发

IoT物联网技术

小程序无需编程,体验IoT物联网平台-物模型开发

附录:物模型TSL

{
  "schema": "https://iotx-tsl.oss-ap-southeast-1.aliyuncs.com/schema.json",
  "profile": {
    "productKey": "替换为你的productKey"
  },
  "services": [
    {
      "outputData": [],
      "identifier": "set",
      "inputData": [
        {
          "identifier": "temperature",
          "dataType": {
            "specs": {
              "unit": "°C",
              "min": "-20",
              "max": "80",
              "step": "0.1"
            },
            "type": "float"
          },
          "name": "温度"
        },
        {
          "identifier": "humidity",
          "dataType": {
            "specs": {
              "unit": "%",
              "min": "0",
              "max": "100",
              "step": "0.1"
            },
            "type": "float"
          },
          "name": "湿度"
        }
      ],
      "method": "thing.service.property.set",
      "name": "set",
      "required": true,
      "callType": "async",
      "desc": "属性设置"
    },
    {
      "outputData": [
        {
          "identifier": "temperature",
          "dataType": {
            "specs": {
              "unit": "°C",
              "min": "-20",
              "max": "80",
              "step": "0.1"
            },
            "type": "float"
          },
          "name": "温度"
        },
        {
          "identifier": "humidity",
          "dataType": {
            "specs": {
              "unit": "%",
              "min": "0",
              "max": "100",
              "step": "0.1"
            },
            "type": "float"
          },
          "name": "湿度"
        }
      ],
      "identifier": "get",
      "inputData": [
        "temperature",
        "humidity"
      ],
      "method": "thing.service.property.get",
      "name": "get",
      "required": true,
      "callType": "async",
      "desc": "属性获取"
    },
    {
      "outputData": [],
      "identifier": "switch",
      "inputData": [
        {
          "identifier": "status",
          "dataType": {
            "specs": {
              "length": "48"
            },
            "type": "text"
          },
          "name": "开关"
        }
      ],
      "method": "thing.service.switch",
      "name": "开灯",
      "required": false,
      "callType": "async"
    }
  ],
  "properties": [
    {
      "identifier": "temperature",
      "dataType": {
        "specs": {
          "unit": "°C",
          "min": "-20",
          "max": "80",
          "step": "0.1"
        },
        "type": "float"
      },
      "name": "温度",
      "accessMode": "rw",
      "required": true
    },
    {
      "identifier": "humidity",
      "dataType": {
        "specs": {
          "unit": "%",
          "min": "0",
          "max": "100",
          "step": "0.1"
        },
        "type": "float"
      },
      "name": "湿度",
      "accessMode": "rw",
      "required": true
    }
  ],
  "events": [
    {
      "outputData": [
        {
          "identifier": "temperature",
          "dataType": {
            "specs": {
              "unit": "°C",
              "min": "-20",
              "max": "80",
              "step": "0.1"
            },
            "type": "float"
          },
          "name": "温度"
        },
        {
          "identifier": "humidity",
          "dataType": {
            "specs": {
              "unit": "%",
              "min": "0",
              "max": "100",
              "step": "0.1"
            },
            "type": "float"
          },
          "name": "湿度"
        }
      ],
      "identifier": "post",
      "method": "thing.event.property.post",
      "name": "post",
      "type": "info",
      "required": true,
      "desc": "属性上报"
    },
    {
      "outputData": [
        {
          "identifier": "temperature",
          "dataType": {
            "specs": {
              "unit": "°C",
              "min": "0",
              "max": "10000",
              "step": "0.1"
            },
            "type": "float"
          },
          "name": "温度"
        }
      ],
      "identifier": "hotAlarm",
      "method": "thing.event.hotAlarm.post",
      "name": "温度过高报警",
      "type": "alert",
      "required": false,
      "desc": "温度过高报警"
    }
  ]
}           

继续阅读