Simplification code avec boucle for + dtostrf
Bonjour tout le monde,
J'essaie de simplifier ma fonction miseEnForme au travers d'une boucle mais je n'y arrive pas, voici mon code :
Cette fonction permet de mettre en forme un URL en ajoutant la valeur de mes capteurs dans l'url.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| void setup() {
Serial.begin(9600);
}
float tempDHT = 12.2;
float humDHT = 88.55;
float poids = 50.55;
char tempDHTchar[4];
char humDHTchar[5];
char poidschar[5];
char valeurs[8]=;
//obligé de faire dtostrf à chaque ligne
void miseEnForme()
{
const String args[4] = { "http://xxxxx.xxxxx.com?Temp=", "&Hum=", "&poids=" };
String result = "";
result += args[0];
dtostrf(tempDHT, 4, 2, tempDHTchar);
result += tempDHTchar;
result += args[1];
dtostrf(humDHT, 4, 2, humDHTchar);
result += humDHTchar;
result += args[2];
dtostrf(poids, 4, 2, poidschar);
result += poidschar;
Serial.println(result);
Serial.println();
} |
J'ai essayé avec une boucle for mais ca ne fonctionne pas car il faut exécuter la commande dtostrf à chaque iteration :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| //probléme car il faut faire un dtosrf à chaque fois
void miseEnForme2()
{
const String args2[8] = { "http://xxxx.xxxx.com?Temp=", tempDHTchar, "&Hum=", humDHTchar, "&poids=", poidschar };
String result2 = "";
for (int i=0; i <= 6; i++){
Serial.print(args2[i]);
}
Serial.println(result2);
Serial.println();
} |
Auriez vous une idée par tout hasard ? car pour le moment je n'ai que 3 capteurs mais bientot j'en aurais bien plus .
Merci pour votre aide ;)