CONTROLLING A LED FROM THE HIVEMQTT BROKER IN WINDOWS:
Installing HIVEMQTT platform:
Download the first link and run in powershell as administrator. Windows will install the files. In some computers JRE (Java runtime environment) needs to be installed. If needed install JRE also.
file link (windows power shell) for uninstalling Hivemqtt platform:
Open windows cmd (WIN + R)
Go to folder by typing cd c:\hivemq\tools\mqtt-cli\bin
We are going to use mqtt cli (command line interface) in command window
Type mqtt – help to view help commands
C:\Hivemq\tools\mqtt-cli\bin>mqtt --help
To publish a message in hive mqtt broker:
C:\hivemq\tools\mqtt-cli\bin>mqtt pub --host broker.hivemq.com --port 1883 --topic your/topic --message "Hello World"
Now open another command window and type the subscribe mqtt command
In the second command window type the following command
mqtt sub --host broker.hivemq.com --port 1883 --topic your/topic
NOTE : the published and subscribed topic names should be same. Port 1883 indicates this is a simple TCP connection unsecured and unauthorised . For secured connection the port number is different
CONTROLLING AN LED IN ESP 8266:
In the esp8266 or esp32 install micropython and also install umqtt simple from library
Or else you can copy the file from our github repository
https://github.com/muceetech/hivemqtt_espled
Save the following program as main.py in esp8266 or esp32 from Thonny ide
https://github.com/muceetech/hivemqtt_espled/blob/main/mqtt_ledcontrol.py
once you are running your esp8266 you will get the message in console that the mcu is connected to hivemqtt broker and subscribed to topic “esp\led”
On the computer give the following commands in command window to ON or OFF the led based on the message given to the led.
Publish a message to switch on the led: (in windows command window)
mqtt pub --host broker.hivemq.com --port 1883 --topic esp/led --message "on"
Publish a message to switch off the led: (in windows command window)
mqtt pub --host broker.hivemq.com --port 1883 --topic esp/led --message "off"
Note: once the message is send from windows no notification will come. If sent successfully the command prompt will be shown after a few seconds. The response may take less than 2 seconds to send the message.
On the thonny ide shell window you can see the message received by esp from the mqtt broker













