error: no match for 'operator=='

I have studied this error for hours on C++ forums to no avail!

if("House Temperatures"==allSensors[i].channel)

Generates this compile error:

ThingSpeak:294: error: no match for 'operator==' in '"House Temperatures" == allSensors[i].Sensor_Specification::channel'

allSensors*.channel is part of this struct:*
* *struct Sensor_Specification {   String location;   String channel;   int field;   String  addressString;   DeviceAddress address;   int pin;   unsigned long updateInterval;//in milliseconds   boolean online;   float currentTemp;   float recentTemps[5];   float averageTemp; } ; #define numberSensors 8 Sensor_Specification allSensors[] = {   {     "1st Floor","House Temperatures",1,"2826AEEB030000B2",{       0x28, 0x26, 0xAE, 0xEB, 0x03, 0x00, 0x00, 0xB2    }     ,11,600000,false,0,{       0,0,0,0,0    }     ,0  }   ,{* *
Please Help!

What happens if you replace:

if("House Temperatures"==allSensors[i].channel)

with

if(strcmp("House Temperatures", allSensors[i].channel))

where strcmp() return 0 if the two strings are equal.

Yes basically in C you can't use == to compare strings.

Thanks for the replies!

Well, in fact, strcmp() was what I had originally tried (see the else if below):

if("House Temperatures"==allSensors[i].channel)
        {
          if (channelHouseStr.length()==0) channelHouseStr = "field" + allSensors[i].field + '=' + tempStr;
          else channelHouseStr = channelHouseStr + "&field" + allSensors[i].field + "=" + tempStr;
        }
        else if(strcmp("Water Source",allSensors[i].channel)==0)
        {
          if (channelWaterStr.length()==0) channelWaterStr = "field"+allSensors[i].field+'='+tempStr;
          else channelWaterStr = channelWaterStr+"&field"+allSensors[i].field+"="+tempStr;
        }

it yields this error (line 293), which I have also pursued on the forums to no avail:

ThingSpeak.ino: In function 'void loop()':
ThingSpeak:288: error: no match for 'operator==' in '"House Temperatures" == allSensors[i].Sensor_Specification::channel'
ThingSpeak:293: error: cannot convert 'String' to 'const char*' for argument '2' to 'int strcmp(const char*, const char*)'

I'm thinking that these problems are related... Help!

It would be helpful to post the complete program so we can compile it ourselves. Also, have you tried:

else if(strcmp("Water Source", (const char*) allSensors[i].channel)==0)

to see if the cast makes a difference?

Thanks for the idea, econjack. Compiler says invalid cast.

The whole program exceeds 9500 characters. It is attached.

ThingSpeak.ino (11.3 KB)

turgo:
Compiler says invalid cast.

I don't have your full set of #include files here so I can't compile it myself. Can you post the complete error message, please?

if("House Temperatures"==allSensors[i].channel)

Try this:

if(allSensors[i].channel == "House Temperatures")

Thanks Arrch, that worked. I am shocked and disappointed that it makes a difference what side of the == the "string" is on.

turgo:
Thanks Arrch, that worked. I am shocked and disappointed that it makes a difference what side of the == the "string" is on.

You're leveraging the String object's overloading of the == operator which allows it to compare itself with a const char * (also known as a string, note the lack of capitalization):

if(allSensors[i].channel == "House Temperatures")

translates to

if(allSensors[i].channel.operator==("House Temperatures"))

The other way around doesn't work because the const char *'s == operator isn't setup to allow comparisons to String objects.

Thanks Arrch, it's nice to know the reason. However, it also disappointing that to program in C++ one has to know such esoteric details. It's much easier to program in a language like AppleScript that takes care of all those kind of details transparently. Are there similar languages for micro controllers?

turgo:
Thanks Arrch, it's nice to know the reason. However, it also disappointing that to program in C++ one has to know such esoteric details. It's much easier to program in a language like AppleScript that takes care of all those kind of details transparently. Are there similar languages for micro controllers?

These language that are "easier" than C++ can achieve that because they are being run on machines with 1000 of times the memory and clock speed, as well as having an operating systems to handle low level hardware interaction. The only other ones I'm aware of are the Netduinos and Propellors. Netduinos use a micro .NET framework, while the Propellors use a proprietary (and confusing) Spin language.