Send data from cayenne to arduino possible ?!

we try again guys, desperately looking for a way to exchange values ​​between arduino devices in an easy and fast way maybe.
do you know how to suggest a guide to one of the first programming and easy to do?
ie from one device to another ?!
that is, if I produce as much photovoltaic I have to activate resistance or reduce the load


to subscribe to another device published data here is a code which i modified from @spacefolder code.

/*
  MQTT Raw Data to Cayenne Dashboard,
  using the great Nick O'Leary's PubSubClient
  (Arduino Client for MQTT, https://github.com/knolleary/pubsubclient)
  What does it do?
  This sketch will attempt to connect to Cayenne MQTT server via Wifi,
  subscribe to a "dashboard button" topic, to turn on/off the esp8266 built in led.
  Also it will publish temperature readings from a Dallas DS18b20 digital temperature sensor.
  In a near future, the esp8266 (NodeMCU v2) should act as a smart thermostat, controlling my central heater/boiler.
  It should be possible to remotely check ambient temperature and boiler status using
  Cayenne Dashboard and turn the heater on/off (in case I left home in a hurry!, etc.)
  Inspired in several tutorials and sketches mashed up, mainly..
  Andreas Spiess  https://github.com/SensorsIot
  Terry King      terry@yourduino.com
  Markus Ulsass   https://github.com/markbeee
  Marc / spacefolder
*/

// ---------- INLCUDE LIBRARIES ----------

#include <ESP8266WiFi.h>
#include <PubSubClient.h>


// ---------- DEFINE CONSTANT VALUES ----------

#define MQTT_SERVER     "mqtt.mydevices.com"
#define MQTT_SERVERPORT 1883
#define MQTT_USERNAME   ""
#define MQTT_PASSWORD   ""
#define CLIENT_ID       ""

#define CLIENT_ID_SUB       ""


#define MQTT_TOPIC_BTN_ONOFF    "v1/" MQTT_USERNAME "/things/" CLIENT_ID_SUB "/data/2"

// ---------- INITIALIZE INSTANCES ----------

WiFiClient    espClient;              // Creates a client instance for the PubSubClient
PubSubClient  client(espClient);


// ---------- DEFINE VARIABLES ----------

const   char* ssid        = ""; // WLAN-SSID (WiFi router)
const   char* password    = ""; // WLAN Password

// Define a datatype to store the mqtt message, up to 50 bytes.
char    msg[50];                 // 50 BYTES QUIZAS SEA MUCHO AL GAS, pero bueh





// -------------------- SETUP -------------------

void setup() {

  // Initialize serial monitor for debugging purposes.
  Serial.begin(9600);
  Serial.println("DEBUG: Entering setup ");

  // Attempt to connect to WiFi.
  WiFi.begin(ssid, password);
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");                       // Faltaria agregar que muestre el ip si no es estatico
  Serial.println("WiFi connected");

  // Initialize MQTT PubSub Library
  client.setServer(MQTT_SERVER, MQTT_SERVERPORT);
  // Function called in case of an incomming mqtt message from Cayenne Dashboard
  // (In this case is the dashboard button to turn on/off the heater)
  client.setCallback(mqttCallback);

  Serial.println("DEBUG: Setup Done! ");

}




// -------------------- LOOOP -------------------

void loop() {
  // Check if the esp8266 is connected to the mqtt server.
  if (!client.connected()) {
    reconnect();
  }

  // If connected, perform PubSubClient housekeeping function.
  client.loop();
  delay(500);
}







// ------------------------------ OTHER FUNCTIONS

// Function that attempts to reconnect to the mqtt server.

void reconnect() {
  // If esp8266 is disconnected from the mqtt server, try to reconnect.
  // (*** I still need to think what wil happen to the boiler if connection is lost ***)
  while (!client.connected()) {
    Serial.print("DEBUG: Attempting MQTT connection...");

    // Attempt to connect
    if (client.connect(CLIENT_ID, MQTT_USERNAME, MQTT_PASSWORD)) {
      Serial.println("connected");

      // Once connected, resubscribe to the Dashboard on/off button topic.
      client.subscribe(MQTT_TOPIC_BTN_ONOFF);

    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
  Serial.println("DEBUG: Quiting reconnect loop ");
}

// Function to intercept MQTT messages

void mqttCallback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  for (int i = 0; i < length; i++) {
    // Show the received message "stream" in the serial monitor.
    Serial.print((char)payload[i]);
  }
  Serial.println();
 //  Delay for debugging purposes. If a message arrives from Cayenne, the terminal feed pauses 5'.
  delay(5000);
}

#define MQTT_SERVER “mqtt.mydevices.com
#define MQTT_SERVERPORT 1883
#define MQTT_USERNAME “”
#define MQTT_PASSWORD “”
#define CLIENT_ID “”

#define CLIENT_ID_SUB “”

tell me what should I enter ?!

#define CLIENT_ID is the id of the subscriber device.

#define CLIENT_ID_SUB is the ID of the device you want to subscribe to.

So #define CLIENT_ID_SUB will be your sender ID and #define CLIENT_ID will be your receiver ID

DEBUG: Attempting MQTT connection…failed, rc=-1 try again in 5 seconds

this is the message that gets me out of error, please can you be more exhaustive in describing the code?

are you using an esp or Arduino device? it is working without any issue on my nodemcu. the code is quite straight forward I guess. what is the thing you are not getting? it first connects to the wifi, next connect to the server. if connected, subscribes to the publishes topic of sender device.

nothing, I can’t as you say, I ask for help, keep giving me the same mistake

which part of the code do you want me to explain. (not the entire code)

I don’t know what the problem is and if it depends on the code, but I posted the error that gives me, so I think it’s an authentication problem

i just tried again the same above code with wemos D1 mini and it worked for me again. which device are you using?

i am using esp8266

can you provide a link to the device.

spiegati meglio. è un nodemcu 12e

it should work on nodemcu without any issue.

#include <ESP8266WiFi.h>
#include <PubSubClient.h>

// ---------- DEFINE CONSTANT VALUES ----------

#define MQTT_SERVER “mqtt.mydevices.com
#define MQTT_SERVERPORT 1883
#define MQTT_USERNAME “”
#define MQTT_PASSWORD “”
#define CLIENT_ID “”

#define CLIENT_ID_SUB “”

#define MQTT_TOPIC_BTN_ONOFF “v1/” MQTT_USERNAME “/things/” CLIENT_ID_SUB “/data/2”

// ---------- INITIALIZE INSTANCES ----------

WiFiClient espClient; // Creates a client instance for the PubSubClient
PubSubClient client(espClient);

// ---------- DEFINE VARIABLES ----------

const char* ssid = “”; // WLAN-SSID (WiFi router)
const char* password = “”; // WLAN Password

// Define a datatype to store the mqtt message, up to 50 bytes.
char msg[50]; // 50 BYTES QUIZAS SEA MUCHO AL GAS, pero bueh

// -------------------- SETUP -------------------

void setup() {

// Initialize serial monitor for debugging purposes.
Serial.begin(9600);
Serial.println("DEBUG: Entering setup ");

// Attempt to connect to WiFi.
WiFi.begin(ssid, password);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println(""); // Faltaria agregar que muestre el ip si no es estatico
Serial.println(“WiFi connected”);
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
// Initialize MQTT PubSub Library
client.setServer(MQTT_SERVER, MQTT_SERVERPORT);
// Function called in case of an incomming mqtt message from Cayenne Dashboard
// (In this case is the dashboard button to turn on/off the heater)
client.setCallback(mqttCallback);

Serial.println("DEBUG: Setup Done! ");

}

// -------------------- LOOOP -------------------

void loop() {
// Check if the esp8266 is connected to the mqtt server.
if (!client.connected()) {
reconnect();
}

// If connected, perform PubSubClient housekeeping function.
client.loop();
delay(500);
}

// ------------------------------ OTHER FUNCTIONS

// Function that attempts to reconnect to the mqtt server.

void reconnect() {
// If esp8266 is disconnected from the mqtt server, try to reconnect.
// (*** I still need to think what wil happen to the boiler if connection is lost ***)
while (!client.connected()) {
Serial.print(“DEBUG: Attempting MQTT connection…”);

// Attempt to connect
if (client.connect(CLIENT_ID, MQTT_USERNAME, MQTT_PASSWORD)) {
  Serial.println("connected");

  // Once connected, resubscribe to the Dashboard on/off button topic.
  client.subscribe(MQTT_TOPIC_BTN_ONOFF);

} else {
  Serial.print("failed, rc=");
  Serial.print(client.state());
  Serial.println(" try again in 5 seconds");
  // Wait 5 seconds before retrying
  delay(5000);
}

}
Serial.println("DEBUG: Quiting reconnect loop ");
}

// Function to intercept MQTT messages

void mqttCallback(char* topic, byte* payload, unsigned int length) {
Serial.print(“Message arrived [”);
Serial.print(topic);
Serial.print("] ");
for (int i = 0; i < length; i++) {
// Show the received message “stream” in the serial monitor.
Serial.print((char)payload[i]);
}
Serial.println();
// Delay for debugging purposes. If a message arrives from Cayenne, the terminal feed pauses 5’.
delay(5000);
}

nulla…sempre lo stesso errore

have you used two separate client_id here?

certo

try this code and see if you can connect atleast. https://github.com/spacefolder/esp8266-MQTT-v1/blob/master/esp8266-MQTT-v1.cpp

stesso errore "DEBUG: Attempting MQTT connection…failed, rc=-1 try again in 5 seconds
"

can you atleast connect using the cayenne library? https://github.com/myDevicesIoT/Cayenne-MQTT-Arduino/blob/master/examples/Connections/ESP8266/ESP8266.ino