I have the following code as part of a large programme that reads in 2 float values from a DHT11 sensors and another int value from an LDR connected to A0.
The code that reads in the values is as follows:
float h = dht.readHumidity(); float t = dht.readTemperature(); int l = analogRead(A0);
My aim is to send this data to a webserver as part of an HTTP GET request (i.e. a string).
The problem I have is that when I use the following it adds 4k onto my sketch size (too big):
sprintf(buffer, "GET /submit.php?temp=%.1f&hum=%.1f&light=%d HTTP/1.0", t, h, l);
This method works and the data gets to the server however it is too big for the sketch.
If I convert h,t and l to a string beforehand the sketch size drops by 4k:
String temperature = String((int) t); String humidity = String((int) h); String light = String((int) l); sprintf(buffer, "GET /submit.php?temp=%s&hum=%s&light=%s HTTP/1.0", temperature, humidity, light);
The problem, however is that the second method doesn't work, the data doesn't get to the server.
Does anyone know: a) why the second method isn't working? b) why the first method is considerably larger in sketch size?