2017年3月23日 星期四

安裝 Mosquitto MQTT

取得key後進行安裝
sudo 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-jessie.list
sudo apt-get update
sudo apt-get install mosquitto
安裝三個 Mosquitto proper 會用到的程式庫
mosquitto – the MQTT broker (or in other words, a server)
mosquitto-clients – command line clients, very useful in debugging
python-mosquitto – the Python language bindings
sudo apt-get install mosquitto mosquitto-clients python-mosquitto 
安裝完後mosquitto會立即執行,但還需要進行部分設定,所以先停止
sudo /etc/init.d/mosquitto stop 
開啟設定檔案
sudo nano /etc/mosquitto/mosquitto.conf 
修改找到 log_dest 列,將後面改為 topic,如下
log_dest topic
並再增加下面六個參數後存檔
log_type error
log_type warning
log_type notice
log_type information
connection_messages true
log_timestamp true 
重新啟動mosquitto
sudo /etc/init.d/mosquitto start 
進行測試,開啟終端機,輸入下列指令
mosquitto_sub -d -t hello/world 
再開啟另一個終端機,輸入下列指令
mosquitto_pub -d -t hello/world -m "Hello from Terminal 2!" 

會在第一個開啟的終端機看到如上畫面

會在第二個開啟的終端機看到如上畫面




沒有留言:

Free ERP on the Raspberry Pi (odoo)

  #更新系統軟體 sudo apt update && sudo apt upgrade -y #安裝資料庫 sudo apt install postgresql -y #安裝py程序 sudo apt install python3-pip -y #安裝od...