Installing Jupyter notebook
[Link] open link and follow below instructions.
Installing Jupyter notebook
Installing Jupyter notebook
Click on next next then wait for complete installation.
Once installation is done
Search for anaconda navigator
Installing Jupyter notebook
Click on open.
This window will show.
Now click on Jupyter notebook (Launch button)
Below window will open in your browser.
Here search for your downloaded Ipynb file
IOT mqtt protocol practical [Link] file
Installing Jupyter notebook
As I created file(name- IOT as shown in lab lecture 3 ) in desktop
I clicked on desktop and
Double click on IOT Mqtt protocall [Link]
It will show like above
Installing Jupyter notebook
Installing Jupyter notebook
Code Explanation Step-by-Step Breakdown:
1. Connects to an MQTT Broker
o Uses the public broker HiveMQ ([Link]).
o Subscribes to a specific topic: "IOT/light/control/your bits id" (which
should be unique per user ).
o Listens for messages published on this topic.
2. Receives and Processes MQTT Messages
o When a message is received:
▪ If the message is "1", the light turns Green (ON).
▪ If the message is "0", the light turns Red (OFF).
▪ If an unexpected message is received, it prints an error.
3. Displays a GUI with a Virtual Light Indicator
o Uses Tkinter to create a window.
o A circle is drawn on a canvas to represent the light.
o The light starts red (OFF) and changes color based on MQTT messages.
4. Keeps Running and Updates in Real Time
o The program continuously listens for MQTT messages.
o If the window is closed, the MQTT connection is disconnected properly.
Summary
🔹 Listens for MQTT messages on a specific topic.
🔹 Displays a virtual light in a GUI using Tkinter.
🔹 Changes the light's color based on MQTT messages.
🔹 Handles proper connection and disconnection from the MQTT broker.
Installing Jupyter notebook
Once you run this code
This type of popup will come on window (please search it will pop up anywhere in your
window)
Installing Jupyter notebook
Then open IOT application on your mobile :
[Link]
hare
Open application IOT MQTT panel
Installing Jupyter notebook
Click on Setup connection.
Installing Jupyter notebook
After typing all click on + button
Installing Jupyter notebook
Give the dashboard a name, such as "Light" (or feel free to choose any other name) and click on save.
Installing Jupyter notebook
Click on create button
Installing Jupyter notebook
Click on any name (as per your given name, it will show).
Installing Jupyter notebook
Click on ADD panel
Installing Jupyter notebook
Click on Switch button
IOT/light/control/2023ab05195 # MQTT topic (must be unique per user change with ur Bits ID )
Installing Jupyter notebook
Topic should be as per given in code (for me it was IOT/light/control/2023ab05195 as per that I entered here)
Installing Jupyter notebook
Click on Create button.
Installing Jupyter notebook
That button will get added.
Now as your code is already running in pc and if u click on this button it will send message.
Now perform the practical as per instructions given in lab lecture 3.