跳至主要內容

MQTT初探

最近因接收即時訊息 意外認識MQTT這款IOT發布/訂閱架構的協定

工具

CLI可以安裝mosquitto-clients 內有mosquitto_pub mosquitto_sub指令供使用

Python可以透過pip install paho-mqtt

Python subscribe example in Eclipse paho Getting Started

Topic符號意義

+ 一階層任意數(foo/+ 不包含foo/+/bar)
# 多階層任意數(foo/#包含foo/以下任何節點)
$SYS系統訊息(如$SYS/# 有loading, users info等)
視覺化$SYS Tree

CLI參數

default port 1883 (non-tls) 8883 (over tls)

參數 -h [host] -p [port] -t [topic] -u [username] -P [password] -i [client_id] -m [msg]
-d 顯示debug連接訊息 -v 訊息輸出topic名稱

over tls的部份需指定–cafile or –capath /etc/ssl/certs
或是更嚴謹簽發client密鑰 –cert [client.crt] –key [client.key]

Mosquitto Client Debug訊息

持續顯示sending CONNECT是over tls未指定憑證

Error: A TLS error occurred. 指定錯誤的憑證

Connection Refused: identifier rejected. 帳號或密碼錯誤

Connack Return Codes

0 Connection accepted
1 The Server does not support the level of the MQTT protocol requested by the Client
2 The Client identifier is correct UTF-8 but not allowed by the Server
3 The Network Connection has been made but the MQTT service is unavailable
4 The data in the user name or password is malformed
5 The Client is not authorized to connect

好用網站

Web Client #1

Web Client #2

mosquiito test server

分類:Linux

搶先發佈留言

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料

由 Compete Themes 設計的 Author 佈景主題