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

微信小程序码

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​

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值