20201/5/17更新: Windows上也支持mosquitto了,在mosquitto官网上有windows版本的下载, 可以使用. 以前的似乎不能用:windows(win10) 就别费劲了。。。两个版本win32和cygwin装完都不能运行,坑爹的是它还需要一大堆的dll,这些dll它不提供还要你去找。。。
ubuntu上装起来很容易,直接

sudo apt-get install mosquitto

就可以了。装完了直接作为服务运行。开始还奇怪,为什么运行mosquitto老是提示地址被占用(Address already in use.)
装完服务装客户端,命令是

sudo apt-get install mosquitto-clients

mosquitto_sub命令

这样你才可以用mosquitto-sub命令
输入

mosquitto_sub -t 'test/topic' -v

订阅消息,等待消息输出。
使用-h命令可以指定服务器地址, 否则是以本机为服务器.
mosquitto的payload可以是二进制数据, 如果要以16进制显示, 使用-F命令跟上格式%x, 注意-F命令在旧版的mosquitto上不支持:

mosquitto_sub -h 192.168.0.108 -t rgb/show -F %x

mosquitto_pub

另开一个终端,输入:

mosquitto_pub -t 'test/topic' -m 'hello world'

在前一个终端窗口就能看到消息了。

远程连接MQTT服务器,加入参数 -h xxx.xxx.xxx.xxx 就可以了。

mosquitto pub发送二进制的方式

命令行直接发送(限于Linux BASH)

echo -ne "\x45\x23\x43" | mosquitto_pub -h test.mosquitto.org -t 'test/binary' -s

通过文件发送

mosquitto_pub -t test -f filename

标签: none 阅读量: 1257

添加新评论