Checking data received over MQTT

Hi all.

I am having problems with the strcmp function which despite playing around with for quite some time I've been unable to solve.

I am using the pubsub client (https://github.com/knolleary/pubsubclient/tags) to receive messages over MQTT. I can see all of this is working as expected as I am printing the received message to the serial port and it matches the one that was sent. However my strcmp function fails every time regardless of whether it receives the message I am looking for or not. To simplify things for myself at this stage I am simply looking for the message "correct". Receipt of this message should print "allow" to the serial, whereas anything else will print "deny" to the serial.

As the code is quite long I have only included the function that is called when a message is received and does the actual comparison.

void callback(char* topic, byte* payload, unsigned int length) {
  
  // In order to republish this payload, a copy must be made
  // as the orignal payload buffer will be overwritten whilst
  // constructing the PUBLISH packet.
  
  int i = 0;
  
  for(i=0; i<length; i++) {
    messageBuff[i] = payload[i];
  }
  
  messageBuff[i] = '\0';

  if(strcmp(messageBuff, "correct")  == 1) {
    Serial.println(messageBuff);
    Serial.println("allow");
  }

  else {
    Serial.println(messageBuff);
    Serial.println("deny");
  }
  
  memset (messageBuff, 0, sizeof(messageBuff));
}
  if(strcmp(messageBuff, "correct")  == 1) {
    Serial.println(messageBuff);
    Serial.println("allow");
  }

So, if the message is "wrong", that comes after "correct" in the dictionary, so strcmp() returns 1. Somehow you decide that that means "allow". Why?

strcmp() returns 0 if the string match.

Thanks Paul,

Couldn't see the wood for the trees on that one.

You are absolutely correct. Changed the 1 to a 0 and everything now works perfectly.