I need help!


with this code everything works correctly, the problem is that I do not know how to code correctly to add the other relay module

can you see my error?

Arduino:1.8.5 (Windows 10), Tarjeta:“Arduino/Genuino Uno”

In file included from C:\Users\maria\OneDrive\Documentos\Arduino\libraries\CayenneMQTT\src/CayenneMQTTEthernetClient.h:21:0,

             from C:\Users\maria\OneDrive\Documentos\Arduino\libraries\CayenneMQTT\src/CayenneMQTTEthernet.h:25,

             from C:\Users\maria\OneDrive\Documentos\Arduino\EthernetShieldW5100\EthernetShieldW5100.ino:20:

C:\Users\maria\OneDrive\Documentos\Arduino\libraries\CayenneMQTT\src/CayenneArduinoMQTTClient.h: In member function ‘void CayenneArduinoMQTTClient::connect()’:

C:\Users\maria\OneDrive\Documentos\Arduino\libraries\CayenneMQTT\src/CayenneArduinoMQTTClient.h:58:63: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]

if (!NetworkConnect(&_network, CAYENNE_DOMAIN, CAYENNE_PORT)) {

                                                           ^

C:\Users\maria\OneDrive\Documentos\Arduino\EthernetShieldW5100\EthernetShieldW5100.ino: In function ‘void InputHandler1(Request&, CayenneMessage&)’:

EthernetShieldW5100:56: error: a function-definition is not allowed here before ‘{’ token

{

^

EthernetShieldW5100:64: error: expected ‘}’ at end of input

}

^

exit status 1
a function-definition is not allowed here before ‘{’ token

Este reporte podría tener más información con
“Mostrar salida detallada durante la compilación”
opción habilitada en Archivo → Preferencias.

these are the error messages that shows me

can you try this code and interchange pin between pin 2 and 3 of arduino.

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

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

unsigned long lastMillis = 0;
 
#define ACTUATOR_PIN 2

 #define ACTUATOR_PIN_2 3

void setup() {
	Serial.begin(9600);
pinMode(ACTUATOR_PIN, OUTPUT);
pinMode(ACTUATOR_PIN_2, OUTPUT);
Cayenne.begin(username, password, clientID);
}

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();
		//Write data to Cayenne here. This example just sends the current uptime in milliseconds.
		Cayenne.virtualWrite(0, lastMillis);
}
}
CAYENNE_IN(1)
{
int x = getValue.asInt();
Serial.println(x);
if (x == 1)
{
digitalWrite(ACTUATOR_PIN,  HIGH);
}
else
{
digitalWrite(ACTUATOR_PIN,  LOW);
}}
CAYENNE_IN(2)
{
int y = getValue.asInt();
Serial.println(y);
if (y == 1)
{
digitalWrite(ACTUATOR_PIN_2,  HIGH);
}
else
{
digitalWrite(ACTUATOR_PIN_2,  LOW);
}
}

but the widget must be on channel 1 and 2, right? and for the physical connections I use pins 2 and 3, right?

yes
on dashboard add widget using channel 1 and 2.
connect your relay to arduino 2 and 3 pin.

I’m going to try it, I’m making the connections and I uploaded the code already. Thank you very much.
is it normal that suddenly the signal is lost? suddenly the platform is locked and appears as “offline” and also with the mobile application the same thing happens. It is normal? I read some comments saying that the mobile application was failing

now the platform does not respond. It appears that the device is offline. but the connections are fine and all this time it was working well being online all the time

if I could try it and that code works!
It works with both relays correctly!
only now the device is no longer connected to the platform. It appears offline and that happened suddenly, I was testing it as it worked with the lap and with the mobile application to see if it was linked well when suddenly it was disconnected and now it only appears offline.

I think it’s a platform problem

so it is working as you want now. sorry i made some silly mistake previously and you had to try alot to get it working.

see your serial monitor for connection status or reset your arduino.

nope. i am using it for last hour and no problem at all. maybe problem with your network service.

1 Like

It appeared online again and if it works well.
Yes, in fact that I tried to do, to look for the errors and try to correct it and even try to do the code by myself. But as you have noticed I do not know how to program arduino and without knowledge in programming it is very difficult (it was for me). I thank you so much for all your help and good wishes that I learn to program. Believe me I am going to do it because it´s too much necessary.

really thank you very much, I do not know how to thank you for all your help.

3 Likes