Mosquitto-MQTT

安装Mosquitto

#To use the new repository you should first import the repository package signing key:  
wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key  
sudo apt-key add mosquitto-repo.gpg.key  
   
#Then make the repository available to apt:  
cd /etc/apt/sources.list.d/  
   
#Then one of the following, depending on which version of debian you are using:  
sudo wget http://repo.mosquitto.org/debian/mosquitto-wheezy.list  
    
#Then update apt information:  
sudo apt-get update  
   
#And discover what mosquitto packages are available:  
sudo apt-cache search mosquitto  
   
##Or just install:
#安装服务端
sudo apt-get install mosquitto
#安装客户端 (订阅sub  与 发布pub)
sudo apt-get install mosqutitto-client
#安装调试器
sudo apt-get install mosquitto-dbg 

启动与关闭Mosquitto

开启 mosquitto:
sudo service mosquitto start
停止 mosquitto:
sudo service mosquitto stop
查看 mosquitto 状态:
sudo service mosquitto status
查看监听的端口:
sudo lsof -i:1883

测试Mosquitto

#启动代理服务
mosquitto -v
    【-v】打印更多的调试信息
 
#订阅主题
mosquitto_sub -v -t sensor -h 192.168.228.130 -p 1883-t】指定主题,此处为sensor
    【-v】打印更多的调试信息
    【-h】指定代理服务的IP地址
    【-p】指定代理服务的端口号
 
#发布内容
mosquitto_pub -t sensor -m test_one -h 192.168.228.130 -p 1883-t】指定主题,此处为sensor
    【-m】指定消息内容,此处为test_one
    【-h】指定代理服务的IP地址
    【-p】指定代理服务的端口号

MQTT协议工作过程

---------------------------------------------------------------------------------------------------------------------------------------
我在手机上先订阅内涵小段子(我为订阅者),内涵小段子每发我就会收到(内涵小段子为发布者,当然它也可以选择不发给我),我不订阅就收不到。
---------------------------------------------------------------------------------------------------------------------------------------
posted @ 2016-09-28 16:42  夜雨沧神  阅读(4131)  评论(0编辑  收藏  举报