Library interferes with preprocessor expressions

I’m experiencing an issue where, after I include the SPARKFUN_PHOTON_WEATHER_SHIELD_LIBRARY in my project, I can no longer define string macros (preprocessor constants). It’s definitely related to the inclusion of this library as the following code is valid prior to inclusion and invalid after inclusion, with the error: token ““ELECTRON”” is not valid in preprocessor expressions.

#define DEVICE_FAMILY "ELECTRON"

void setup() {

#if DEVICE_FAMILY == "ELECTRON"
Particle.publish("Hello World");
#endif

}

void loop() {

}

Can anyone explain why this is happening and how to fix the error?

I'm pretty sure you still can define them, but I'm not convinced you can compare the macro with a string litteral via the equality operator (==).
e.g. see here Question 10.12

Did you know about the PLATFORM_ID macro that is defined for you by the build enviroment?

With that you'd write

#if (PLATFORM_ID == PLATFORM_ELECTRON_PRODUCTION)
  Particle.publish("Hello World");
#endif

Nope, it's (unsurprisingly) not building for me even without the library.
Just try a fresh project with nothing but your own code and try building.

Thank you @ScruffR. Your solution cuts through the problem entirely.

2 Likes