I’m using paho and mosquitto in Python and running it on CMD not receiving the full message.

huangapple go评论81阅读模式
英文:

(noob) I'm using paho and mosquitto in Python and running it on CMD not receiving the full message

问题

I'm running an example of a program that publishes a random temperature in Python and uses Mosquitto to display it in CMD. This is the code of my program:

import paho.mqtt.client as mqtt
import time
import json
import uuid

import control

BROKER = "localhost"
PORT = 1883
NOTIFICATION_TOPIC = "oan/spm/tel15/ccd/notification"

TEMP_MIN = -110.9
TEMP_MAX = -100.5

id = uuid.uuid4()

client = mqtt.Client(client_id=str(id))
client.connect(BROKER, PORT, 60)
client.loop_start()

while True:
    data = dict()
    data["ccd"] = "Marconi 2"
    data["temp"] = control.get_random_temperature(TEMP_MIN, TEMP_MAX)

    client.publish(NOTIFICATION_TOPIC, json.dumps(data), retain=True)
    time.sleep(10)

And it works, but the message I get in CMD looks like this:

1687366819: Received PUBLISH from 3c60bffd-8a69-4f7d-90ae-982d725afdd7 (d0, q0, r1, m0, 'oan/spm/tel15/ccd/notification', ... (36 bytes))

It doesn't show the full message and instead only displays ...(36 bytes). What do I need to do to show the full message?

I don't know if I need to change the settings of CMD or if it's related to the Mosquitto configuration file.

英文:

I'm running an example of a program that publishes a randon temperature in Python and using mosquitto to show it on the CMD. This is the code of my program

import paho.mqtt.client as mqtt
import time
import json
import uuid

import control

BROKER = "localhost"
PORT = 1883
NOTIFICATION_TOPIC = "oan/spm/tel15/ccd/notification"

TEMP_MIN = -110.9
TEMP_MAX = -100.5

id = uuid.uuid4()

client = mqtt.Client(client_id=str(id))
client.connect(BROKER, PORT, 60)
client.loop_start()

while(True):
    data = dict()
    data["ccd"] = "Marconi 2"
    data["temp"] = control.get_random_temperature(TEMP_MIN, TEMP_MAX)

    client.publish(NOTIFICATION_TOPIC, json.dumps(data), retain=True)
    time.sleep(10)

And it works, but the message I get in the CMD look like this

1687366819: Received PUBLISH from 3c60bffd-8a69-4f7d-90ae-982d725afdd7 (d0, q0, r1, m0, 'oan/spm/tel15/ccd/notification', ... (36 bytes))

It doesn't show the full message and instead it shows only ...(36 bytes). What do I need to do to show the full message?

I don't know if I need to change the settings of the CMD or is it with the mosquitto conf file.

答案1

得分: 2

经纪人不应该打印出您发布到它的完整消息,即使启用了调试日志记录。

如果您想查看这些消息,您需要编写另一个Python应用程序来订阅这些消息,或者使用类似于 mosquitto_sub 的工具来将它们打印出来。

例如,

 mosquitto_sub -v -t '#'
英文:

The broker is not supposed to print out the full messages you publish to it, even with debug logging enabled.

If you want to see the messages you will need to either write another python app to subscribe to the messages or use a tool like mosquitto_sub to print them out.

E.g.

 mosquitto_sub -v -t '#'

答案2

得分: 0

@hardillb正确!

在这种情况下,一个连接的客户端发送了一条发布消息,但没有客户端订阅了相关主题(oan/spm/tel15/ccd/notification),以便接收消息。订阅该主题的客户端将成功接收带有相关36字节有效负载的消息。

在进行测试时,我建议使用HiveMQ MQTT CLI工具,它提供了一些出色的客户端功能,而不需要在开发发布客户端时实现订阅客户端。

此外,如果您刚开始使用MQTT,我强烈推荐阅读HiveMQ MQTT Essentials系列,它提供了关于MQTT的简明介绍。https://www.hivemq.com/mqtt-essentials/

最好的祝愿,

HiveMQ团队的Aaron

英文:

@hardillb has the right of it!

In this instance, a publish message was sent from a connected client, but no clients were subscribed to the associated topic (oan/spm/tel15/ccd/notification) in order to receive the message. A client subscribed to that topic would successfully receive a message with the relevant 36 byte payload.

While performing testing, I recommend using the HiveMQ MQTT CLI tool, which offers some great client functionality without having to implement a subscribing client while developing a publishing client.

Additionally, if you happen to be new to MQTT as a whole, I highly recommend the HiveMQ MQTT Essentials series, which provides a great, bite-sized breakdown of all things MQTT. https://www.hivemq.com/mqtt-essentials/

Best,

Aaron from the HiveMQ Team

huangapple
  • 本文由 发表于 2023年6月22日 01:03:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76525625.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定