[RSLVED] invalid operands 'const char*' and 'const char [2]' to binary 'operator

ThingSpeak:294: error: invalid operands of types 'const char*' and 'const char [2]' to binary 'operator+'

Error from line 294 below:

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

In line 289, no error is generated, but it doesn't work. The output shown below is missing ("field" + allSensors*.field + '=')*
* *House Temperaturesower is:  64.40&field2= 72.14&field3= 72.95&field4= 62.28&field5= 59.18* *
curiously, the 'else channelHouseStr = channelHouseStr + "&field" + allSensors*.field + "=" + tempStr;' works fine.*
What's going on here?

turgo:
What's going on here?

Same problem you had before: The const char * variable types ("field" in your sketch) doesn't have the + operator overloaded to allow concatenation. If channelHouseStr is a string (null-terminated char array), then use strcat() or sprintf(). If it's a String object, then first generate a String out of "field" before trying to concatenate.

So, the second 'else' line works because the first item is a type String, but the original 'if' line fails because "field" is not a string. How do I turn "field" into a string? (intuitively, "field" looks like a string to me.)

There is some kind of weird pointer magic going on here. The output of the first if is:

e devices... 64.06

The text "e devices..." is from an earlier line in my code:

Serial.print("Locating House devices...");

so somehow that if line generates a pointer to it.

What is happening?

Looks like memory corruption to me, although it's possible it is just a bug in your code. Can you post a complete sketch that demonstrates the problem - preferably one without a lot of extraneous code?

turgo:
because "field" is not a string.

Incorrect. "field" is a string. It is NOT a String. Again, note the difference in capitalization. strings don't support concatination via the plus operator; Strings do.

Thanks for your help all. The final answer was to recast with String():

if (channelHouseStr.length()==0) channelHouseStr = String("field") + allSensors[i].field + "=" + tempStr; //289

The pointer behavior can remain a mystery.

Arrch:
Incorrect. "field" is a string. It is NOT a String. Again, note the difference in capitalization. strings don't support concatination via the plus operator; Strings do.

Thanks for the explanation!