狠狠撸

狠狠撸Share a Scribd company logo
MQTT协议说明
eric.xiao
ericssonxiao@gmail.com
谁创造了MQTT协议?
在1999年,来自IBM公司的Andy Stanford-Clark 和 来自Arcom (现在改名为
Eurotech)公司的Arlen Nipper创造了MQTT协议。
Dr Andy Stanford-Clark Arlen Nipper
惭蚕罢罢协议的发展历程
标准化组织
? 2013年3月, MQTT 协议提交到OASIS组织并不断演进过程中。
? MQTT协议规格书被公开发布,它使用免版税的许可证,Eurotech
公司(之前的名字是 Arcom) 在他们的产物中实现了这个协议。
? 在2011年11月IBM 和 Eurotech 公司对外宣布加入Eclipse M2M
Industry 工作组 并捐赠 MQTT 代码给Eclipse Paho 项目组。
惭蚕罢罢协议在物联网中的位置
什么是MQTT协议?
MQTT 是消息队列遥感传输协议
的缩写(Message Queueing
Telemetry Transport
Protocol).
? 基于轻量级代理的发布/订阅协议
? 开放
? 简单
? 容易实现
所以它能够应用在资源受限的环
境中.
例如:
? 传感器
? 手机移动设备及平板电脑
? 物联网 (IoT)
发布/订阅 协议
发布/订阅 协议(简单的场景)
发布/订阅消息模式支持广播
MQTT 协议规格书
MQTT 协议规格书
? MQTT v3.1 -- MQTT V3.1 协议规格书
它是一个基于TCP/IP协议的,可提供发布/订阅消息模式的,十分轻量
级的通信协议
? MQTT v3.0 -- MQTT V3.0 协议规格书
它是一个基于TCP/IP协议的,可提供发布/订阅消息模式的,十分轻量
级的通信协议
? MQTT-SN v1.2 -- MQTT for Sensor Networks V1.2 协议规格书
它是一个基于非TCP/IP协议的(例如:ZigBee协议),专门为嵌入式
设备提供消息通信模式的协议
设计原理和假设条件
? 简单,简单,简单!
? 发布/订阅消息传递
? 零管理,零配置
? 低带宽占用
? 预料并且满足网络的频繁中断带来的问题。
(低带宽, 高等待时间, 不可靠, 高成本的网络)
? 可提供持续的会话
? 客户端仅需做有限的处理工作,即可使用
? 在环境许可的情况下,可提供传统的QoS服务
? 无严格的数据内容的规定
MQTT协议的特性是什么?
? 使用发布/订阅消息通信模式来提供一对多的分布式消息和解耦合的
应用
? 在消息传输过程中提供与消息内容无关的有效载荷
? 基于TCP/IP协议的基础网络连接
? 提供三种QoS的消息传递质量:
a. 最多一次(At most once)
b. 最少一次(At least once)
c. 仅仅一次(Exactly once)
? 很小的传输费用开销 (固定头部的消息仅仅2个字节), 和很少的协议交
换来减少网络传输通信量
? 使用约定的机制来提醒相关各方,客户端产生了一个异常的连接断开
三种消息传递的QoS质量
Qualities of Service
在什么场景下使用MQTT协议?
? 间歇性的连接
? 昂贵的带宽
? 需要与一个或多个手机终端进行通信的公司级应用
? 在不使用代码处理逻辑的情况下,使手机和平板电脑有可靠的数据传
输
? 确保消息的有效分发
? 很低的等待响应时间
谁正在使用MQTT协议?
公司级应用 :
1. WebSphere MQ By IBM
特性: 它能使用消息的形式传输任何数据, 使SOA商业系统架构更加灵活
可靠
2. GaianDB
特性: 分布式联邦数据库使用生物启发自组织原理来减少管理
3. LAMA By IBM Extreme Blue Project
全名: Location Aware Messaging for Accessibility
特性: 在2006年作为IBM’s Extreme Blue 项目的一部分, LAMA 是一个可
提供给人们感兴趣的东西和位置点的系统
4. SiSi By IBM Extreme Blue Project
全名: Say It, Sign It
特性: 在2007年作为IBM’s Extreme Blue项目的一部分,SiSi 帮助聋哑人将
语音转换为英国手语(BSL),通过MQTT和Java来实现
谁正在使用MQTT协议?
智慧家居:
1. Andy SC's Twittering / Automated House
2. Power Monitoring
3. Lighting Control
4. Gardening
5. Energy monitoring with an old-style analog ammeter
6. Android/TV/Burglar detection system
7. Ciseco OpenKontrol Gateway
8. WarmDirt
9. homA
10. St Jude Medical
Ciseco OpenKontrol Gateway
谁正在使用MQTT协议?
移动端应用:
1. Facebook Messenger
? Facebook Messenger 使用MQTT协议,使得手机与手机之间的通信更
加快捷,节省手机电源和带宽
? MQTT可以使用在iOS iPhone,iPad,Android 和 Windows 应用程序中。
MQTT-SN (MQTT For Sensor Networks)
? MQTT-SN v1.2 -- MQTT for 传感器网络 V1.2 协议规格书
它是一个基于非TCP/IP协议的(例如:ZigBee协议),专门为嵌入式
设备提供消息通信模式的协议
MQTT-S 综述
? MQTT-S协议设计和MQTT协议很相似
- 例如:使用MQTT 语义
? 传感器网络中每个节点是客户端,这些客户端通过网关与基于IP网络
的MQTT代理进行通讯
? 网关可以在MQTT-S 与MQTT之间传输数据
? 专为无线传感器网络架构及数据传输而设计的协议
MQTT vs MQTT-S
"简单客户端" QoS = -1
MQTT-S 网关 <--> MQTT 代理
MQTT-S 网关 <--> MQTT 代理
支持MQTT协议的服务器
? IBM Websphere MQ Telemetry
? IBM MessageSight
? IBM Integration Bus
? Mosquitto
? Eclipse Paho
? Eurotech Everywhere Device Cloud
? Xively
? eMQTT
? m2m.io
? webMethods Nirvana Messaging
? RabbitMQ
? Apache ActiveMQ
? Apache Apollo
? Moquette
? HiveMQ
? Mosca
? Litmus Automation Loop
支持MQTT协议的服务器 性能对比图
支持MQTT协议的客户端
Device-Specific :
? Arduino
? mbed
? mbed (simple port of the Arduino pubsubclient)
? Nanode
? Netduino
? M2MQTT (works with .Net Micro Framework)
Actionscript :
? as3MQTT
C :
? Eclipse Paho
? libmosquitto
? libemqtt - an embedded C client
C++ :
? libmosquittopp
Clojure :
? Machine Head
Dart :
? mqtt.dart
Delphi :
? TMQTTClient
Erlang :
? erlmqtt
? mqtt4erl
? my-mqtt4erl - updated fork
of mqtt4erl
支持MQTT协议的客户端
Java :
? Eclipse Paho
? Xenqtt Includes a client library, mock broker for unit/integration testing, and
applications to support enterprise needs like using a cluster of servers as a single
client, an HTTP gateway, etc.
? MeQanTT
? Fusesource mqtt-client
? moquette
? "MA9B" zip of 1/2 dozen mobile clients source code. Includes Android-optimized
Java source that works with Android notifications, based on Paho
? IA92 - deprecated IBM IA92 support pack, use Eclipse Paho GUI client instead. A
useful MQTT Java swing GUI for publishing & subscribing. The Eclipse Paho GUI is
identical but uses newer client code
MQTT Clients Librarys
Javscript / Node.js :
? Eclipse Paho HTML5 JavaScript for MQTT over WebSocket.
? mqtt.js
? node_mqtt_client
? IBM-provided PhoneGap / Apache Cordova MQTT plug-in for Android - JavaScript
API is identical to Eclipse Paho HTML5 JavaScript
? mosquitto websocket client (deprecated, use Eclipse Paho)
? Ascoltatori - a node.js pub/sub library that allows access to Redis, AMQP, MQTT
and ZeroMQ with the same API.
LotusScript :
? MQTT from LotusScript
Lua :
? Eclipse Paho Lua client
? mqtt_lua (deprecated use Paho)
MQTT Clients Librarys
.NET / dotNET :
? MqttDotNet
? nMQTT
? M2MQTT
Perl :
? net-mqtt-perl
? anyevent-mqtt-perl
? WebSphere-MQTT-Client
PHP :
? phpMQTT
? Mosquitto-PHP
Objective-C :
? mqttIO-objC
? libmosquitto - via wrappers
? MQTTKit
? "MA9B" zip of 1/2 dozen mobile
clients source code including
Objective-C
Python :
? Eclipse Paho Python client -
originally the mosquitto Python client
? python-mosquitto (deprecated use
Paho code)
? nyamuk
? MQTT for twisted python
Ruby :
? ruby-mqtt
? em-mqtt
消息格式
Fixed Header
Message Type DUP Flag
QoS
消息格式
Fixed Header
Remaining Length
消息命令列表
? CONNECT
? CONNACK
? PUBLISH
? PUBACK
? PUBREC
? PUBREL
? PUBCOMP
? SUBSCRIBE
? SUBACK
? UNSUBSCRIBE
? UNSUBACK
? PINGREC
? PINGRESP
? DISCONNECT
Introduction MQTT in Chinese
一个简单的样例(服务器与客户端)
服务器端
Mosquitto Broker v3.1
它是一个开源的MQTT 代理
? mosquitto -- the broker
? mosquitto.conf -- broker
configuration
? mosquitto_passwd -- tool for
managing mosquitto password files
? mosquitto_tls -- very rough cheat
sheet for helping with SSL/TLS
? mosquitto_pub -- command line client
for publishing
? mosquitto_sub -- command line client
for subscribing
客户端
Paho MQTT Client 来自于Eclipse 物联网
工作组
? C client
? C++ client
? Java client
? JavaScript client
? Lua client
? Python client
样例:介绍Mosquitto 服务器/消息代理
? 1883端口 -- the standard unencrypted MQTT port and can be used with
any MQTT client.
? 8883和8884端口 -- using certificate based SSL/TLS encryption(TLS v1.2)
and require client support to connect. In both cases should use the
certificate authority file mosquitto.org.crt to verify the server connection.
? 8883端口 -- allows unrestricted connections.
? 8884端口 -- requires clients to provide their own certificate to
authenticate their connection.
? 8885端口 -- it is the same as 8883 but using TLSv1 instead of TLSv1.2.
样例:用Mosquitto作为消息代理
如何安装Mosquitto在Debian Linux 系统中
首先我们需要导入respository package 签名的密钥:
使APT可以使用respository:
更新APT 信息:
wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
sudo apt-key add mosquitto-repo.gpg.key
cd /etc/apt/sources.list.d/
sudo wget http://repo.mosquitto.org/debian/mosquitto-stable.list
apt-get update
样例:用Mosquitto作为消息代理
查询什么样的mosquitto 包可以被使用:
查询结果将会是:
apt-cache search mosquitto
样例:用Mosquitto作为消息代理
然后安装mosquitto
样例:用Mosquitto作为消息代理
安装mosquitto完成后,将会显示如下信息:
当运行 "mosquitto -v "命令,将会显示如下信息,这就表示安装成功了
测试mosquitto的命令 : mosquitto_sub -h test.mosquitto.org -t "#" -v
样例:客户端
发布消息
订阅消息
使用WSNs 和 MQTT-S 协议实现物联网(滨辞罢)
案 例
案 例 : Nike + iPod
如何学习基于ZigBee协议的开发?
BWSN: 书 + 开发工具包
MQTT 书籍:
参考资源:
官方网站:
? MQTT official site
协议规格书:
? MQTT v3.1 Protocol Specification
? MQTT-S v1.2 Protocol Specification
论文:
? MQTT-S -- A Pub/Sub protocol for Wireless Sensor Networks
一个简单的样本项目:
? Controlling the house lighting via MQTT
参考资源:
物联网资源:
? special report the internet of things
? smarter sensors
? the value of privacy
? will the internet of things crush it
? whats coming next the internet of everything
? conferences marchoctober 2014
? help with building the next big thing
? setting the stage for the internet of things
? yenkuang chen improving lives
? ask the expert the internet of things
? tech news the internet of things
? books of interest march 2014
维基百科:
? MQ Telemetry Transport
参考资源:
Youtube网站的视频资源:
? Android Home Automation Demo | Voice + NFC
? Fully Automated Digital Home Systems
? Enterprise exploitation of the internet of things (IoT) with BlackBerry 10
? MQTT + BeagleBone Black + Augmented Reality = FUN!
? MQTT Starfighter, JazzHub, BlueMix and live Scaling Out
? Starfighter - IBM MessageSight and MQTT for multiplayer gaming
? M2Mqtt : MQTT client testing
? IBM Cluster Code Off - CICS monitoring application using IBM MessageSight, MQTT
and Arduino
? IBM Cluster Code Off - The Big Blue Line mobile geo-location race application
? London Green Hackathon: Kindle Energy Dashboard
? MQTT FOR multi-users gaming
Twitter 资源:
? https://twitter.com/mqttorg
参考资源:
开源项目:
? http://mosquitto.org/
? http://mosquitto.org/download/
? http://www.eclipse.org/paho/
? http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt.c.git/
? http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt.cpp.git/
? http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt.java.git/
? http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt.javascript.git/
? https://github.com/fusesource/mqtt-client
? https://github.com/TomoakiYAMAGUCHI/MQTT-S
? http://build.eclipse.org/technology/paho/C/
? https://repo.eclipse.org/content/repositories/paho-snapshots/
? https://repo.eclipse.org/content/repositories/paho-releases/
? https://github.com/dpslwk/OpenKontrol-Gateway
? http://shop.ciseco.co.uk/openkontrol-gateway-starter/
Thanks! Questions?
Contact:
Eric Xiao
Email: ericssonxiao@gmail.com
Twitter: @ericssonxiao
LinkedIn:
http://www.linkedin.com/in/ericssonxiao
Ad

Recommended

CPR ( cardio pulmonary resuctation )
CPR ( cardio pulmonary resuctation )
ROMAN BAJRANG
?
ethical decision making.pptx
ethical decision making.pptx
ManoharKumar81
?
Cauti.dr rudrika
Cauti.dr rudrika
rudrika
?
Node.js中间件 connect模块深入浅出
Node.js中间件 connect模块深入浅出
Eric Xiao
?
Hybrid app简要介绍
Hybrid app简要介绍
Eric Xiao
?
Introduction MQTT in English
Introduction MQTT in English
Eric Xiao
?
2024 Trend Updates: What Really Works In SEO & Content Marketing
2024 Trend Updates: What Really Works In SEO & Content Marketing
Search Engine Journal
?
Storytelling For The Web: Integrate Storytelling in your Design Process
Storytelling For The Web: Integrate Storytelling in your Design Process
Chiara Aliotta
?
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
OECD Directorate for Financial and Enterprise Affairs
?
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
SocialHRCamp
?
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
?
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
?
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
?
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
?
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
?
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
?
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
?
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
?
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
?
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
?
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
?
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
?
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
?
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
?
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
?
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
?
Introduction to Data Science
Introduction to Data Science
Christy Abraham Joy
?
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
Vit Horky
?

More Related Content

Featured (20)

Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
OECD Directorate for Financial and Enterprise Affairs
?
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
SocialHRCamp
?
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
?
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
?
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
?
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
?
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
?
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
?
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
?
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
?
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
?
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
?
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
?
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
?
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
?
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
?
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
?
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
?
Introduction to Data Science
Introduction to Data Science
Christy Abraham Joy
?
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
Vit Horky
?
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
SocialHRCamp
?
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
?
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
?
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
?
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
?
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
?
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
?
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
?
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
?
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
?
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
?
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
?
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
?
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
?
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
Vit Horky
?

Introduction MQTT in Chinese