使用Mosquito MQTT的二进制数据

Mer*_*ury 2 mqtt mosquitto

我正在使用蚊子MQTT服务器来播放mesegges.

如何发送二进制数据(不是文本),例如:

mosquitto_pub -t test -m 0x452343
Run Code Online (Sandbox Code Playgroud)

将被收到:0100 0101 0010 011 0100 0011

ral*_*ght 6

您可以将二进制数据放入文件中,然后将其作为消息发送:

mosquitto_pub -t test -f file
Run Code Online (Sandbox Code Playgroud)

或者,您可以使用libmosquitto或其他MQTT客户端库编写自己的客户端。


njh*_*njh 6

如果您真的想要发送二进制字符序列,那么您可以使用echo将字符串转换为二进制:

echo -ne "\x45\x23\x43" | mosquitto_pub -h test.mosquitto.org -t 'test/binary' -s
Run Code Online (Sandbox Code Playgroud)

这也适用于二进制命令的输出,例如在Raspberry Pi上捕获图像:

raspistill -o - | mosquitto_pub -h test.mosquitto.org -t 'webcam/' -s
Run Code Online (Sandbox Code Playgroud)