Byte Pointer Comparison

Hi there!
In my code (adapted from a tiny mqtt exemple) there are a byte pointer variable that will receive the content of a mqtt subscription. This subscription will just receive 1 or 0. 1 to tunr a relay on and 0 to turn a relay off.
The problem is that I need to know how to compare this pointer on my code to decide what action need to be done.
I am a begginer in C++ and don't know how to do this comparison.
Can some one help me with this, please?
This is the part of my code that I am talking about:

void mqttCallback(char* topic, byte* message, unsigned int len) {
  Serial.print("Message arrived [");
  Serial.print("]: ");
  Serial.write(message, len);

  if (String(topic) == tRoubado) {
    if(message[0] == msg[0]) {  // declared as unsigned char* msg; at the beginning of my code, it was just an attempt that didn't work
      Serial.println("PASSOU PELO IF");
      digitalWrite(disparaAlarme, liga);
    } else {
      Serial.println("PASSOU PELO ELSE");
      digitalWrite(disparaAlarme, desliga);
    mqtt.publish(tRoubadoEst, message ? "1" : "0");
if ( message[0] == '0' ) {
  // do something
else {
  // do something else

or declare this at the top of your sketch

unsigned char msg[] = "0";

but note that this will only work if you have 1 char. It would not work with a string like "on" or "off" since you would need to use strcmp() for that.

So easy and me getting beaten up by the code.
Thank you so much!

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