K.V.Lucky
K.V.Lucky

Reputation: 51

Is there any way that I can store all the recieved messages at MQTT client side?

I was running Mosquitto broker on my PC.

I opened two command prompt windows in the same PC. From the first window, I published the message "First_Message" with the topic name 'Hello' using this command.

mosquitto_pub -d -t Hello -m "First_Message"

From another command window, subscribed to the same topic using:

mosquitto_sub -d -t Hello

Then I was able to see the "First_Message" received and printed in command window.

Now, what exactly I need is rather than printing this message in that command window, is there any way that I can store this received message in a text file on the same PC.

Upvotes: 2

Views: 3027

Answers (1)

hardillb
hardillb

Reputation: 59816

Just pipe the output to a file using normal shell conventions.

moquitto_sub -t Hello > log_file.txt

If you want to have the topic name prefixed to the payload use the -v command line argument. There should be no need to use the -d option

moquitto_sub -v -t Hello > log_file.txt

Upvotes: 2

Related Questions