Error compiling for board arduino

combine two sketches (with help thanks) both sketches compile fine but new combined sketch i get error compiling for board arduino uno . The error message appears to have something to do with cayenne ethernet mqtt multiple libraries were found .
I will post error message and then my sketch below

Arduino: 1.8.3 (Windows 7), Board: “Arduino/Genuino Uno”

In file included from C:\Users\Home Laptop\Documents\Arduino\libraries\CayenneMQTT\src/CayenneArduinoDefines.h:128:0,

             from C:\Users\Home Laptop\Documents\Arduino\libraries\CayenneMQTT\src/CayenneArduinoMQTTClient.h:21,

             from C:\Users\Home Laptop\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTEthernetClient.h:21,

             from C:\Users\Home Laptop\Documents\Arduino\libraries\CayenneMQTT\src/CayenneMQTTEthernetW5500.h:25,

             from C:\Users\Home Laptop\Documents\Arduino\xoxoxo\xoxoxo.ino\xoxoxo.ino.ino:6:

C:\Users\Home Laptop\Documents\Arduino\xoxoxo\xoxoxo.ino\xoxoxo.ino.ino: In function ‘void OutputHandler4(Request&)’:

C:\Users\Home Laptop\Documents\Arduino\libraries\CayenneMQTT\src/CayenneHandlers.h:69:37: error: redefinition of ‘void OutputHandler4(Request&)’

#define CAYENNE_OUT_2(channel) void OutputHandler ## channel (Request& request)

                                 ^

C:\Users\Home Laptop\Documents\Arduino\libraries\CayenneMQTT\src/CayenneHandlers.h:71:30: note: in expansion of macro ‘CAYENNE_OUT_2’

#define CAYENNE_OUT(channel) CAYENNE_OUT_2(channel)

                          ^

C:\Users\Home Laptop\Documents\Arduino\xoxoxo\xoxoxo.ino\xoxoxo.ino.ino:86:1: note: in expansion of macro ‘CAYENNE_OUT’

CAYENNE_OUT(VIRTUAL_CHANNEL4)

^

C:\Users\Home Laptop\Documents\Arduino\libraries\CayenneMQTT\src/CayenneHandlers.h:69:37: note: ‘void OutputHandler4(Request&)’ previously defined here

#define CAYENNE_OUT_2(channel) void OutputHandler ## channel (Request& request)

                                 ^

C:\Users\Home Laptop\Documents\Arduino\libraries\CayenneMQTT\src/CayenneHandlers.h:71:30: note: in expansion of macro ‘CAYENNE_OUT_2’

#define CAYENNE_OUT(channel) CAYENNE_OUT_2(channel)

                          ^

C:\Users\Home Laptop\Documents\Arduino\xoxoxo\xoxoxo.ino\xoxoxo.ino.ino:59:1: note: in expansion of macro ‘CAYENNE_OUT’

CAYENNE_OUT(VIRTUAL_CHANNEL6)

^

Multiple libraries were found for “CayenneMQTTEthernetW5500.h”
Used: C:\Users\Home Laptop\Documents\Arduino\libraries\CayenneMQTT
Not used: C:\Users\Home Laptop\Documents\Arduino\libraries\Cayenne-MQTT-Arduino-master
Not used: C:\Users\Home Laptop\Documents\Arduino\libraries\Cayenne-MQTT-Arduino-master
Not used: C:\Users\Home Laptop\Documents\Arduino\libraries\Cayenne-MQTT-Arduino-master
Not used: C:\Users\Home Laptop\Documents\Arduino\libraries\Cayenne-MQTT-Arduino-master
exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

 // This example shows how to connect to Cayenne using an Ethernet W5100 shield and send/receive sample data.

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
//#include <CayenneMQTTEthernet.h>
#include <CayenneMQTTEthernetW5500.h>
 #include <OneWire.h>
#include <DallasTemperature.h>
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "MQTT_USERNAME";
char password[] = "MQTT_PASSWORD";
char clientID[] = "CLIENT_ID";

unsigned long lastMillis = 0;

#define SENSOR_PIN0 A0
#define VIRTUAL_CHANNEL1 1
#define SENSOR_PIN1 A1
#define VIRTUAL_CHANNEL2 2
#define SENSOR_PIN2 A2
#define VIRTUAL_CHANNEL3 3
#define SENSOR_PIN3 A3
#define VIRTUAL_CHANNEL4 4
#define VIRTUAL_CHANNEL5 5
#define VIRTUAL_CHANNEL6 4


// Digital pin the DS18B20 is connected to. Do not use digital pins 0 or 1 since those conflict with the use of Serial.
const int tmpPin6 = 6;
const int tmpPin5 = 5;

OneWire oneWire6(tmpPin6);
OneWire oneWire5(tmpPin5 );  
DallasTemperature sensors6(&oneWire6);
DallasTemperature sensors5(&oneWire5);

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

void loop()
{
  Cayenne.loop();
}
  // This function is called at intervals to send sensor data to Cayenne.
CAYENNE_OUT(VIRTUAL_CHANNEL5)
{
  // Send the command to get temperatures.
  sensors5.requestTemperatures();
  // This command writes the temperature in Celsius to the Virtual Channel.
  //Cayenne.celsiusWrite(VIRTUAL_CHANNEL, sensors5.getTempCByIndex(0));
  // To send the temperature in Fahrenheit use the corresponding code below.
  Cayenne.fahrenheitWrite(VIRTUAL_CHANNEL5, sensors5.getTempFByIndex(0));
}  
CAYENNE_OUT(VIRTUAL_CHANNEL6) 
{
    // Send the command to get temperatures.
  sensors6.requestTemperatures();
  // This command writes the temperature in Celsius to the Virtual Channel.
  //Cayenne.celsiusWrite(VIRTUAL_CHANNEL, sensors6.getTempCByIndex(0));
  // To send the temperature in Fahrenheit use the corresponding code below.
  Cayenne.fahrenheitWrite(VIRTUAL_CHANNEL6, sensors6.getTempFByIndex(0)); 
  
}
// This function is called at intervals to send sensor data to Cayenne.
CAYENNE_OUT(VIRTUAL_CHANNEL1)
{
  Cayenne.virtualWrite(VIRTUAL_CHANNEL1, analogRead(SENSOR_PIN0));
}
//This function is called at intervals to send sensor datato Cayenne.
CAYENNE_OUT(VIRTUAL_CHANNEL2)
{
  Cayenne.virtualWrite(VIRTUAL_CHANNEL2, analogRead(SENSOR_PIN1));
} 
  //This function is called at intervals to send sensor datato Cayenne.
CAYENNE_OUT(VIRTUAL_CHANNEL3)
{
  Cayenne.virtualWrite(VIRTUAL_CHANNEL3, analogRead(SENSOR_PIN2));
}

  // This function is called at intervals to send sensor data to Cayenne.
CAYENNE_OUT(VIRTUAL_CHANNEL4)
{
   Cayenne.virtualWrite(VIRTUAL_CHANNEL4, analogRead(SENSOR_PIN3));
  
}

there is an bug in this. tagging @jcruz and @bestes for this.

I see a couple issues. One is that this line:

#define VIRTUAL_CHANNEL6 4

should be

#define VIRTUAL_CHANNEL6 6

otherwise it will conflict with the previously defined channel 4.

Also it appears you have two versions of the Cayenne MQTT library installed. One at C:\Users\Home Laptop\Documents\Arduino\libraries\CayenneMQTT that was probably installed via the Arduino Library Manager and one at C:\Users\Home Laptop\Documents\Arduino\libraries\Cayenne-MQTT-Arduino-master that was probably installed manually. This causes issues for the Arduino IDE so you should remove the Cayenne-MQTT-Arduino-master library folder then restart the Arduino IDE and try to compile the sketch again.

1 Like