?
目錄
1.下載 mosquitto
2.安裝?mosquitto?
3.配置?mosquitto?
4.測試 mosquitto
1.下載 mosquitto
????????登錄網(wǎng)址:
????????http://mosquitto.org/files/binary/
????????這里是window環(huán)境,選擇win32/,下載mosquitto安裝包。
2.安裝?mosquitto?
? ? ? ? ?雙擊安裝 -> 點擊Next -> 點擊Next -> 選擇安裝路徑 -> 點擊install -> 點擊Finish。
?
?
3.配置?mosquitto?
? ? ? ?(1)關(guān)閉匿名訪問?
? ? ? ?在安裝路徑下找到配置文件 mosquitto.conf 打開,任意位置加入下面文本。
#設(shè)置不允許匿名登錄
allow_anonymous false
? ? ? ? (2)插入新用戶名及密碼
? ? ? ?a)新增用戶:
????????輸入密碼時界面是不會顯示的,直接輸入后回車就可以。保證pwfile.example的路徑和上面的配置一致。下面打開CMD并進入mosquitto目錄輸入:
mosquitto_passwd -c pwfile.example 用戶名1
?
? ? ? ? ?b)追加用戶:
????????使用-c 參數(shù)會導(dǎo)致清空密碼文件,重新插入用戶,如需追加用戶,則不使用 -c,如下:
mosquitto_passwd pwfile.example 用戶名2
打開pwfile.example文件可以看到增加的用戶:
?
4.測試 mosquitto
? ? ? ?(1)先打開Mosquitto Broker 服務(wù):
????????
? ? ? ? (2)這里方便操作,啟動三個cmd窗口服務(wù),并進入mosquitto目錄下。
? ? ? ? a)第一個cmd服務(wù)窗口啟動mosquitto。
mosquitto.exe -c mosquitto.conf
? ? ? ? ?b)第二個cmd服務(wù)窗口訂閱消息(示例:賬戶user,密碼123456)。
mosquitto_sub -u user1 -P 123456 -t 'user/topic' -v
? ? ? ? c)第三個cmd服務(wù)窗口發(fā)布消息(示例:mqtt測試)。文章來源:http://www.zghlxwxcb.cn/news/detail-678009.html
mosquitto_pub -u user1 -P 123456 -t 'user/topic' -m 'mqtt測試'
? ? ? ? 第二個訂閱窗口會收到來自第三個訂閱窗口發(fā)布的消息。文章來源地址http://www.zghlxwxcb.cn/news/detail-678009.html
到了這里,關(guān)于MQTT:windows環(huán)境下配置MQTT服務(wù)器(mosquitto)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!