Linux command
mosquitto_pub 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Publish message to topic
mosquitto_pub -t [topic] -m "[message]"
Publish to remote broker
mosquitto_pub -h [broker.example.com] -t [topic] -m "[message]"
Publish with authentication
mosquitto_pub -h [host] -u [user] -P [password] -t [topic] -m "[message]"
Publish file contents
mosquitto_pub -t [topic] -f [file.txt]
Publish with QoS
mosquitto_pub -t [topic] -m "[message]" -q [1]
Publish retained message
mosquitto_pub -t [topic] -m "[message]" -r
说明
mosquitto_pub publishes messages to an MQTT broker. It's part of the Mosquitto package. The tool sends single messages. Supports authentication, TLS, and various QoS levels.
参数
- -h _HOST_
- MQTT broker hostname.
- -t _TOPIC_
- Topic to publish to.
- -m _MESSAGE_
- Message payload.
- -u _USER_
- Username.
- -P _PASSWORD_
- Password.
- -q _QOS_
- Quality of service (0, 1, 2).
- -r
- Retain message.
- --help
- Display help information.
FAQ
What is the mosquitto_pub command used for?
mosquitto_pub publishes messages to an MQTT broker. It's part of the Mosquitto package. The tool sends single messages. Supports authentication, TLS, and various QoS levels.
How do I run a basic mosquitto_pub example?
Run `mosquitto_pub -t [topic] -m "[message]"` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -h _HOST_ do in mosquitto_pub?
MQTT broker hostname.