MQTT筆記1

Topic:

A topic is a named logical channel and it is also referred to as a channel or subject. The broker will send publishers only the messages published to topics to which they are subscribed.

The Raspberry Pi 3 board publishes a message with 100 feet as the payload and sensor1/altitude as the topic.

MQTT Client:

Any device that has a TCP/IP stack and is capable of using an MQTT library can become an MQTT client, that is, a publisher, a subscriber or both a publisher and a subscriber. The MQTT library makes it possible for the device to talk MQTT on top of TCP/IP and to interact with specific types of MQTT servers. For example, any of the following can become an MQTT client: an Arduino board, a Raspberry Pi 3 board, an Intel Joule board, an iPhone, an iPad, a laptop running Windows, a server running Linux, a Macbook running macOS, and Android tablet, among other devices.

MQTT Server:

Throughout this book, we will work with the Eclipse Mosquitto MQTT server (http://www.mosquitto.org). Mosquitto is an open source MQTT server with an EPL/EDL license that is compatible with MQTT versions 3.1 and 3.1.1. We can take advantage of everything we learn with any other MQTT server such as Erlang MQTT Broker (EMQ), also known as EMQTT (http://www.emqtt.io), and HiveMQ (http://hivemq.com), among others. In addition, we might use our knowledge to work with a cloud-based MQTT server such as CloudMQTT (http://www.cloudmqtt.com).

Authentication and Authorization:

Publish: QoS 0

C:\Program Files\mosquitto>mosquitto_pub -V mqttv311 -t sensors/drone01/altitude -m "10 f" -d
Client mosq/iegxvI2NaT03FjtmWK sending CONNECT
Client mosq/iegxvI2NaT03FjtmWK received CONNACK (0)
Client mosq/iegxvI2NaT03FjtmWK sending PUBLISH (d0, q0, r0, m1, 'sensors/drone01/altitude', ... (4 bytes))
Client mosq/iegxvI2NaT03FjtmWK sending DISCONNECT

Subscribe: QoS 0

C:\Program Files\mosquitto>mosquitto_sub -V mqttv311 -t sensors/drone01/altitude -d
Client mosq/0drFODuX39byfDBWxx sending CONNECT
Client mosq/0drFODuX39byfDBWxx received CONNACK (0)
Client mosq/0drFODuX39byfDBWxx sending SUBSCRIBE (Mid: 1, Topic: sensors/drone01/altitude, QoS: 0, Options: 0x00)
Client mosq/0drFODuX39byfDBWxx received SUBACK
Subscribed (mid: 1): 0
Client mosq/0drFODuX39byfDBWxx received PUBLISH (d0, q0, r0, m0, 'sensors/drone01/altitude', ... (4 bytes))
20 f

Publish: QoS 2

C:\Program Files\mosquitto>mosquitto_pub -V mqttv311 -t sensors/drone03/speed/rotor/1 -m "362 f" -q 2 -d
Client mosq/mAXmaOXN6weTK0gLJ4 sending CONNECT
Client mosq/mAXmaOXN6weTK0gLJ4 received CONNACK (0)
Client mosq/mAXmaOXN6weTK0gLJ4 sending PUBLISH (d0, q2, r0, m1, 'sensors/drone03/speed/rotor/1', ... (5 bytes))
Client mosq/mAXmaOXN6weTK0gLJ4 received PUBREC (Mid: 1)  
Client mosq/mAXmaOXN6weTK0gLJ4 sending PUBREL (m1)
Client mosq/mAXmaOXN6weTK0gLJ4 received PUBCOMP (Mid: 1, RC:0)
Client mosq/mAXmaOXN6weTK0gLJ4 sending DISCONNECT

Subscribe:QoS 2

C:\Program Files\mosquitto>mosquitto_sub -V mqttv311 -t sensors/drone03/# -q 2 -d
Client mosq/HandUbV2zBwXkQqeTB received PUBLISH (d0, q2, r0, m1, 'sensors/drone03/speed/rotor/1', ... (5 bytes))
Client mosq/HandUbV2zBwXkQqeTB sending PUBREC (m1, rc0)
Client mosq/HandUbV2zBwXkQqeTB received PUBREL (Mid: 1)
Client mosq/HandUbV2zBwXkQqeTB sending PUBCOMP (m1)
362 f

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章