Fifth Particle.subscribe not working

Hey there,
I am new with particle firmware coding.
I try to controll a relay with 4 channels with google home.
My problem is to controll the 3rd and 4th channel with particle.
If I change the “relay1” to D3 the relay 3 is ready runs.
Here is my code:

int relay1 = D0; //pin to which relay is connected
int relay2 = D1; //pin to which relay is connected
int relay3 = D2; //pin to which relay is connected
int relay4 = D3; //pin to which relay is connected

//int boardLed = D7;
bool vin1 = LOW; //a virtual boolean variable
bool vin2 = LOW; //a virtual boolean variable
bool vin3 = LOW; //a virtual boolean variable
bool vin4 = LOW; //a virtual boolean variable

// setup() is run only once, it's where we set up GPIO and initialise peripherals
void setup() {
    
  // Setup GPIO
pinMode(relay1,OUTPUT); // relay1 pin is set as output
digitalWrite(relay1,HIGH);
pinMode(relay2,OUTPUT); // relay2 pin is set as output
digitalWrite(relay2,HIGH);
pinMode(relay3,OUTPUT); // relay3 pin is set as output
digitalWrite(relay3,HIGH);
pinMode(relay4,OUTPUT); // relay4 pin is set as output
digitalWrite(relay4,HIGH);
 
  // Subscribe to events published by IFTTT using Particle.subscribe
  Particle.subscribe("relay1_off", myHandler1); //turning off function declaration
  Particle.subscribe("relay1_on", thisHandler1); //turning on function declaration
  Particle.subscribe("relay2_off", myHandler2); //turning off function declaration
  Particle.subscribe("relay2_on", thisHandler2); //turning on function declaration
  Particle.subscribe("relay3_off", myHandler3); //turning off function declaration
  Particle.subscribe("relay3_on", thisHandler3); //turning on function declaration
  Particle.subscribe("relay4_off", myHandler4); //turning off function declaration
  Particle.subscribe("relay4_on", thisHandler4); //turning on function declaration
}

// loop() runs continuously, it's our infinite loop.
void loop() {
     if (vin1==HIGH)    //relay 1
     {
         digitalWrite(relay1,LOW);
     }
else if (vin1==LOW)
      {
         digitalWrite(relay1,HIGH);
     }
     
     if (vin2==HIGH)       //relay2
     {
         digitalWrite(relay2,LOW);
     }
else if (vin2==LOW)
      {
       digitalWrite(relay2,HIGH);
     }
     
      if (vin3==HIGH)      //relay3
     {
        digitalWrite(relay3,LOW);
     }
else if (vin3==LOW)
      {
       digitalWrite(relay3,HIGH);
     }
     
      if (vin4==HIGH)     //relay4
     {
        digitalWrite(relay4,LOW);
     }
else if (vin4==LOW)
      {
       digitalWrite(relay4,HIGH);
     }

}

//our events are called when IFTTT applets are triggered
void myHandler1(const char *event, const char *data)
{
    vin1=LOW;
}
void thisHandler1(const char *event, const char *data)
{
     vin1=HIGH;
}

void myHandler2(const char *event, const char *data)
{
    vin2=LOW;
}
void thisHandler2(const char *event, const char *data)
{
    vin2=HIGH;
}

void myHandler3(const char *event, const char *data)
{
    vin3=LOW;
}
void thisHandler3(const char *event, const char *data)
{
    vin3=HIGH;
}

void myHandler4(const char *event, const char *data)
{
    vin4=LOW;
}
void thisHandler4(const char *event, const char *data)
{
   vin4=HIGH;
}

The command from iftt for the relay 3 and 4 is shown in particle console.
I hope anyone can help.
thx!

https://docs.particle.io/reference/firmware/electron/#particle-subscribe-

Have a look:

NOTE 1: A device can register up to 4 event handlers. This means you can call Particle.subscribe() a maximum of 4 times; after that it will return false.

You can use a prefix and subscribe to “relay”, since they all have that in common. You can then figure out, in your code, what the required action is.

3 Likes

Hello Hyp,

I also had the same problem…
just relay 1 and 2 can wok properly…

Have you also tried the proposed solution?

not yet…