mqtt

mqtt.fx 国内下载地址

http://mqttfx.bceapp.com/

各种mqtt库

https://github.com/mqtt/mqtt.github.io/wiki/libraries?spm=a2c4g.11186623.2.5.5YAnRS

mosquitto 安装

https://mosquitto.org/
make & make install

  • 问题 编译过程找不到ares.h 打开config.mk文件,把WITH_SRV:=yes 改成WITH_SRV:=no 就可以编译了
  • 问题 Invalid user 'mosquitto'
    adduser mosquitto
  • 问题 libmosquitto.so.1: cannot open shared object file
    ldconfig
  • 问题 uuid/uuid.h
    yum install libuuid-devel
mosquitto -c /etc/mosquitto/test.conf -d
mosquitto_passwd -b /etc/mosquitto/test.pwfile dev1 123
mosquitto_passwd -b /etc/mosquitto/test.pwfile admin 123
mosquitto_passwd -b /etc/mosquitto/test.pwfile mqtt_server 123
mosquitto_sub -u admin -P 123 -d -t 'device/#'
mosquitto_pub -u dev1 -P 123 -d -t 'device/dev1/report_info' -m 'xxx'
-r 保留retained

mosquitto

  • retained保留消息
    broker保存最后一次topic的保留消息,每当有客户端订阅这个topic,都会收到保留消息
    删除保留消息:
    方式1:发送空消息体的保留消息;
    方式2:发送最新的保留消息覆盖之前的(推荐);

  • 增加用户 mosquitto_passwd -b /etc/mosquitto/test.pwfile 11010611100000000008 ryrnog

  • 删除用户 mosquitto_passwd -D /etc/mosquitto/test.pwfile 11010611100000000008

  • 重新load
    kill -1 $pid 发送SIGHUP信号,让mosquitto重新load conf

  • mosquittoconf
    log_dest file /var/log/mosquitto/mosquitto.log
    出现Unable to open log file /var/log/mosquitto/mosquitto.log for writing问题
    chmod 777 /var/log/mosquitto/

MQTT Control Packet

  1. Fixed header 固定头 MQTT Control Packet type 控制类型,包括CONNECT,CONNACK,PUBLISH,SUBSCRIBE等等
  2. Variable header 变量头
  3. Payload

QOS

  • 最多一次(0) 客户端发送一次就不再发了
  • 最少一次(1) 客户端会一直重复发送,知道收到服务端的PUBACK
  • 只一次(2) 确保消息服务端只会收到一次

php mqtt-client

https://github.com/mgdm/Mosquitto-PHP

  • 安装
pecl install Mosquitto-alpha
/usr/local/php/etc/php.ini
extension=mosquitto.so
  • loopForever($timeout=1000)
    在回调里调用disconnect就会退出
    或者exitLoop退出
    exitLoop 表示不断开连接退出loopForever
    $timeout 表示等待网络,并不是说loop长时间

转载于:https://my.oschina.net/u/3798036/blog/3013130

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值