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
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
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.
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.