2018-05-17 sitewhere 对接 MQTT 设备

本文描述如何将 物联设备 通过 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

== 待继 ==

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 一:前言 最近在了解MQTT协议相关的内容,内容有点多,特此把MQTT协议,以及其从服务端到客户端的流程整理出来...
    子夏的不语阅读 70,413评论 9 92
  • 导语 翻译自iot in five days 8.2 MQTT是什么?MQTT(formerly MQ Telem...
    happy1993阅读 6,576评论 1 14
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,026评论 19 139
  • MQTT全称Message Queue Telemetry Transport,是一个针对轻量级的发布/订阅式消息...
    tripleCC阅读 14,727评论 6 11
  • ** 今天看了一下kafka官网,尝试着在自己电脑上安装和配置,然后学一下官方document。** Introd...
    RainChang阅读 5,053评论 1 30