Making Assorted Variables into a String

I am writing a sketch to send data to a python program via ethernet. The easy way, from the Python point of view, is to combine everything into a string and send that string in one client.print command.

The problem is that I don't know haw to combine the variables and string. What is the right way of doing what I tried to do in the following?

            int sensread = analogRead(3);
            float degreex = Temperature(sensread);
            char allin[25] = sensereadi + " node 1 " + degreex;



Python receives the data one byte at a time. So the easiest thing to do on the arduino side is to make separate calls to client.print. The python program will never be able to tell the difference. It comes in the same way to it either way.

Thanks Delta,

I thought that that was a good idea too, in fact it was the first thing that I tried, but only the first, and sometimes the second client.print would show up in my Python. I tried a whole bunch of things in Python before I went back to the Arduino to try sending data in a different format.

What I found was that as long as the data was in one client.print, even a thousand characters would transfer successfully.


I guess something like this will work,

client.print(allin, "Temperature = %i, Analogue is %i", degreedec, sensread);


Why don't you try that and get back to us. I don't think the comma operator works likethat.

It is working. The only additional problem was that I could not get a float to work, %f, so I scaled the one value by a factor of ten and sent it as an integer too.

            int sensread = analogRead(3);
            float degreex = Temperature(sensread);
            int degreedec = 10*degreex;
            char allin[45];
            sprintf(allin, "Temperature = %i, Analogue is %i", degreedec, sensread);


The below sketch builds this String:

Result: 3.1452549 Volts

If you don't need float variables you could just use sprintf() NS char array

void setup() {
 char tmp[25];
 float val=3.14525478;

String tmp2="Result: ";
String tmp3=" Volts";
String output=tmp2+tmp+tmp3;

void loop() {