关于物联网:小程序无需编程体验-IoT-物联网平台-物模型开发设备接入类

21次阅读

共计 3143 个字符,预计需要花费 8 分钟才能阅读完成。

微信小程序码

1. 筹备工作

1.1 注册阿里云账号

浏览器关上 ​​https://aliyun.com​​,开明阿里云账号,并通过支付宝实名认证。[](https://www.aliyun.com)/>

1.2 收费开明 IoT 物联网平台

在产品分类,找到物联网平台,进入产品官网,立刻开明。​​https://aliyun.com/product/iot​​

2. 控制台操作步骤

2.1 创立产品

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

2.2 产品性能定义

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

这里咱们能够导入附录里的物模型。​​点击获取​​ 残缺物模型 JSON,导入前须要替换对应的产品 productKey。物模型导入胜利如下:

2.3 注册设施

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

3. 微信小程序操作

3.1 设施上线

咱们关上微信,扫描小程序码,进入小程序。输出设施身份三元组,点击设备上线。如下图,能够看到设施状态为在线,小程序 log 和设施详情页面 最初上线工夫统一。

3.2 上报数据

在小程序界面,点击数据上报,咱们看到模拟器上报了以后湿度,温度值。在控制台设施日志也能够查到本次音讯详情,如下图。

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

3.3 订阅主题和数据上行

在小程序界面,点击 订阅主题,而后咱们再去控制台,设施详情页面的 Topic 列表,找到对应的 topic,点击公布音讯。在公布音讯页面,填写音讯内容,点击确认。咱们就会看到在小程序端展现推送音讯,如下图。

同时在设施上行日志,也能够看到残缺的上行音讯。

3.4 物模型 - 服务调用

在控制台的在线调试界面,咱们选中小程序设施,选中性能 开灯 (switch),输出参数 {“status”:”on”}, 点击发送命令。小程序的灯,就会变亮。如下图。{“status”:”on”} //status 选项有:on ,off ,blue ,green

在设施详情的服务调用选项卡,也能够看到服务调用记录。如下图。

3.4 物模型 - 事件上报

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

附录:物模型 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": "温度过高报警"
    }
  ]
}

物联网平台产品介绍详情:​​https://www.aliyun.com/product/iot/iot_instc_public_cn​​

               阿里云物联网平台客户交换群 

正文完
 0