digitalwrite with function parameter as parameter Firstly, excuse my poor English, this is not my native langage.
I'm trying to use an Arduino Uno to drive an 8 relay board from an MQTT Subscription. I ask for help because i'm some kind of beginner in arduino, i'm just a Linux addict.
The idea is to get a payload from PubSubclient and use it to manage relays.
For example, the payload '71' ask the relay 7 to turn on and '42' make the relay 4 to turn off.
All works fine until I wanted to write a function with two parameters : 'relay_number' and 'Action'
All parameters are received but the relay never goes up or down.
My code :
void callback(char* topic, byte* payload, unsigned int length) {
  
  Relay_Nb = (char)payload[0];
  Action = char(payload[1]);

  Serial.println(Relay_Nb);
  Serial.println(Action);
  
  RelayControl(Relay_Nb, Action);
}

void RelayControl(char Relay_Nb, char Action) {
  Serial.println(Relay_Nb);   // for debugging purpose
  Serial.println(Action);
   
  if ( Action == '0') {
    Serial.print(&quot;Bringing down Relay &quot;);
    Serial.println(Relay_Nb);
    digitalWrite(Relay_Nb, LOW); 
  } else if (Action == '1') {
    Serial.print(&quot;Bringing up Relay &quot;);
    Serial.println(Relay_Nb);
    digitalWrite(Relay_Nb, HIGH);
  } else if (Action == '2') {
    // Relay temporisé (ouverture portail par ex)
    Serial.println(&quot;Bringing up, and down Relay &quot;);
    digitalWrite(Relay_Nb, HIGH);
    delay(750);
    digitalWrite(Relay_Nb, LOW);
  } 
}

I'm sure an old maker have the solution i'm searching for hours now.
Please help and don't hesitate to show me others ways.
Thanks.
You are sending the parameter Relay_Nb as a character, and then using it as an integer.
You need to turn the character into an integer - and the simplest way is to subtract the ASCII value of 0 from it:
Relay_Nb = payload[0] - '0';

But with that said, a note on how you have written your callback:

You aren't checking the data is valid.

You should really be doing, at the very least, the following:

Check that the length parameter is at least 2,
Check that the two data values are within the correct range for your function