美文网首页
ubuntu&mosquitto

ubuntu&mosquitto

作者: 沿哲 | 来源:发表于2021-03-25 17:36 被阅读0次

说到mosquitto不得不先提一下MQTT(Message Queuing Telemetry Transport,消息队列遥测传输协议,参考我之前介绍mqtt的博文
想通过mqtt协议通信,主机需有mqtt的消息代理(即broker),和客户端(比如mosquitto-client)参考我之前介绍mqtt的博文中有提到在线的broker:broker.mqttdashboard.com,今天介绍一下安装在本地的broker:mosquitto

准备

  • 系统:ubuntu(虚拟机)
  • 进入root模式(如果没进入root需要安装的时候前面加sudo)

安装步骤

apt-get install mosquitto
apt-get install mosquitto-clients

!!!命令行下输入命令开启broker,默认监听端口是1883

mosquitto

:网上有很多教程说 service mosquitto start开启,service mosquitto status检查运行状况,不过我这样开启之后没有什么效果,在发布/订阅中还报错Error:connection refused,看来是因为moquitto没有开启)

测试

开启broker后,发布主题和消息

mosquitto_pub -h 10.***** -t "mqtt" -m "Hello"

注:很多教程上写 mosquitto_pub -h localhost -t "mqtt" -m "Hello",我的虚拟机配置的是桥接模式,-h localhost会报错,必须要写具体的ip地址
订阅消息,能看到Hello的输出

mosquitto_sub -h 10.**** -t "mqtt" 

相关文章

  • ubuntu&mosquitto

    说到mosquitto不得不先提一下MQTT(Message Queuing Telemetry Transpor...

网友评论

      本文标题:ubuntu&mosquitto

      本文链接:https://www.haomeiwen.com/subject/huulhltx.html