Hello everyone,
I am trying to send some data over to the MQTT broker using the Thingy91 and the example of 'Cellular IoT fundamentals - Lesson 4'. The example itself works well when not adjusted and publishes the string message to the MQTT broker. The adjustment that I am trying to implement has to send data of type 'double' over to the MQTT broker. To achieve this, I first convert the 'double' to 'char'. A simplified version of the altered code section looks like this:
double accel_double = 10; // A random-valued double
char acc[9]; // 'char' variable
sprintf(acc, "%f", accel_double); // double to char conversion
int err = data_publish(&client, MQTT_QOS_1_AT_LEAST_ONCE,
acc, sizeof(acc)-1); // The data publish function directly from the example, only difference is that 'acc' is now the input
The rest of the code is unaltered from the example and it builds without error. However, the output in the MQTT broker is scrambled:
topic = �[1]����
I expect that there is a problem with the data formatting, but I cannot find out what exactly. Can anyone help?