18 Temmuz 2019 Perşembe

MQTT

Giriş
Message Queue Telemetry Transport kelimelerinin baş harfleridir. MQTT Sürüm 3.1.1'den sonra MQTT bu kelimelerin kısaltması değildir deniyor. Bu durumda neyin kısaltması oluyor ben de anlamadım :)
Starting with Version 3.1.1, MQTT does not stand for Message Queue Telemetry Transport anymore.
Open Source Broker'lar
Seçenekler şöyle.
- HiveMQ
- Eclipse Mosquitto
- VerneMQ
Mosquitto Broker
Mosquitto MQTT protokolünü gerçekleştirir. Konfigürasyon dosyası mosqitto.conf dosyasıdır. Mosquitto Raspbery Pi üzerinde çalışabilir.

Telemetry  Nedir? 
Açıklaması şöyle
Telemetry technology allows things to be measured or monitored from a distance.
Ne Zaman MQTT
Noktadan noktaya iletişim yoksa MQTT uygun bir protokol. Açıklaması şöyle.
About IoT protocols, most commonly HTTP, CoAP and MQTT are used on communication.

HTTP and CoAP are suitable for REST type of client(s) to server communication and MQTT supports publishing and subscribing based multi user communication, where the origin can easily be from server to client, client to server and even client to client.
MQTT ve RPC
RPC tarzı çağrılar yapmak direkt mümkün değil. Bazı kütüphanaler publish-subscribe mekanizmasını sarmalayarak RPC taklidi yapabiliyor. Bu açıdan MQTT arakatmanı (middleware) Data Distribution System (DDS) arakatmanına benziyor.

MQTT ve Websocket
Açıklaması şöyle.
Most MQTT brokers currently available on the market provide native support for WebSockets, thus enabling any MQTT JavaScript library to establish communications by encapsulating MQTT messages into WebSocket frames: This is called the MQTT Over WebSocket

The great benefit of this approach is to allow all modern browsers, including those running on smartphones, to send and receive MQTT messages. This has the effect of stretching out the protocol to the web, making it more and more attractive for M2H (machine to human) scenarios, too.
MQTT-SN
Kardeş protokol. Açıklaması şöyle
MQTT has to run over TCP/IP but it's sister protocol MQTT-SN can be run over nearly any protocol that can pass data, I've seen implementations in UDP and serial.
Protocol
MQTT binary bir protocol. Mesaj zarfında source gibi bir alan bulunmuyor. Açıklaması şöyle
There is no information about who published the message included in the message header, only the topic and any retained flags.

QoS Parametreleri
Açıklaması şöyle
No guarantees are made about the relative ordering of messages published with different QoS values. (for example, QoS 0 can over take QoS 2 for example as it involves a single packet rather than the 4 packets of the latter).
1. QoS 0 - At most once delivery
Udp gibi gibidir.  Mesaj kaybolabilir. Açıklaması şöyle
QoS 0 messages will be delivered in order (albeit messages may get lost)
2. QoS 1 - At least once delivery
Açıklaması şöyle
QoS 1 allows for message duplicates - it is possible a duplicate will arrive after the first instance of the next message that was published.

QoS 1 ordering can be guaranteed if the client/broker only allow a single message inflight at any time.
3. QoS 2 - Exactly once delivery
TCP gibidir. Mesaj kaybolmaz ve sadece bir kere gelir.Açıklaması şöyle
QoS 2 messages will be delivered in order

Broker
MQTT sunucusu broker olarak anılır. Tüm cihazlar bu sunucuya bağlanır. Açıklaması şöyle
In MQTT, clients (both the IoT device and user devices) make outbound connections to the broker, and the broken shares messages which are "published" on a "topic" by one client to all clients which have "subscribed" to that "topic" topic.
MQTT Broker'ı dış dünyaya açmak için seçenekler şöyle
1. Use a broker in the cloud so client from home always connect out to it. Use TLS and authentication so others can't eavesdrop or inject unwanted messages
2. Use a cloud broker and set up a bridge between the internal broker and cloud broker (you still want to encrypt and set username/password on the cloud broker). This has the advantage that internal things keep working if the internet connection goes down.
3. A VPN on all external devices to allow access to your home network (but, to be honest, you're probably going to have to either open a port for the VPN or have a router that supports being a VPN server)
Message Buffering
Açıklaması şöyle.
MQTT’s advanced message retention policies and offline message queuing are essential to accommodating network latency and unreliable mobile networks.

Topic İsimleri
Topic isimleri slash yani / karakteri ile hiyerarşik hale getirilir. Topic ismi şöyledir.
device1-id/sensor1-id
device1-id/sensor2-id
Single Level Abonelik
Artı (+) işareti kullanılır.

Örnek
Elimizdeki topic ismi şöyle olsun.
myhome/groundfloor/+/temperature
Şu kanallara abone olunur.
myhome/groundfloor/livingroom/temperature
myhome/groundfloor/kitchen/temperature
Multi Level Abonelik
Diyez (#) işareti kullanılır.

Örnek
Elimizdeki topic ismi şöyle olsun.
+/groundfloor/#

Şu kanallara abone olunur.

myhome/groundfloor/livingroom/temperature
myhome/groundfloor/kitchen/brightness
garage/groundfloor/fridge/temperature/more/specific/fields
MQTT ve Bağlantı
Açıklaması şöyle
The good news is, that a MQTT client only needs to establish a connection once per session – in contrary to protocols like HTTP, which needs to re-establish a connection on every request (if no keep-alive is used or other techniques like Long Polling are in place). Once connected to the broker, the client can send and receive messages without any additional handshake overhead. The use of TLS needs to allocate additional buffers, so RAM consumption is also slightly higher per MQTT connection.
MQTT ve TLS
Açıklaması şöyle.
According to Stanford-Clark, security was consciously left out of the protocol initially because he and Nipper knew security mechanisms could be wrapped around MQTT to boost security. Also, at the time, Stanford-Clark said information sent via MQTT, such as wind speed data from a weather station, wasn't particularly in need of securing.


Hiç yorum yok:

Yorum Gönder