Search code examples
pythoncmdmqttmosquittopaho

(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 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.


Solution

  • @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