简体   繁体   English

MQTT代理和客户端在同一个RPI上

[英]MQTT broker and client on the same RPI

So I'm building a system where I scan a RFID tag with a reader connected to a Raspberry Pi, the RFID tag ID should then be sent to another "central" RPI, where a database is checked for some info, and if it matches the central Pi sends a message to a lamp (also connected to a Pi) which will then turn on. 因此,我正在建立一个系统,我用一个连接到Raspberry Pi的阅读器扫描RFID标签,然后将RFID标签ID发送到另一个“中央”RPI,在那里检查数据库的某些信息,如果匹配中心Pi向灯(也连接到Pi)发送消息,然后灯将打开。 This is just the start of a larger home-automation system. 这只是一个更大的家庭自动化系统的开始。

I read about MQTT making it very easy to make more RPIs communicate and act on events like this. 我读到了关于MQTT的信息,这使得更多的RPI可以很容易地进行通信,并对这样的事件采取行动。 The only thing I am wondering about, but can't find documented on the internet, is whether the central Pi in my case can act like the broker, but also be subscribed to the topic for the RFID tag ID, check the database and then publish to another topic for the light. 我唯一想知道的,但在互联网上找不到记录,是我的案例中的中心Pi是否可以像经纪人一样,还要订阅RFID标签ID的主题,检查数据库然后发布到灯光的另一个主题。

Purely based on logical thinking I'd say yes, since the broker is running in the background. 纯粹基于逻辑思维我会说是,因为经纪人在后台运行。 Thus I would still be able to run a python script that subscribes/publishes to, I'm guessing, localhost instead of the central Pi's IPaddress and port. 因此,我仍然可以运行一个python脚本,订阅/发布,我猜,localhost而不是中心Pi的IP地址和端口。

Can anyone confirm this? 谁能证实这一点? I can't test it myself yet because I have just ordered the equipment, and am doing lots of preparation-research. 我自己无法测试,因为我刚刚订购了设备,并且正在进行大量的准备研究。

You can run as many clients as you like on the same machine as the broker (You could even run multiple brokers as long as they listen on different ports). 您可以在与代理相同的计算机上运行任意数量的客户端(只要他们在不同的端口上侦听,您甚至可以运行多个代理)。 The only thing you need to do is ensure that each client has different client id 您需要做的唯一事情是确保每个客户端具有不同的客户端ID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM