网站建设qq群,公司网站界面如何设计,网页设计网站概述怎么写,自考网站建设与管理[MQTT | Raspberry Pi]Publish and Subscribe with RSSI Data of Esp32 on Intranet 延續[MQTT]Mosquitto的簡介、安裝與連接測試文章#xff0c;接著將繼續測試在內網的兩台機器是否也可以完成發佈和訂閱作業。 同一網段的兩台電腦測試:
假設兩台電腦的配置如下:
A電腦為發… [MQTT | Raspberry Pi]Publish and Subscribe with RSSI Data of Esp32 on Intranet 延續[MQTT]Mosquitto的簡介、安裝與連接測試文章接著將繼續測試在內網的兩台機器是否也可以完成發佈和訂閱作業。 同一網段的兩台電腦測試:
假設兩台電腦的配置如下:
A電腦為發佈端兼broker角色IP:192.168.0.101 B電腦為訂閱端IP:192.168.0.102
a.請在A電腦的mosquitto.conf內新增下列內容
#For remote access
listener 1883
allow_anonymous true
完成修改後重新啟動mosquitto broker。
b.A電腦作為發佈端來發佈主題並同時為中介端接收來自發佈端和訂閱端的消息。
mosquitto_pub -h 192.168.0.101 -t sensor_1 -m “25.3C”
c.B電腦訂閱來自A電腦發佈的主題
mosquitto_sub -h 192.168.0.101 -t sensor_1
另外mosquitto官網也有提供一個broker供使用者測試訂閱和發佈功能是否正常。 使用者/密碼權限設定
在mosquitto中可利用建置一個user/password文件來做發佈者和訂閱者的管理步驟如下:
a.在A電腦建置一個檔名為password_file的文件並將username和password資訊放入該檔案中。
sudo touch password_file
sudo mosquitto_passwd -b password_file username password
b.在A電腦的mosquitto.conf文件中請一併新增下列配置內容
#For authentication premission
password_file /etc/mosquitto/password_file
完成設置的password_file內容如下圖一並重新啟動 mosquitto broker。 c.A電腦為發佈端的指令如下
mosquitto_pub -h 192.168.0.101 -t sensor_1 -m “25.3C” -u username -P password
d.B電腦為訂閱端的指令如下
mosquitto_sub -h 192.168.0.101 -t sensor_1 -u username -P password 關於權限設定mosquitto提供Password, Acess Control List(ACL)和Pre-Shared Key(PSK)三種方式對應的範例文件分別為pwfile.example, aclfile.example和pskfile.example可在/usr/share/doc/mosquitto/examples中開啟檢閱。