传感器mqtt树莓派_使用mqtt在多个设备之间共享传感器数据

传感器mqtt树莓派

TL;DR: You can use MQTT and its pub/sub architecture to share data from multiple devices and sensors without much overhead. Here are some starter publisher and subscriber JavaScript clients to help you get started: https://github.com/rdeprey/mqtt-starter.

TL; DR:您可以使用MQTT及其发布/订阅体系结构来共享来自多个设备和传感器的数据,而不会产生太多开销。 以下是一些入门发布者和订阅者JavaScript客户端,可帮助您入门: https : //github.com/rdeprey/mqtt-starter

Over the past few years, I’ve accumulated a fair number of Raspberry Pis and have sensors set up to monitor various things around my home. As the number of sensors has grown, I’ve found myself wanting to create my own “home hub” similar to the Google Nest Hub or Amazon Echo, allowing me to see data from multiple devices at a glance.

在过去的几年中,我已经积累了相当多的Raspberry Pis,并且设置了传感器来监视我家周围的各种事物。 随着传感器数量的增加,我发现自己想要创建自己的类似于Google Nest Hub或Amazon Echo的“家庭中心”,从而使我能够一目了然地查看来自多个设备的数据。

I recently decided to do just that and initially thought that Bluetooth would be the easiest way to simultaneously get data from each device. After all, Bluetooth is a common way to connect commercially produced smart devices. While that is a valid option, I found it required a fair amount of setup though because you need to create custom GATT services for each device and the sensor data that you want to share from it.

我最近决定这样做,并且最初认为蓝牙是同时从每个设备获取数据的最简单方法。 毕竟,蓝牙是连接商业生产的智能设备的常用方法。 尽管这是一个有效的选项,但我发现它需要大量的设置,因为您需要为每个设备以及要与之共享的传感器数据创建自定义GATT服务。

As I was researching my options, I came across MQTT (short for Message Queuing Telemetry Transport), which is an OASIS standard messaging protocol for the Internet of Things (IoT). It’s a publish/subscribe (also known as pub/sub) messaging protocol that’s primary use is to connect remote devices. It has a small codebase, uses minimal network bandwidth, and is very lightweight. In order for MQTT to work, all of the devices have to be on the same network, but this wasn’t a problem given my device configuration.

在研究选项时,我遇到了MQTT(消息队列遥测传输的缩写) ,它是用于物联网(IoT)的OASIS标准消息协议。 这是一种发布/订阅(也称为pub / sub)消息传递协议,其主要用途是连接远程设备。 它具有小的代码库,使用最小的网络带宽,并且非常轻巧。 为了使MQTT正常工作,所有设备都必须位于同一网络上,但是考虑到我的设备配置,这不是问题。

In short, it was perfect for my needs! It might be a great fit for your next project too, so I wanted to share a guide on how to get started with using MQTT.

简而言之,它非常适合我的需求! 这也可能非常适合您的下一个项目,因此我想分享一个有关如何开始使用MQTT的指南。

This guide explains how to implement MQTT in JavaScript, but you can use the protocol in other languages as well. There’s a thorough list of MQTT implementations, tools, and resources available from hobbyquaker on Github that I recommend checking out for further information.

本指南说明了如何在JavaScript中实现MQTT,但是您也可以在其他语言中使用该协议。 Github上的hobbyquaker提供了MQTT实现,工具和资源的完整列表 ,我建议您查看更多信息。

MQTT的基础 (Basics of MQTT)

Before we dive into writing code, let’s first discuss how MQTT works.

在开始编写代码之前,让我们首先讨论MQTT的工作原理。

MQTT的主要功能 (Key Features of MQTT)

MQTT implements the following main tenets of the pub/sub model:

MQTT实现了pub / sub模型的以下主要原则:

  • Clients don’t need to know that other clients exist. To publish or subscribe to messages, clients only need to know the hostname/IP address and the port of the broker.

    客户不需要知道其他客户的存在。 要发布或订阅消息,客户端只需要知道主机名/ IP地址和代理的端口即可。
  • It’s not time dependent. In most cases, MQTT is used to share messages in real-time, but it’s possible for the broker to store messages for clients that aren’t online.

    它与时间无关。 在大多数情况下,MQTT用于实时共享消息,但是代理可以为不在线的客户端存储消息。
  • It works asynchronously, so it doesn’t block client-side rendering.

    它异步工作,因此不会阻止客户端渲染。

发布/订阅体系结构 (Publish/Subscribe Architecture)

At its core, MQTT implements the publish/subscribe architecture to allow multiple devices to publish and subscribe to messages from other devices. It’s different from the client-server mode

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值