美文网首页
2018-05-17 sitewhere 对接 MQTT 设备

2018-05-17 sitewhere 对接 MQTT 设备

作者: 杨廣xiang | 来源:发表于2018-05-17 20:58 被阅读0次

本文描述如何将 物联设备 通过 MQTT协议 与 sitewhere 对接起来。

环境准备

在Ubuntu系统里,安装 sitewhere docker。在docker hub上已经有了sitewhere image。

sudo docker pull sitewhere/standalone:1.8.0

特别要注意的就是要指定版本。另外,安装的是standalone版本。

sudo docker run -p 80:8080 -p 1883:1883 -p 61623:61623 sitewhere/standalone:1.8.0

使用上面的命令启动sitewhere。

启动后,就可以通过浏览器访问 sitewhere web console。

MQTT client

在Ubuntu上安装mosquitto。

发送MQTT消息

sitewhere standalone版本里,包含了mqtt broker。所以,可以直接向sitewhere 发送MQTT消息。

准备下面的数据,保存到 loc.json文件。

{
"hardwareId": "7c1c95e9-eb01-422f-9aec-fd64094d01e3",
"type":"DeviceLocation",
"request": {
"latitude": "33.75",
"longitude": "-84.39",
"elevation": "0",
"updateState": true,
"eventDate": "2018-05-17T19:40:03.390Z"
}
}

mosquitto_pub -h 127.0.0.1 -f loc.json -t SiteWhere/input/json

sitewhere会在它的 mqtt broker 里订阅 sitewhere/input/json 主题。所以,要向这个topic发消息。消息数据中的 hardwareId,是在sitewhere里定义的 device 。 sitewhere安装好后,里面有一个例子。这里的这个hardwareId就取自例子中的一个 device。
发送了消息后,我们就可以在sitewhere中看到。


a.png

我们还可以发送 Alert 消息:

{
"hardwareId": "7c1c95e9-eb01-422f-9aec-fd64094d01e3",
"type":"DeviceAlert",
"request": {
"type": "engine.overheat",
"level": "Warning",
"message": "The engine is about to overheat! Turn the machine off!",
"updateState": false,
"eventDate": "2018-05-17T19:40:03.391Z",
"metadata": {
"name1": "value1",
"name2": "value2"
}
}
}

b.png

发送数据格式可参考 http://documentation.sitewhere.io/userguide/sending-data.html

物联设备状态变更,触发事件

上面的Alert,是外部设备直接发来的 Alert 消息。如果需要支持 condition trigger,需要与openHAB集成。

sudo docker pull openhab/openhab:2.2.0-amd64-debian

https://groups.google.com/forum/#!topic/sitewhere/w5Obz3MjHkU
https://docs.openhab.org/installation/docker.html#obtaining-the-official-image-from-dockerhub
http://documentation.sitewhere.io/integration/openhab.html

== 待继 ==

相关文章

网友评论

      本文标题:2018-05-17 sitewhere 对接 MQTT 设备

      本文链接:https://www.haomeiwen.com/subject/ppcidftx.html