# Merging strings and constants causing scope errors

I'm getting a few errors when merging strings with constants.

Here's the pertinent code...

#define STATION_ID ABC123
#define STATION_PASS XYZ987

void loop(){
}


And then the errors...

weather.cpp:15:20: error: 'ABC123' was not declared in this scope
weather.cpp:64:66: note: in expansion of macro 'STATION_ID'

weather.cpp:16:22: error: 'XYZ987' was not declared in this scope
weather.cpp:64:90: note: in expansion of macro 'STATION_PASS'


Not sure where I'm going wrong on this.

Maybe? Not sure, but give this a try.

#define STATION_ID "ABC123"
#define STATION_PASS "XYZ987"


Further optimization is:

#define STATION_ID "ABC123"
#define STATION_PASS "XYZ987"

void loop(){
String path = "/weatherstation/updateweatherstation.php?ID=" STATION_ID "&PASSWORD=" STATION_PASS "&dateutc=now&tempf="+celsiusToFahrenheit(temperature)+"&humidity="+String(humidity)+"&action=updateraw";
}


This will remove some intermediate String variables in the expression, etc.

That is just so wrong on so many levels.

Firstly, you should really not use String, especially not for constants.

Secondly, you do not need to manually concatenate string constants at all.

Thirdly, there is very rarely ever any need to concatenate things together into a single string before using them. Instead you can in general send individual parts separately:

#define STATION_ID "ABC123"
#define STATION_PASS "XYZ987"

client.print(F("/weatherstation/updateweatherstation.php?ID="
STATION_ID

By having multiple string constants next to each other (such as "string one " "string two") the compiler will automatically join them together (into "string one string two") for you. No plus, no comma, no nothing - just place them next to each other. And always use F() for string constants.
• Calm down @Majenko, did you see this? Here's the pertinent code... I think he just gave an example. I think this: That is just so wrong on so many levels. is a little rude – Dat Ha Nov 22 '16 at 20:06