I have this function mqtt.publish(topic, message) where the function parameters are Arduino String objects. It uses the MQTT protocol to send data out. Usually, the parameters are in text String. However, in my case, the data is in binary hex.
Here is the relevant code;
MqttClient mqtt("192.168.1.71", 1883, onMessageReceived); char buffer; //buffer filled with binary data terminated with null character at this point mqtt_msg = String(buffer); String topic = "XXX"; mqtt.publish(topic, mqtt_msg );
I will terminate the binary data in buffer with a null character 0x00. The problem comes when 0x00 happened to be part of the binary data. How can this problem be solved?