Testing for a MQTT topic

Hello,
I am using an Arduino mega with PubSub Client 2.8.0
I want to subscribe to two topics and need to distinguish which topic has arrived in the calback routine.
When the message arrives I can Serial.print the topic (See below). But when I try to test the topic name with an if statement the if never proves true.

void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  if(topic=="Broadcast"){   //why doesn't this work?
  Serial.println("Broadcast RX");
}

Seems simple but it is baffling to this noobe. Any help is greatly appreciated.

read here thereĀ“s some light. compare characters (or string) in "if" function - #5 by UKHeliBob

Thank you so much. strncmp() was my ticket to more hair. Shows me that I need to learn more about strings!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.