Conflict between 2 included library files

My project is using a NodeMCU programmed via Arduino IDE to post sensor data to google spreadsheet and also to trigger an IFTTT webhook if a certain event occurs. I have succeeded in accomplishing these 2 objectives using 2 separate sketches. However, when trying to merge these 2 functions into one sketch to upload to NodeMCU the compile fails with the following error log:

In file included from C:\Users\hosey\Documents\Arduino\TestOnceOnlyLoopV4\TestOnceOnlyLoopV4.ino:6:0:
C:\Users\hosey\Documents\Arduino\libraries\AnotherIFTTTWebhook-master/AnotherIFTTTWebhook.h:38:12: error: conflicting declaration 'WiFiClient client'
WiFiClient client;

  • ^*
    In file included from C:\Users\hosey\Documents\Arduino\TestOnceOnlyLoopV4\TestOnceOnlyLoopV4.ino:4:0:
    C:\Users\hosey\Documents\Arduino\libraries\TRIGGER_WIFI/TRIGGER_WIFI.h:11:18: error: 'client' has a previous declaration as 'BearSSL::WiFiClientSecure client'
    WiFiClientSecure client;
  • ^*
    Using library TRIGGER_WIFI in folder: C:\Users\hosey\Documents\Arduino\libraries\TRIGGER_WIFI (legacy)
    Using library ESP8266WiFi at version 1.0 in folder: C:\Users\hosey\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WiFi
    Using library TRIGGER_GOOGLESHEETS in folder: C:\Users\hosey\Documents\Arduino\libraries\TRIGGER_GOOGLESHEETS (legacy)
    Using library AnotherIFTTTWebhook-master in folder: C:\Users\hosey\Documents\Arduino\libraries\AnotherIFTTTWebhook-master (legacy)
    Using library DHT_sensor_library at version 1.3.7 in folder: C:\Users\hosey\Documents\Arduino\libraries\DHT_sensor_library
    Using library Adafruit_Unified_Sensor at version 1.0.3 in folder: C:\Users\hosey\Documents\Arduino\libraries\Adafruit_Unified_Sensor
    exit status 1
    Error compiling for board NodeMCU 1.0 (ESP-12E Module).

The problem seems to center around "WiFiClient client" used in AnotherIFTTTWebhook.h and "WiFiClientSecure client" used in TRIGGER_WIFI.h.

These libraries were probably intended to be used only for the single purpose each sketch provided, one to trigger IFTTT webhook and the other to post data to google spreadsheet. Each sketch included calls to wifi function to establish secure connections and when merged they conflict. I'm not skilled at coding and haven't the knowledge to fix the problem alone. If anyone can point me in the right direction it would be much appreciated.

If this is not the best forum to post this message please let me know.

Thanks

You need to post the two separate programs and your best attempt at the merged program.

It may be that when you merged the code you have include duplicates of some lines of code where only one of them is required.

On the other hand it would not be surprising to discover that two libraries are incompatible.

...R

Thanks for the reply and advice Robin2. My apologies for incomplete information.
To recap, my goal is to use one sketch to post data to google spreadsheet on Google Drive and also to trigger an IFTTT webhook. I will post the 2 standalone sketches which work and the sketch which merged the 2 functions which failed to compile along with the error messages.

Here are the links to the external libraries used:
https://github.com/NishantSahay7/Nodemcu-to-Google-Sheets
https://github.com/Siytek/AnotherIFTTTWebhook

IFTTT working sketch

#include <ESP8266WiFi.h>
#include <AnotherIFTTTWebhook.h>
#define IFTTT_Key "xyxyxyxyxyxy"
#define IFTTT_Event "Send_SMS"

const char* ssid = "xkxkxkxkxk";
const char* password = "12498ggg";

int IfTrig = 2;
int LstTrig = 1;
int CurTrig;
unsigned long CurrentTime;
unsigned long PreviousTime1;
unsigned long PreviousTime2;
unsigned long IntervalTime1 = 10000; // 10 Seconds
unsigned long IntervalTime2 = 20000; // 20 Seconds

void setup() {
  pinMode(IfTrig, INPUT_PULLUP);
  Serial.begin(9600);

  Serial.print("Connecting to: SSID NAME");
  WiFi.begin(ssid, password);
  Serial.println(" ");
  Serial.print("Attempting to connect: ");
  int i = 10;
  while (WiFi.status() != WL_CONNECTED && i >= 0) {
    delay(1000);
    Serial.print(i);
    Serial.print(", ");
    i--;
  }
  Serial.println(" ");

  if (WiFi.status() == WL_CONNECTED) {
    Serial.print("Connected.");
    Serial.println(" ");// print an empty line
    Serial.print("NodeMCU ip address: ");
    Serial.println(WiFi.localIP());
  }
  else {
    Serial.println("Connection failed - check your credentials or connection");
  }

}

void loop() {
  CurrentTime = millis();
  if (CurrentTime - PreviousTime1 > IntervalTime1) {
    CurTrig = digitalRead(IfTrig);
    Serial.print("CurTrig = ");
    Serial.print(CurTrig);
    Serial.println();
    Serial.print("LstTrig = ");
    Serial.print(LstTrig);
    Serial.println();
    if (CurTrig == 0 && LstTrig == 1) {
      Serial.println("Send IFTTT request");
      Serial.println();
      send_webhook(IFTTT_Event, IFTTT_Key, "value1", "value2", "value3");
    }

    LstTrig = digitalRead(IfTrig);
    PreviousTime1 = millis();
  }
}

Google Sheet working sketch

#include "TRIGGER_WIFI.h"               /*Includes ESP8266WiFi.h and WiFiClientSecure.h, just have these two libraries downloaded before*/
#include "TRIGGER_GOOGLESHEETS.h"       /*Library file for Google Sheets, has to be used after Wi-Fi Client Secure declaration, here everything is in Trigger_WIFI.h, so using it after Trigger_WIFI.h*/

/**********Google Sheets Definations***********/
char column_name_in_sheets[ ][20] = {"value1", "value2", "value3"};  /*1. The Total no of column depends on how many value you have created in Script of Sheets;2. It has to be in order as per the rows decided in google sheets*/
String Sheets_GAS_ID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";          /*This is the Sheets GAS ID, you need to look for your sheets id*/
int No_of_Parameters = 3;                                            /*Here No_of_Parameters decides how many parameters you want to send it to Google Sheets at once, change it according to your needs*/
/*********************************************/

void setup()
{
  Serial.begin(9600);
  while (!Serial);

  WIFI_Connect("xoxoxoxo", "xoxoxoxo");                                        /*Provide you Wi-Fi SSID and password to connect to Wi-Fi*/
  Google_Sheets_Init(column_name_in_sheets, Sheets_GAS_ID, No_of_Parameters ); /*Sets the column name for Google Sheets, the GAS ID, and the No of Parameter we want to send*/
}

void loop()
{
  float a = 1, b = 2, c = 3;                           /*Demo values that has to be sent to google sheets, you can use sensor values*/

  Data_to_Sheets(No_of_Parameters,  a,  b, c);         /*1. This function accepts multiple float parameter, here No_of_Parameters decides how many parameters you want to send to Google Sheets; 2. The values sent should be in order as per the column in Google Sheets*/

  Serial.println();
  delay(10000);                                       /*10 Sec Delay, Here 10 second delay is just used so that we can see the data pushed to sheets one by one
                                                        There is nothing like a minimum delay between two data push*/
}

Google + IFTTT sketch which failed to compile

#include <TRIGGER_WIFI.h>               /*Includes ESP8266WiFi.h and WiFiClientSecure.h, just have these two libraries downloaded before*/
#include <TRIGGER_GOOGLESHEETS.h>       /*Library file for Google Sheets, has to be used after Wi-Fi Client Secure declaration, here everything is in Trigger_WIFI.h, so using it after Trigger_WIFI.h*/
#include <AnotherIFTTTWebhook.h>
#include <DHT.h>    // including the library of DHT11 temperature and humidity sensor
#define IFTTT_Key "xxxxxxxxxx"
#define IFTTT_Event "Send_SMS"
#define DHTTYPE DHT11   // DHT 11
#define dht_dpin 0
float TempF;
float Humidity;
int IfTrig = 2;
int LstTrig = 1;
int CurTrig;
unsigned long CurrentTime;
unsigned long PreviousTime1;
unsigned long PreviousTime2;
unsigned long IntervalTime1 = 10000; // 10 Seconds
unsigned long IntervalTime2 = 20000; // 20 Seconds
DHT dht(dht_dpin, DHTTYPE);
/**********Google Sheets Definations***********/
char column_name_in_sheets[ ][20] = {"value1", "value2", "value3"};                      /*1. The Total no of column depends on how many value you have created in Script of Sheets;2. It has to be in order as per the rows decided in google sheets*/
String Sheets_GAS_ID = "xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy";                                         /*This is the Sheets GAS ID, you need to look for your sheets id*/
int No_of_Parameters = 3;                                                                /*Here No_of_Parameters decides how many parameters you want to send it to Google Sheets at once, change it according to your needs*/
/*********************************************/

void setup() {
  dht.begin();
  pinMode(IfTrig, INPUT_PULLUP);
  Serial.begin(9600);
  while (!Serial);
  //Provide your Wi-Fi SSID and password to connect to Wi-Fi
  WIFI_Connect("SSID", "Password");
  //Sets the column name for Google Sheets, the GAS ID, and the No of Parameter we want to send
  Google_Sheets_Init(column_name_in_sheets, Sheets_GAS_ID, No_of_Parameters );

}

void loop() {
  CurrentTime = millis();
  if (CurrentTime - PreviousTime1 > IntervalTime1) {
    CurTrig = digitalRead(IfTrig);
    Serial.print("CurTrig = ");
    Serial.print(CurTrig);
    Serial.println();
    Serial.print("LstTrig = ");
    Serial.print(LstTrig);
    Serial.println();
    if (CurTrig == 0 && LstTrig == 1) {
      Serial.println("Send IFTTT request");
      Serial.println();
      Serial.println();
      send_webhook(IFTTT_Event, IFTTT_Key, "AnotherIFTTT", "ESP device", "Webhook");
      // Read Temperature and Humidity
      Humidity = dht.readHumidity();
      TempF = dht.readTemperature(true);
      Serial.print("Current humidity = ");
      Serial.print(Humidity);
      Serial.print("%  ");
      Serial.print("temperature = ");
      Serial.print(TempF);
      Serial.println("F  ");
    }

    LstTrig = digitalRead(IfTrig);
    PreviousTime1 = millis();
  }
  if (CurrentTime - PreviousTime2 > IntervalTime2) {
    float c = (TempF - 32) / 1.8;
    //1. This function accepts multiple float parameter, here No_of_Parameters decides how many parameters you want to send to Google Sheets; 2. The values sent should be in order as per the column in Google Sheets
    Data_to_Sheets(No_of_Parameters,  TempF,  Humidity, c);
    Serial.println();
    PreviousTime2 = millis();
  }

}

Error message on failed compile:

Arduino: 1.8.9 (Windows 10), Board: “NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200”

In file included from C:\Users\hosey\Documents\Arduino\Forum\IFTTT-Google_Test\IFTTT-Google_Test.ino:5:0:

C:\Users\hosey\Documents\Arduino\libraries\AnotherIFTTTWebhook-master/AnotherIFTTTWebhook.h:38:12: error: conflicting declaration ‘WiFiClient client’

WiFiClient client;

^

In file included from C:\Users\hosey\Documents\Arduino\Forum\IFTTT-Google_Test\IFTTT-Google_Test.ino:3:0:

C:\Users\hosey\Documents\Arduino\libraries\TRIGGER_WIFI/TRIGGER_WIFI.h:11:18: error: ‘client’ has a previous declaration as ‘BearSSL::WiFiClientSecure client’

WiFiClientSecure client;

^

exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).

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

It looks as if both libraries are trying to use the same instance name and I suspect the only solution is to edit one the libraries to make it use a different name. The problem is that the instance might be referred to in several places in the library code and all the references would need to be changed.

Another thought which might be simpler (though I know very little about ESP8266 WiFi) might be to comment out the WiFiClient client; line in the second library in the hope that its code could also use the client instance created by the other library. I suspect this is rather unlikely but it would be quick to try.

Hopefully someone who knows more about ESP8266 WiFi will come to your assistance.

...R

Thanks again Robin2 for your input.
The problem was solved but not by resolving the conflict between the 2 libraries. Research revealed that this problem exists and that there doesn’t seem to be an easy resolution. IFTTT webhook uses wifi.client connection and Google sheets requires wifi.clientsecure connection. Apparently combining these in a single sketch is not easily done or may even be impossible.

My solution turned out to be easy. I used a trigger to IFTTT webhook applet which then sends data included in the webhook request to populate a Google sheet. Different webhook applets may be triggered from within the sketch to populate the google sheet and then send an email.

One thing discovered which may be useful to the community is that the value fields in an IFTTT webhook must be a string type. So if the data to be sent is a a float type for instance, it must first be converted to a string. I accomplished this with the dtostrf function included in stdlib.h. The following code snippet indicates the general method to do this minus network connection, etc. Hope this might help someone.

#include <AnotherIFTTTWebhook.h>
#include <stdlib.h>
#include <DHT.h>    // including the library of DHT11 temperature and humidity sensor
char TempFStr[9];
TempF = dht.readTemperature(true);
dtostrf(TempF, 7, 2, TempFStr);
send_webhook(IFTTT_Event,IFTTT_Key,TempFStr);