MQQT using payload later in sketch

I'm looking at using the information received over MQQT later on in my mega sketch but am unsure how to do it and can't seem to find any indicators on the web.

Any help would be gratefully received.

void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (int i=0;i<length;i++) {
Serial.print((char)payload[i]);

if (topic == "Pylon/SMA")
** {**
** messageSMA = received_payload;**
** }**

}
Serial.println();
}

That is not how you compare strings in C++

if ( strcmp(topic, "Pylon/SMA") == 0 ) {
  strcpy( messageSMA, payload);  // or whatever variables you are using
}

Thank you, that's a big help.

Now need to look at the payload and how to convert it back to what was sent.

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