Windows Command prompt as Publisher and Subscriber

Before you start using Windows Command Prompt as Publisher and Subscriber, You need to install MQTT Broker on Windows Machine or Computer.
Please click the following link for installing MQTT broker on Windows machine.
Installing MQTT Broker on Windows Computer

1)Open Command Prompt as Administrator. Steps given below.
Search command Prompt in your computer -> Right click on command prompt -> Run as Administrator

2)Navigate to Mosquitto Installed folder or path. For navigation use following command
cd C:\Program Files (x86)\mosquitto

3)Execute the following Command to Subscribe topic test.

mosquitto_sub -t test -h localhost


Host name(-h) is localhost because Broker and subscriber are running on same the machine. You can also use host name as IP address of Computer on which broker is installed.

As there is no publisher at the moment , you won’t receive¬† the data , to receive data please follow the following publisher steps in another command prompt and then check the subscriber terminal to see received data.

1)Open another Command Prompt as Administrator.
2)Navigate to mosquitto installed folder or path.
3)Execute the following Commands to Publish message Temp:10 & Temp:20.

mosquitto_pub -t test -h localhost -m “Temp:10”
mosquitto_pub -t test -h localhost -m “Temp:20”


Host name(-h) is localhost because Broker and Publisher are running on same the machine. You can also use host name as IP address of Computer on which broker is installed.

Now check your Subscriber command prompt, you should get data
Temp:10
Temp:20
;

You may also like...

Leave a Reply