My project is not arduino. One to trigger 4 relays work normal, when I switched to MQTT I can not add the second trigger (relay). We advise you to add it first using a sketch or code, but I have questions about how to write the code for the next triggers together. In the middle code only the first relay, how do I put 4 or more?
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space #include <CayenneMQTTEthernet.h>
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = â6xxxxxxâ;
char password = â8xxxxxxâ;
char clientID = â7axxxxxxâ;
#define VIRTUAL_CHANNEL 8 #define ACTUATOR_PIN 4 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
// This function is called when data is sent from Cayenne.
CAYENNE_IN(VIRTUAL_CHANNEL)
{
int value = getValue.asInt();
CAYENNE_LOG(âChannel %d, pin %d, value %dâ, VIRTUAL_CHANNEL, ACTUATOR_PIN , value);
// Write the value received to the digital pin.
digitalWrite(ACTUATOR_PIN , value);
}
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h>
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = â6xxxxxxâ;
char password[] = â8xxxxxxâ;
char clientID[] = â7axxxxxxâ;
#define VIRTUAL_CHANNEL 8
#define ACTUATOR_PIN 4
#define VIRTUAL_CHANNEL_1 9
#define ACTUATOR_PIN_1 5 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
void setup()
{
Serial.begin(9600);
pinMode(ACTUATOR_PIN , OUTPUT);
pinMode(ACTUATOR_PIN_1 , OUTPUT);
Cayenne.begin(username, password, clientID);
}
void loop()
{
Cayenne.loop();
}
// This function is called when data is sent from Cayenne.
CAYENNE_IN(VIRTUAL_CHANNEL)
{
int value = getValue.asInt();
CAYENNE_LOG(âChannel %d, pin %d, value %dâ, VIRTUAL_CHANNEL, ACTUATOR_PIN , value);
// Write the value received to the digital pin.
digitalWrite(ACTUATOR_PIN , value);
}
CAYENNE_IN(VIRTUAL_CHANNEL_1)
{
int value_1 = getValue.asInt();
CAYENNE_LOG(âChannel %d, pin %d, value %dâ, VIRTUAL_CHANNEL, ACTUATOR_PIN , value);
// Write the value received to the digital pin.
digitalWrite(ACTUATOR_PIN_1 , value_1);
}