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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值