arduino/node red MQTT

hello, i am trying to use a switch on node-red to turn an led on, on the Arduino i am not sure if im doing it right. i am getting data back from node red on the serial monitor but i cant seem to do anything with that data.
please help thanks.
i am using an Arduino MKRWIFI1010

arduino_wifi_mqtt.ino (2.08 KB)

What data are you getting from MQTT?

 while (mqttClient.available()) {
      Serial.print((char)mqttClient.read());
      Serial.println();
      
      
 
     int state = (int)mqttClient.read();
      if(state == 1){
        digitalWrite(0, HIGH);
      }
      if(state == 2){
        digitalWrite(0, LOW);
      }
 }

You do know that the first read() consumes the character you see in the Serial Monitor, so the state code sees only a potential second character, don't you?