如何发送二进制数据?
How to send binary data?
我正在使用 Mosquitto MQTT 服务器广播消息。
如何发送二进制数据(不是文本)?
示例:
mosquitto_pub -t test -m 0x452343
应收到:
0100 0101 0010 011 0100 0011
您可以将二进制数据放在一个文件中,然后将该文件作为消息发送:
mosquitto_pub -t test -f file
或者您可以使用 libmosquitto 或其他 MQTT 客户端库编写自己的客户端。
如果您真的想发送字符的二进制序列,则可以使用 echo 将字符串转换为二进制,方法如下:
echo -ne "\x45\x23\x43" | mosquitto_pub -h test.mosquitto.org -t 'test/binary' -s
这也适用于二进制命令的输出,例如在 Raspberry Pi:
上捕获图像
raspistill -o - | mosquitto_pub -h test.mosquitto.org -t 'webcam/' -s
我正在使用 Mosquitto MQTT 服务器广播消息。
如何发送二进制数据(不是文本)?
示例:
mosquitto_pub -t test -m 0x452343
应收到:
0100 0101 0010 011 0100 0011
您可以将二进制数据放在一个文件中,然后将该文件作为消息发送:
mosquitto_pub -t test -f file
或者您可以使用 libmosquitto 或其他 MQTT 客户端库编写自己的客户端。
如果您真的想发送字符的二进制序列,则可以使用 echo 将字符串转换为二进制,方法如下:
echo -ne "\x45\x23\x43" | mosquitto_pub -h test.mosquitto.org -t 'test/binary' -s
这也适用于二进制命令的输出,例如在 Raspberry Pi:
上捕获图像raspistill -o - | mosquitto_pub -h test.mosquitto.org -t 'webcam/' -s