snprintf(payload, sizeof(payload), "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s", timestampChar, weightMedianChar,temperatureChar[0],humidityChar[0],temperatureChar[1],humidityChar[1],temperatureArrayChar[0],temperatureArrayChar[1],temperatureArrayChar[2],temperatureArrayChar[3],temperatureArrayChar[4],temperatureArrayChar[5],temperatureArrayChar[6],temperatureArrayChar[7],temperatureArrayChar[8],temperatureArrayChar[9],temperatureArrayChar[10],temperatureArrayChar[11],voltageChar);
I have this ugly and long line of code to make a char out of different variables. How can I make it a bit more pretty and parameter based?
The "%s,%s,%s,%s, ..." part can I replace with a char variable that makes automatically as many %s or other placeholder as I need.
Complicated is the variable part. how can I say "Take in the sprintf as variables timestamp, weight then
- 2x temp and hum
- 12x tempArray
??