I'm using Arduino as a UDP client to send information about values read from sensors.
I'd like to send packets like:
"string1=value1"
where value1 is an integer read from Arduino analog pins.
The problem is that udp.write() only takes as parameter char arrays, so i can't sum a string to an integer and then pass the new string to udp.write().
I have to concatenate a char array to an integer value and then pass the array to the udp.write() function.
At the moment, i'm using dtostrf(FrontSonar_Reading,1,2,temp);
in order to save the integer value in the "temp" array char, but i do not know how to concatenate this result to the array char.
The only risk you have with sprintf is that you will outrun your target buffer space.
As you are using a char buffer containing the variable name and you are adding a int you can 100% guarantee your buffer is big enough.
Unless you go for runtime memory allocation (like String class does) you will always have this problem.
Best regards
Jantje
Hello Friends, I am exploring the below sketch to concatenate arrays.. If I want to add "%" symbol to the end of the integer value to myConcatenation[80] array, how do I do it? basically, when I print myConcatenation, I would like to see the output as "A variable name = 5 %.
Lavan:
Is there any other better way to achieve it?
Reading the sprintf documentation? ]
You probably need to add a \ before the % but I'm sure google can point you to documentation of the printf family that tells you how to do it.