PubSubClient and AndroidJSON

Hey all! New to this forum and would like some help in a project I'm working on...

pubsub callback

void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("New message on [");
  Serial.print(topic);
  Serial.print("] ");
  Serial.println("");
  char s[length];

  for (int i = 0; i < length; i++) {
    Serial.print((char)payload[i]);
    s[i]=payload[i];
  }

  StaticJsonBuffer<500> jsonBuffer;
  JsonObject& root = jsonBuffer.parseObject(s);
  if (!root.success()) {
    Serial.println("parseObject() failed");
  }
  
  String relay = root["relay"]; // "relayOne"
  int time = root["timestamp"]; // 1351824120
  String trigger = root["trigger"]; // "ON"

  // Feel free to add more if statements to control more GPIOs with MQTT
  commander(relay, trigger);

}

commander function

void commander(String relay, String trigger) {

  if(trigger == "ON"){
      Serial.print("Turning ");
      Serial.println(relay);
      Serial.println(" on");
      digitalWrite(relay, HIGH);
  } else if(trigger == "OFF"){
      Serial.println(relay);
      digitalWrite(relayOne, LOW);
      Serial.print("TRIGGERED!");
  } else {
      // turn all the LEDs off:
      for (int pin = 0; pin < relayPinCount; pin++) {
        digitalWrite(relayPins[pin], LOW);
      }
  }
  Serial.println();
}

Not sure how to pass the values in the function in order to be used within the digitalWrite functions. Thanks for your help!

I'm getting the following error:

error: cannot convert 'String' to 'uint8_t' {aka unsigned char}' for argument '1' to 'void digitalWrite(uint8_t, uint8_t)'

The problem should be obvious from the error message. You can't use a String as the pin argument to digitalWrite(). If you insist on using String then you will need to use toInt() to convert it to an integer. See: