阿里云物联网之四:使用MQTT.FX模拟设备更新网页应用信息

json数据体

向阿里云应用发送数据,需要按照阿里云要求的格式进行发送。
具体数据格式,我们可以参考阿里云平台帮助文档

https://help.aliyun.com/document_detail/73736.html?spm=a2c4g.11186623.6.643.279b20051fSa7A

这里我们可以看一下,当我们使用虚拟设备调试的时候,推送的是什么内容

2020-04-28 22:19:27.296, 88525EA89A314F62AC3C967EE3F1D4EB, upstream - bizType=PROPERTY_REPORT,params={"id":"123","iotId":"TfiSvafEU*****TvI3X000100","method":"thing.event.property.post","params":{"CurrentHumidity":23,"CurrentTemperature":12},"topic":"/sys/a1a3XzsznJI/SMART_LIGHT01/thing/event/property/post","uniMsgId":"5020558276217065472","version":"1.0"},result=code:200,message:success,topic=/sys/a1a3XzsznJI/SMART_LIGHT01/thing/event/property/post,response={"code":200,"data":{},"id":"123","message":"success","method":"thing.event.property.post","version":"1.0"},device={"aliyunCommodityCode":"iothub_senior","deviceKey":"TfiSvafEUPoYjuFTvI3X","deviceSecret":"***","gmtCreate":1588075639000,"gmtModified":1588075639000,"id":214218830,"instanceId":"iotx-oxssharez200","iotId":"TfiSvafEUPoYjuFTvI3X000100","name":"SMART_LIGHT01","productKey":"a1a3XzsznJI","rbacTenantId":"88525EA89A314F62AC3C967EE3F1D4EB","region":"cn-shanghai","status":0,"statusLast":0,"thingType":"DEVICE"},scriptData={},useTime=8,traceId=0be3e0a715880835671633943e0f24

其中 params里面的内容即是真正的报问题,我们展开看一下

{
  "id": "123",
  "iotId": "TfiSvafEU*****TvI3X000100",
  "method": "thing.event.property.post",
  "params": {
    "CurrentHumidity": 23,
    "CurrentTemperature": 12
  },
  "topic": "/sys/a1a3XzsznJI/SMART_LIGHT01/thing/event/property/post",
  "uniMsgId": "5020558276217065472",
  "version": "1.0"
}

我们可以看到,里面包含了ID IOTID METHOD PARAMS TOPIC UNIMSGID VERSION

可以看到,我们需要推送的主题是

"/sys/a1a3XzsznJI/SMART_LIGHT01/thing/event/property/post"

其中,下面几项使我们必须要包含在数据体里面的,也就是我们要推送的内容

{
  "id": "123",
  "method": "thing.event.property.post",
  "params": {
    "CurrentHumidity": 23,
    "CurrentTemperature": 12
  },
  "version": "1.0"
}

使用MQTT.FX发送报文

我们拿到了报文体后,即可以通过更改报文体里面的温湿度值,推送到云平台来更新我们的显示信息了。

我们使用MQTT.FX连接阿里云
设置推送topic

/sys/a1a3XzsznJI/SMART_LIGHT01/thing/event/property/post

填写报文体

{
  "id": "123",
  "method": "thing.event.property.post",
  "params": {
    "CurrentHumidity": 90,
    "CurrentTemperature": 35
  },
  "version": "1.0"
}

点击推送后,我们会发现,我们发布的页面里面的数据跟着产生了变化。
在这里插入图片描述

至此,我们已经完成了使用MQTT.FX客户端,更新阿里云网页应用信息。

下一步我们需要使用真实的2G/3G/4G模块,使用嵌入式系统,进行数据推送,更新网页应用信息。

原创文章 17 获赞 1 访问量 261

猜你喜欢

转载自blog.csdn.net/cw_huang/article/details/105826077