Como incluir outros atuadores no nodemcu

 Estou na luta para aprender a programação no Cayenne.  Meu desejo agora é utilizar o NODEMCU para acionar as luzes da minha casa.  Pelo passo a passo consegui funcioar um relé ligado no pino D5.  No meu painel do Cayenne ficou como Channel 3.  Agora gostaria de colocar mais 4 rele para outras lampadas, mas nao faço ideia como mudar no código IDE.  Com um rele somente o codigo ficou assim:


  • @file SimplePublish.c
  • Simplified example app for using the Cayenne MQTT C library to publish example data.

#include “CayenneMQTTClient.h”

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char* username = “xxxxx”;
char* password = “xxxxxx”;
char* clientID = “xxxxxxx”;

Network network;
CayenneMQTTClient mqttClient;

// Connect to the Cayenne server.
int connectClient(void)
// Connect to the server.
int error = 0;
printf(“Connecting to %s:%d\n”, CAYENNE_DOMAIN, CAYENNE_PORT);
if ((error = NetworkConnect(&network, CAYENNE_DOMAIN, CAYENNE_PORT)) != 0) {
return error;

if ((error = CayenneMQTTConnect(&mqttClient)) != MQTT_SUCCESS) {
	return error;

// Send device info. Here we just send some example values for the system info. These should be changed to use actual system data, or removed if not needed.
CayenneMQTTPublishData(&mqttClient, NULL, SYS_MODEL_TOPIC, CAYENNE_NO_CHANNEL, NULL, NULL, "Linux");



// Main loop where MQTT code is run.
void loop(void)
while (1) {
// Yield to allow MQTT message processing.
CayenneMQTTYield(&mqttClient, 1000);

	// Publish some example data every second. This should be changed to send your actual data to Cayenne.
	CayenneMQTTPublishDataFloat(&mqttClient, NULL, DATA_TOPIC, 0, TYPE_TEMPERATURE, UNIT_CELSIUS, 30.5);
	CayenneMQTTPublishDataInt(&mqttClient, NULL, DATA_TOPIC, 1, TYPE_LUMINOSITY, UNIT_LUX, 1000);


// Main function.
int main(int argc, char** argv)
// Initialize the network.

// Initialize the Cayenne client.
CayenneMQTTClientInit(&mqttClient, &network, username, password, clientID, NULL);

// Connect to Cayenne.
if (connectClient() == CAYENNE_SUCCESS) {
	// Run main loop.
else {
	printf("Connection failed, exiting\n");

return 0;


Why in Nodemcu I inform that I am using channel 3 and physically I connect in pin D5. If you want another device on channel 8 for example which pin D “x” should I connect to?

channel are different from arduino pins. channel are virtual path used for communicating between cayenne and your device. when you add a button on your dashboard with channel 2 selected. this means you are using channel 2 for sending button value (i.e 0/1) from cayenne dashboard to your arduino. now once you have this value on your channel, you can use it to turn on relay connected to any pin on your arduino.

CAYENNE_IN(2) //channel used for button widget 2
int x = getValue.asInt(); //storing the value in x
digitalWrite(arduino_output_pin, x); //writing this x value to arduino output pin

1 Like