安装

命令

sudo apt-get install mosquitto mosquitto-clients

测试

测试安装是否成功

首先在一个终端输入:

mosquitto_sub -t m -d

输出打印

pi@raspberrypi:~ $ mosquitto_sub -t m -d
Client mosqsub/1782-raspberryp sending CONNECT
Client mosqsub/1782-raspberryp received CONNACK
Client mosqsub/1782-raspberryp sending SUBSCRIBE (Mid: 1, Topic: m, QoS: 0)
Client mosqsub/1782-raspberryp received SUBACK
Subscribed (mid: 1): 0

在另一个终端输入:

mosquitto_pub -t m -m "This is a message from pi publisher."

这时在订阅者那儿打印

Client mosqsub/1782-raspberryp received PUBLISH (d0, q0, r0, m0, 'm', ... (36 bytes))
This is a message from pi publisher.

中间会间隙性打印,应该是心跳检测

Client mosqsub/1782-raspberryp sending PINGREQ
Client mosqsub/1782-raspberryp received PINGRESP

服务器broker

问题

hivemq.com say Connect failed: AMQJSC0001E Connect timed out
  • https://xdk.bosch-connectivity.com/community/-/message_boards/message/194509

参考文档

  • 在树莓派上安装mosquitto实现MQTT通信
  • 树莓派实现MQTT通信
  • https://www.switchdoc.com/2018/02/tutorial-installing-and-testing-mosquitto-mqtt-on-raspberry-pi/
  • https://learn.adafruit.com/diy-esp8266-home-security-with-lua-and-mqtt/configuring-mqtt-on-the-raspberry-pi
  • http://www.steves-internet-guide.com/mosquitto_pub-sub-clients/
  • http://www.hivemq.com/demos/websocket-client/
  • https://github.com/mqtt/mqtt.github.io/wiki/public_brokers
  • https://www.hivemq.com/blog/how-to-get-started-with-mqtt/
  • MQTT入门

评论