Need help with variable in a function

I am trying to add the "fan" variable to this GET statement. But I have no idea how to get the code to compile. I know I need to declare the fan variable but I am not sure what it should be or what is the correct way to do it. The value will be "ON" "Off" and "--".

Not the full code but should be most of it.
The area in question is:

client.println("GET /tower/send_email.php?tempe="+temperature+"&humidity="+humidity+"&key=****&fan="+f+" HTTP/1.1"); //Send data
float temperature;
float humidity;

#define DHTPIN 5  

#define DHTTYPE DHT22 
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  dht.begin();
  delay(2000);
  Serial.begin(115200);
  Serial.println("Connecting");
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(100);
  }
  Serial.println("Connected");
  delay(1000);
  readSensor();
  String temperatureString = String(temperature,1);
  String humidityString = String(humidity,1);
  String fanString = String(f,1);
  //String fanString = String(fan,1);
  sendDataToServer(temperatureString,humidityString,f);
}

void loop() {

}

void sendDataToServer(String temperature, String humidity, ??? )
{
 if (client.connect(servername, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");
    client.println("GET /tower/send_email.php?tempe="+temperature+"&humidity="+humidity+"&key=****&fan="+f+" HTTP/1.1"); //Send data
    Serial.println("GET /tower/send_email.php?tempe="+temperature+"&humidity="+humidity+"&key=****&fan="+f+" HTTP/1.1"); //Send data
    client.println("Host: alsconnect.com");
    client.println("Connection: close");  //close 1.1 persistent connection  
    client.println(); //end of get request
  }
float temperature;
float humidity;

you have declared these 2 variables though nowhere do you initialize them so their value (although probably 0) is undetermined when you create these 3 Strings

String temperatureString = String(temperature,1);
  String humidityString = String(humidity,1);
  String fanString = String(f,1);

you will need to declare f before it compiles.
When you are trying to send it it makes sense to just keep passing "String' to the function.sendDataToServer(temperatureString,humidityString,fanString);
so you should declare that in the functionvoid sendDataToServer(String temperature, String humidity, String fan ) and then add that to the 'get command String' client.println("GET /tower/send_email.php?tempe="+temperature+"&humidity="+humidity+"&key=****&fan="+fan+" HTTP/1.1"); //Send data Does that make sense ?

Not the full code but should be most of it.

That is probably why the variables weren't visibly initialized.

I don't understand

String temperatureString = String(temperature,1);
  String humidityString = String(humidity,1);
  String fanString = String(f,1);

Must they be declared before the function or can it be done when the function is created?

void sendDataToServer(String temperature, String humidity, String fan )

Must they be declared before the function or can it be done when the function is created?

Both ! First you convert a 'float' variable (humidity) to a 'String' (humidityString)String humidityString = String(humidity,1); and when you pass it as an argument to the function heresendDataToServer(temperatureString,humidityString,fanString); it has to be declared as an argument here void sendDataToServer(String temperature, String humidity, String fan ) Anyway i suggest you read up a bit on functions in C++. Googling may provide you with some answers but i think a chapter of a book with a full explanation would be better.

Deva_Rishi:

float temperature;

float humidity;


you have declared these 2 variables though nowhere do you initialize them so their value (although probably 0)

Not "probably", but "is".

They're globals; they're initialised before setup() runs, even before the hidden main() runs.

Not "probably", but "is".

Undefined is undefined and undefined is not the same as zero.

No, it definitely is zero.
crt0 guarantees it that globals and statics, not assigned another value, will be initialised to zero.