🔴 ALLES über MQTT in nur 14 Minuten, einfach erklärt! | #EdisTechlab
Summary
TLDRThis Edis Techlab video delves into MQTT, a network protocol for machine-to-machine communication, originally designed for minimal battery and bandwidth usage in remote systems. It explains the protocol's evolution to IoT applications, the client-server model with a broker at its core, and the roles of publishers and subscribers. The video covers MQTT topics, wildcards, Quality of Service levels, retained messages, persistent sessions, and the Last Will and Testament feature. It also touches on keep-alive mechanisms ensuring active connections, promising a practical MQTT application in the next episode.
Takeaways
- 📚 MQTT stands for Message Queuing Telemetry Transport, a network protocol for machine-to-machine communication.
- 🛠️ It was developed in 1999 by Dr. Andy Stanford-Clark and Ellen Neibach, primarily for low battery and bandwidth connectivity, such as satellite connections to oil pipelines.
- 🔄 MQTT's focus has shifted from embedded systems to the Internet of Things (IoT) and became an OASIS standard on October 29, 2014.
- 🌐 It operates on a client-server model with a broker at the center, similar to a post office, filtering and distributing messages to subscribers.
- 🔄 MQTT clients can act as both publishers and subscribers, depending on whether they are sending or receiving messages.
- 📈 Topics in MQTT are used for message filtering and can consist of multiple levels separated by slashes, with certain rules for structuring them effectively.
- 🌟 MQTT supports topic wildcards, allowing clients to subscribe to multiple topics simultaneously, using single-level (+) and multi-level (#) placeholders.
- 📉 Quality of Service (QoS) levels in MQTT range from 0 (At Most Once) to 2 (Exactly Once), determining message delivery guarantees and reliability.
- 🔒 Retained messages allow the broker to store the last message on a topic, ensuring that new subscribers immediately receive the most recent data.
- 🔄 Persistent sessions help maintain subscriptions across client reconnections, conserving resources by avoiding the need to resubscribe to topics.
- 🗝️ Last Will and Testament is a feature that allows a client to leave a final message to be sent in the event of an unexpected disconnection.
- 🕒 Keep-alive is a mechanism to ensure an active connection between the client and broker by sending ping requests within a specified time frame.
Q & A
What does MQTT stand for and what is its primary purpose?
-MQTT stands for Message Queuing Telemetry Transport. It is a network protocol for communication between machines, primarily designed for minimum battery loss and minimum bandwidth usage, originally to connect to oil pipelines via satellite.
Who developed the MQTT protocol and when was it developed?
-The MQTT protocol was developed in 1999 by Dr. Andy Stanford-Clark from IBM and Ellen Neibach from Agrom, now at CirrusLink.
What does OASIS stand for and when did MQTT become an officially recognized OASIS standard?
-OASIS stands for Organization for the Advancement of Structured Information Standards. MQTT became an officially recognized OASIS standard on October 29, 2014.
What is the role of a broker in MQTT communication?
-In MQTT communication, the broker acts as a central hub, similar to a post office, filtering all incoming messages and sending them to the appropriate subscribers, ensuring that senders and subscribers never have direct contact with each other.
Can an MQTT client be both a publisher and a subscriber?
-Yes, an MQTT client can be both a publisher and a subscriber, depending on whether the client is currently sending or receiving messages.
What are the basic rules for structuring MQTT topics?
-The basic rules for MQTT topics include: being case sensitive, not starting with a dollar sign, not using a slash at the beginning, avoiding spaces, keeping topics short to save resources, and not using special characters.
What are the two types of wildcards used in MQTT topics for subscribing to multiple topics at once?
-The two types of wildcards are single-level placeholders (represented by a plus sign '+') and multi-level placeholders (represented by a hash sign '#').
What does QoS stand for and what are the three levels of QoS in MQTT?
-QoS stands for Quality of Service. The three levels are: 0 - At Most Once (Fire and Forget), 1 - At Least Once, and 2 - Exactly Once.
What is the purpose of the Last Will and Testament feature in MQTT?
-The Last Will and Testament feature allows a client to save a message on the broker, which will be sent to all clients subscribed to the Last Will Topic if the client loses connection to the broker.
What is the function of the keep-alive mechanism in MQTT?
-The keep-alive mechanism defines a time interval in which communication between the client and the broker must occur. If no communication happens within this interval, the client sends a ping request to ensure the connection is still active, and the broker responds to confirm the connection.
What is a retained message in MQTT and how does it differ from a non-retained message?
-A retained message in MQTT is a message that is saved in the broker and sent to new subscribers immediately upon their subscription. A non-retained message is deleted if no one is subscribed to it, and new subscribers will only receive messages sent after their subscription.
What is the significance of a persistent session in MQTT and how does it differ from a non-persistent session?
-A persistent session in MQTT ensures that the topics to which a client has subscribed are not lost when the connection is terminated. The client will automatically reconnect to all subscribed topics upon reconnection. In contrast, a non-persistent session requires the client to resubscribe to topics with each new connection.
Outlines
📚 Introduction to MQTT Protocol
This paragraph introduces the MQTT protocol, which stands for Message Queuing Telemetry Transport, designed for machine-to-machine communication with an emphasis on minimal battery consumption and bandwidth usage. Developed in 1999 by Dr. Andy Stanford-Clark and Ellen Neibach, MQTT was initially intended for satellite communication with oil pipelines but has since evolved to support IoT applications. It operates on a client-server model with a broker acting as a message filter and distributor. The protocol allows clients, which can be sensors or devices like laptops or phones, to publish and subscribe to topics, enabling efficient data exchange. The paragraph also covers basic MQTT topic structures, wildcards for subscribing to multiple topics, and the importance of adhering to certain rules for effective communication.
🔄 Understanding MQTT's Quality of Service (QoS) and Retained Messages
This section delves into MQTT's Quality of Service (QoS) levels, which determine the reliability of message delivery. QoS 0, 'At Most Once', is the least reliable, with messages sent without confirmation. QoS 1, 'At Least Once', ensures message delivery by using packet IDs and acknowledgments, which may result in message duplication. QoS 2, 'Exactly Once', guarantees unique message delivery through a four-step handshake process involving packet IDs and multiple acknowledgment packets. The paragraph also explains retained messages, which allow the broker to store the last published message on a topic for new subscribers, ensuring they receive the most recent data upon subscription.
🔒 MQTT Connection Management and Last Will and Testament
The final paragraph discusses MQTT's connection management features, including persistent sessions that allow clients to maintain their subscription state across reconnects by setting a 'clean session' flag to false. It also introduces the concept of 'Last Will and Testament', a feature that allows clients to send a final message in case of an unexpected disconnection. The paragraph explains how to set up a persistent connection, the process of subscribing to topics with different QoS levels, and the automatic reconnection to topics upon reestablishing a connection. Additionally, it covers the 'keep-alive' mechanism, which ensures the connection remains active by exchanging ping requests and responses between the client and broker. The paragraph concludes with an invitation to a future practical MQTT application example involving a pushbutton and an LED.
Mindmap
Keywords
💡MQTT
💡IoT (Internet of Things)
💡OASIS Standard
💡Broker
💡Client
💡Topic
💡Wildcards
💡Quality of Service (QoS)
💡Retained Messages
💡Persistent Session
💡Last Will and Testament
💡Keep-Alive
Highlights
MQTT stands for Message Queuing Telemetry Transport, a network protocol for machine-to-machine communication.
Developed in 1999 by Dr. Andy Stanford-Clark and Ellen Neibach for minimum battery loss and bandwidth to connect oil pipelines via satellite.
MQTT's primary focus has shifted from embedded systems to open Internet-of-Things (IoT).
On October 29, 2014, MQTT became an officially recognized OASIS standard.
MQTT operates on the client-server principle with a broker at the center of communication.
A client can be a sensor, actuator, or any device capable of sending or receiving data to/from the broker.
MQTT topics are used by the broker to filter messages and consist of one or more topic levels separated by slashes.
Topics are case sensitive and have basic structural rules for clarity and efficiency.
Topic wildcards allow clients to subscribe to multiple topics simultaneously.
QoS (Quality of Service) levels determine message delivery reliability: At Most Once, At Least Once, and Exactly Once.
Retained messages allow the broker to store the last message on a topic for new subscribers.
Persistent sessions maintain client subscriptions across connection interruptions.
Last Will and Testament allows a client to leave a final message to be sent in case of abrupt disconnection.
Keep-alive mechanism ensures the connection is active by sending ping requests.
Upcoming practical MQTT application example: Reading a pushbutton signal to switch on an LED via MQTT.
Edis Tech Lab offers a DIY home automation book with growing content and early bird pricing.
Transcripts
Hello and welcome to Edis Techlab. Today's video is about MQTT. I have before
already made a video about it a long time ago about it. If you want it short and sweet,
I'll link you to it below in the video description the link to it. If you want it in detail,
you can now look forward to it. And after this video I am sure that EVERYONE CAN DO IT!!!
MQTT stands for Message Queuing Telemetry Transport and is a network protocol for
communication between machines to machines. The MQTT protocol was developed in 1999 by Dr. Andy Stanford-Clark
by IBM and Ellen Neibach at the time from Agrom and now at CirrusLink
invented. They needed a protocol for minimum battery loss and minimum bandwidth,
to connect to oil pipelines via satellite. via satellite. However, the primary
focus of the protocol has shifted from embedded systems to open Internet-of-Things, the so-called IoTs,
modified. On October 29, 2014, MQTT became an officially recognized OASIS standard. OASIS stands for
for Organization for the Advanced of Structured Information Standards. MQTT works according to the
so-called client-server principle. At the center of every MQTT communication is the broker. The
broker is like a post office, so to speak. The senders and subscribers never
in direct contact with each other. All incoming messages are filtered by the broker and sent to the
subscribers. A client can now be a be a sensor, such as a temperature sensor, a
actuator or any output device such as a fan fan or even a laptop or telephone. Any
participant can send data to the broker. Here example, the temperature sensor, which measures 20 degrees
to the temperature topic. If the fan is interested in the temperature data, it can send
subscribe to the temperature topic and receives receives the 20 degrees from the MQTT broker. On
MQTT client can be both a publisher and a subscriber, depending a subscriber, depending on whether the client is currently
is sending or receiving messages. Let's take a look at now take a closer look at the MQTT topic. The topic,
translated topic, is used by the broker to filter messages messages from all clients. The topic
consists of one or more topic levels. Each topic level is separated by a slash
separated by a slash. Which structure you choose for your topics for your topics is up to you and there are so
almost no restrictions. Nevertheless, there are a a few basic rules for a clean topic structure.
The topics are case sensitive. capitalization. The dollar sign
must not be used at the beginning of a topic as it is used for internal statistics by the broker
is used for internal statistics. Do not use the slash at the beginning of a topic. It is allowed, but
This creates another topic label, which is filled with a zero character and nothing
brings. Do not use spaces in the topics. These are difficult to read and you can
Avoid mistakes. Use short topics. These are sent with every message and you
do not waste unnecessary resources. As a last point, do not use special characters. These
are often displayed incorrectly and the use of of umlauts or special characters is not recommended.
recommended. Next, let's take a look at the Topic wildcats. When a client subscribes to a topic,
he can subscribe to the exact topic of a published message or it can subscribe to placeholders
to subscribe to several topics at the same time. at the same time. There are single-level placeholders
and multi-level placeholders. With the plus sign can be used to replace one or more topic levels.
Let's take an example. Let us assume we assume that all temperatures in the
first floor. The wildcard is used for the different rooms on the first floor.
The wildcard now replaces the various rooms, such as the kitchen in this example,
the storage room or the terrace. With the hash sign replaces several topic labels
and the hash sign is always in the last position position and replaces the subsequent topic labels,
regardless of how deeply they are nested. With this wildcard we get all the data that we
from the first floor. For example the kitchen, temperature and humidity,
whether the light is on in the storage room or the temperature on the terrace. Now we come to
to QoS. This stands for Quality of Service Level. The lowest quality of service level is 0.
And it is called At Most Once, i.e. at most once. The message is sent after
is not saved or sent again. This method is also called Fire and Forget.
The QoS1 label stands for at least once, i.e. at least once. This QoS1 label guarantees,
that a message reaches the recipient at least once. recipient at least once. And that is also
the most frequently used. The sender sends a packet ID when sending each message
and stores it until receipt of the message is confirmed with a message is confirmed with a pub-back packet.
The Pub-Back stands for Publish Acknowledgement and contains the packet ID to ensure
that the correct message has been received. If the sender does not receive a Pub-Back packet,
then it sends the message again and marks it as a duplicate. This makes it possible,
that the message is sent multiple times. QoS 2 exactly once,
the last and highest level of QoS guarantees that each message is only sent once to a recipient
arrives only once. The packet ID of the message is also sent by Abender and the message
is saved. The broker confirms receipt of the of the message with a PubRec packet. This is
for Publish Received. If the sender does not receive a PubRec packet, the message is sent again at
is sent again and marked as a duplicate. If the sender has received the PubRec packet, the message
is deleted and a PubRel packet, Publish Release, is sent to the recipient. The receipt is confirmed by the
Broker confirms receipt by sending a PubComp package, Publish Complete, with the package ID as content to the
sender. The additional messages delays the delivery and valuable
bandwidth is required for QoS 2. If you want to learn more about MQTT, I can provide you with a
good book. You can find it in the e-book store at Edis Tech Lab on the website. For only 99
cents. If you would rather have all the projects, then I recommend the DIY home automation book
in the Early Bird Edition. Here you will find all Edis Tech Lab projects and the book is growing
month by month. If you buy the book early you can really save money, because by
the increased content, the price is also slightly month slightly adjusted. Many thanks in advance!
Retained messages, or withheld messages.
When a temperature sensor sends a message to the broker, the message,
is deleted again if no one has subscribed to it. If a client now subscribes to the temperature topic,
then he will not receive a message. He must now wait until the temperature sensor sends new
sends new data. Only then will the broker make this data available to him. A display
for the temperature would not display a value after the connection with a topic would not display a value for this long,
until a temperature sensor sends a new value to the sends a new value to the topic. This state can be bypassed,
by the client setting the retained flag sets the retained flag to true. This will
the temperature value is saved in the broker. If the client now subscribes to the temperature topic,
then the broker will immediately display the temperature value that is stored,
will be sent back to him. This means that the temperature display instead of no value at all, at least an older
instead of no value at all. Persistent session or the permanent connection connection If a non-persistent session
between the client and the broker is terminated, the topics to which the client has subscribed are lost,
are lost. With each new connection, the client must log in again for all topics
and this costs a lot of resources. To avoid this problem to avoid this problem, the client can connect to the
broker can request a permanent connection. To do this a clean session flag is set in the connect package
is used. If this is set to False, a permanent connection is created. At
True is not. The broker confirms this with a Connection Acknowledgement packet. After the
connection is established, the client can subscribe to all subscribe to all the topics it wants. This can be
in the form of a list where the topic and the corresponding associated Quality of Service is specified.
The broker now saves all information that is relevant for the client and sends a
Subscribe-Acknowledge packet. If the connection is interrupted and the client reconnects with the
broker, then all messages with a QoS with a QoS 1 and QoS 2, which it still wants to receive.
has not yet received. And it is automatically reconnected reconnected to all topics to which he has subscribed.
If you haven't done so yet, now is a good time a good time to subscribe to the channel and
to press the little bell. While you're at it I would of course also appreciate a Like
very much. Now we come to Last Will and Testament, which means the last will and testament.
the will. With the Last Will and Will function can be used in the broker at the first
the will can be saved by the client on the first be saved. The Last Will and Testament is a
normal MQTT message in the Connect package. Here we can specify the Last Will Topic with the
associated Quality of Service number. In the Last Will Message we can write the text,
that we want to store as a will. With Last Will Retain we specify whether we want to use
whether we want to save the message in the broker. The The broker confirms receipt of the connect packet
with a Connection Acknowledge packet. If the client loses the connection to the broker, then
the broker sends the Last Will message to all clients clients that have subscribed to the Last Will Topic.
We have almost done it. Now the Keep-alive and then we'll be through.
With keep-alive we define a time in seconds, in which communication between the client
and the broker must take place. If no message is sent within this no message is sent during this specified time,
then the client sends a ping request is sent by the client. This ping request packet
is then confirmed by the broker with a ping response by the broker. This allows us to ensure that
that the connection is still active. If the keep-alive time is exceeded by 50% without
a message has been sent, then the broker broker terminates the connection to the client. If the client
does not receive the ping response file from the broker, then the client disconnects from the broker.
Next week we will then make a practical application example for MQTT. We will read
a pushbutton signal and switch on the LED on the other the LED on the other microprocessor using MQTT.
See you next week. Your Edi. If you liked the video, please give me a
Thumbs up. Subscribe to the channel. Thank you very much for watching. See you next time. Edis Techlab
Weitere ähnliche Videos ansehen
5.0 / 5 (0 votes)