Duvida no NodeMCU

Good evening friends, I need to include two relays in my project to connect two lamps. I’m using NodeMCU Esp8266. I have saved this code via IDE, but when I add new Widget (custom widgets / button) and added but I can not trigger the relay.

Code I used following the tutorial:

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>

// WiFi network info.
char ssid = “((MP))”;
char wifiPassword = “xxxxxxx”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “xxxxxxxxxxxxxxxxxxxxxx”;
char password = “xxxxxxxxxxxxxxxxxxxxxx”;
char clientID = “xxxxxxxxxxxxxxxxxxxxxxxx”;

unsigned long lastMillis = 0;

void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
Cayenne.loop();
}

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
Cayenne.virtualWrite(0, millis());
// Some examples of other functions you can use to send data.
Cayenne.celsiusWrite(1, 22.0);
Cayenne.luxWrite(2, 700);
Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}

// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
CAYENNE_LOG(“Channel %u, value %s”, request.channel, getValue.asString());
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError(“Error message”);
}

what are using the custom button for? in your code there is no code which reads the state of the button.
Regarding the trigger issue can you PM me your account email id.

I copied the code that the cayenne suggested, but have verify in the IDE the following error:

Arduino: 1.8.5 (Windows 10), Card: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, 4M (1M SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch,

Compilation options changed, recompiling all
C: \ Users \ Central-MP \ Documents \ Arduino \ NodeMCU-TOMADAS \ NodeMCU-TOMADAS.ino: 4:30: Fatal error: CayenneMTTClient.h: No such file or directory

#include “CayenneMTTClient.h”

                           ^

compilation terminated.

exit status 1
Compiling error for NodeMCU 1.0 (ESP-12E Module)

This report would have more information
“Show detailed output during compilation”
option can be activated under “File → Preferences”

have you installed the cayenne library?

Sim instalei, veja na tela!
54|623x500

you need to upload the pic properly. i cannot see it.

Desculpe-me

in your screenshot i can see that the code is uploaded succesfully. So which error this you post above?

Projeto_X.txt (2.3 KB)

Quando mando gravar esse código no NodeMCU da esse erro:

Arduino: 1.8.5 (Windows 10), Placa:“NodeMCU 1.0 (ESP-12E Module), 80 MHz, 4M (1M SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200”

C:\Users\Central-MP\Documents\Arduino\Projeto_X\Projeto_X.ino\Projeto_X.ino.ino:7:31: fatal error: CayenneMQTTClient.h: No such file or directory

#include “CayenneMQTTClient.h”

                           ^

compilation terminated.

exit status 1
Erro compilando para a placa NodeMCU 1.0 (ESP-12E Module)

Este relatório teria mais informações com
“Mostrar a saida detalhada durante a compilação”
opção pode ser ativada em “Arquivo → Preferências”

Did you restart the Arduino IDE after installing the CayenneMQTT library? Do you see the CayenneMQTT library under C:\Users\Central-MP\Documents\Arduino\libraries? Does a CayenneMQTTClient.h file exist under C:\Users\Central-MP\Documents\Arduino\libraries\CayenneMQTT\src?

Removi o ide arduino, fiz nova instalação e inclusive em outro micro. veja a captura de tela da pasta informado
Mas o erro persiste.

@mrpontes any specific reason for using this code, we have a example code of esp8266 which works with nodemcu Cayenne-MQTT-Arduino/ESP8266.ino at master · myDevicesIoT/Cayenne-MQTT-Arduino · GitHub

Mesmo com esse código exemplo acontece o erro, nao sei porque o IDE nao encontra a biblioteca na pasta. Estou quase desistindo de usar o NodeMCU com o cayenne.

That is very strange. What other libraries do you have under C:\Users\Central-MP\Documents\Arduino\libraries? Any other Cayenne libraries there that might be interfering with CayenneMQTT?

Can you enable verbose compilation output under File → Preferences and post the output from compiling the standard ESP8266 example under File → Examples → CayenneMQTT → Connections → ESP8266?

Boa tarde, consegui resolver parte do meu problema. Achei o código do primeiro projeto usando o NodeMCU com o Cayenne. (abaixo). Com esse código consegui adicionar um botão (actuador - rele) para funcionar somente acionando (Widget) sem precisar gravar o código no Nodemcu.
Mas ele funciona somente no pino canal 3 e o relé no pino 5 (físico). Será que tem como colocar outro relé noutro canal? Poderia me dizer qual canal escolho e qual pino eu coloco físico?

//https://mydevices.com/cayenne/docs-2/bring-your-own-thing-api/#bring-your-own-thing-api-supported-data-types

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>

// WiFi network info.
char ssid[] = "XXXX";
char wifiPassword[] = "21031966";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "XXXXXX";
char password[] = "XXXXXX";
char clientID[] = "XXXXXXXX";

unsigned long lastMillis = 0;
//-----------------------------
const int Led_01 = 14;
const int LedPWM = 12;
//-----------------------------
int ValorADC = 0;
int MyTemperatura = 0;
float PorcentajeCo2 = 14.56;
//-----------------------------

void setup() {
  //--------------------------
  pinMode(Led_01, OUTPUT);
  pinMode(LedPWM, OUTPUT);
  //--------------------------
	Serial.begin(9600);
	Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
	Cayenne.loop();

	//Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
	if (millis() - lastMillis > 10000) {
		lastMillis = millis();

    //-----------------------------
    ValorADC = analogRead(A0);  
    MyTemperatura = map(ValorADC, 0, 1023, 0, 100);
    
    //Write data to Cayenne here. This example just sends the current uptime in milliseconds.
    Cayenne.virtualWrite(0 , MyTemperatura , TYPE_TEMPERATURE , UNIT_CELSIUS);
    Cayenne.virtualWrite(1 , ValorADC);
    Cayenne.virtualWrite(2 , PorcentajeCo2);

    PorcentajeCo2 = PorcentajeCo2 + 4.72;
    if(PorcentajeCo2>100){PorcentajeCo2=0;}
    //-----------------------------
    
		//Write data to Cayenne here. This example just sends the current uptime in milliseconds.
		//Cayenne.virtualWrite(0, lastMillis);
		//Some examples of other functions you can use to send data.
		//Cayenne.celsiusWrite(1, 22.0);
		//Cayenne.luxWrite(2, 700);
		//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
	}
}

CAYENNE_IN(3)
{ 
   int Valor_Canal_03 = getValue.asInt();
   digitalWrite(Led_01, Valor_Canal_03);
}

CAYENNE_IN(4)
{ 
   int MySlider = getValue.asInt();
   analogWrite(LedPWM, MySlider);
   /*
   if (x_valor_1){Serial.println("Mensaje 1");}
   if (x_valor_2){Serial.println("Mensaje 2");}
   if (x_valor_3){Serial.println("Mensaje 3");} 
   */
}

/*
//Default function for processing actuator commands from the Cayenne Dashboard.
//You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
	CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());
	//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
}
*/

Add a button to your dashboard with channel number 5 and add the below code:

int Relay pin = 5;
CAYENNE_IN(5)
{ 
   int value  = getValue.asInt();
   digitalWrite(Relay pin, value);
}

Obrigado desde já pela atenção e tentativas de ajuda. Coloquei assim no meu código:

// pinos para reles

int Relay_pin = 5;
int Relay_pin_1 = 6;

// Adicionando comandos para relé

CAYENNE_IN(5)
{
int value = getValue.asInt();
digitalWrite(Relay_pin, value);
}

CAYENNE_IN(6)
{
int value = getValue.asInt();
digitalWrite(Relay_pin_1, value);
}

Um relé funciona, mas o segundo não aciona.

Make sure you have connected the relay pins properly and try the below code:

int Relay_pin = 5;
int Relay_pin_1 = 6;

// Adicionando comandos para relé

CAYENNE_IN(5)
{
int value = getValue.asInt();
digitalWrite(Relay_pin, value);
}

CAYENNE_IN(6)
{
int value_1 = getValue.asInt();
digitalWrite(Relay_pin_1, value_1);
}

Fiz alteração no código como proposto. Porem continua ativando somente um dos reles. Veja a ligação física!
20181021_201133|690x388


Funcionamento