简体   繁体   English

MQTT 双向传感器数据采集

[英]MQTT two way sensor data collection

I'm working in Python.我在 Python 中工作。 I'm trying to connect a Windows PC with a Raspberry Pi.我正在尝试将 Windows PC 与 Raspberry Pi 连接。 I have a sensor connected to the Pi, and a small Python script to publish data to the MQTT broker, also located on the Raspberry Pi.我有一个连接到 Pi 的传感器,以及一个用于将数据发布到同样位于 Raspberry Pi 上的 MQTT 代理的小型 Python 脚本。

The general logic is for the Window's PC to publish a "send" message to "topic 1".一般逻辑是 Window 的 PC 向“主题 1”发布“发送”消息。 The RasPi listens to "topic 1", and when it see's "send", it gets the latest sensor data, and publishes it to "topic 2". RasPi 侦听“主题 1”,当它看到“发送”时,它会获取最新的传感器数据,并将其发布到“主题 2”。 The Window's PC then listens to "topic 2", and grabs the data.然后,Window 的 PC 侦听“主题 2”,并获取数据。

My issue: I'm always one sensor reading behind.我的问题:我总是落后于一个传感器。 I never get the sensor reading attached to when my "send" message.当我“发送”消息时,我从来没有得到传感器读数。

I am expected to publish a "send", and read the latest data once it has been sent.预计我会发布“发送”,并在发送后读取最新数据。

Any thoughts?有什么想法吗?

-Parsko -Parsko

PS - New poster here on SO, still learning how to ask questions of the community. PS - SO 上的新海报,仍在学习如何向社区提问。

There is no need for the Windows machine to send any request messages. Windows 机器不需要发送任何请求消息。

MQTT is a pub/sub protocol, which is a very different mindset from a request/response protocol (eg HTTP) MQTT 是一种发布/订阅协议,它与请求/响应协议(例如 HTTP)有着非常不同的思维方式

The sensors should just publish their values to sensor specific topics and the Windows machine should just subscribe to those topics.传感器应该只将它们的值发布到传感器特定的主题,而 Windows 机器应该只订阅这些主题。 This way it will always have the most up to date data.这样,它将始终拥有最新的数据。

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

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