ESP32 - Cayenne was not found- WiFi library issued

Dear All,

I am trying to connect an ESP32 board to Cayene throuhy CAYENNE_OUT function using wifi as the connection below (code below).

I constant get the “‘Cayenne’ was not declared in this scope” message and I am using a TTGO LoRa ESP32 board set as ESP32 dev board in the boards manager.

I have noticed that by trying different board types as well as Cayene MQTT libraries, I get different error messages that mainly point to WiFi library problems.

Has anyone come across the same issues?

Thank you

#include <LoRa.lyh>
//#include "SSD1306.h"

#include <Arduino.h>
//#include <CayenneArduinoDefines.h>
//#include <CayenneMQTTWiFi.h>
//#include <CayenneMQTTESP32.h>


#include <SPI.h>
//#include <WiFi.h>

//Libraries for OLED Display
#include <Wire.h>
#include <Adafruit_GFX.h>
//#include <Adafruit_SSD1306.h>


#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial


#define VIRTUAL_CHANNEL 5
 

char ssid[] = "";
char wifiPassword[]="s";

char username[] = "";
char mqtt_password[] = "";
char clientID[] = "";
 
//SSD1306  display(0x3c, 4, 15);
 
//OLED pins to ESP32 GPIOs via this connection:
//OLED_SDA -- GPIO4
//OLED_SCL -- GPIO15
//OLED_RST -- GPIO16
// WIFI_LoRa_32 ports
// GPIO5  -- SX1278's SCK
// GPIO19 -- SX1278's MISO
// GPIO27 -- SX1278's MOSI
// GPIO18 -- SX1278's CS
// GPIO14 -- SX1278's RESET
// GPIO26 -- SX1278's IRQ(Interrupt Request)
 
#define SS      18
#define RST     14
#define DI0     26
#define BAND    868E6

//float data;

String data = "";
int rssi = LoRa.packetRssi();

#define BUTTON_PIN_BITMASK 0x200000000 // 2^33 in hex

RTC_DATA_ATTR int bootCount = 0;

/*
Method to print the reason by which ESP32
has been awaken from sleep
*/
void print_wakeup_reason(){
  esp_sleep_wakeup_cause_t wakeup_reason;

  wakeup_reason = esp_sleep_get_wakeup_cause();

  switch(wakeup_reason)
  {
    case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break;
    case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
    case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break;
    case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break;
    case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break;
    default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break;
  }
}
 
void setup() {

  Cayenne.begin(username, mqtt_password, clientID, ssid, wifiPassword);

  
  pinMode(16,OUTPUT);
  digitalWrite(16, LOW);    // set GPIO16 low to reset OLED
  delay(50); 
  digitalWrite(16, HIGH);
//  display.init();
//  display.flipScreenVertically();
//  display.setFont(ArialMT_Plain_10);
//  display.setTextAlignment(TEXT_ALIGN_LEFT);
   
  Serial.begin(115200);
  while (!Serial); //if just the the basic function, must connect to a computer
  delay(1000);
  Serial.println("LoRa Receiver"); 
//  display.drawString(5,5,"LoRa Receiver"); 
//  display.display();
//  SPI.begin(5,19,27,18);
  LoRa.setPins(SS,RST,DI0);
   
  if (!LoRa.begin(BAND)) {
   // display.drawString(5,25,"Starting LoRa failed!");
    while (1);
  }
  Serial.println("LoRa Initial OK!");
//  display.drawString(5,25,"LoRa Initializing OK!");
//  display.display();

delay(1000); //Take some time to open up the Serial Monitor

  //Increment boot number and print it every reboot
  ++bootCount;
  Serial.println("Boot number: " + String(bootCount));

  //Print the wakeup reason for ESP32
  print_wakeup_reason();
 
  
  esp_sleep_enable_ext0_wakeup(GPIO_NUM_33,1); //1 = High, 0 = Low


  );

  //Go to sleep now
  //Serial.println("Going to sleep now");
  //delay(1000);
  //esp_deep_sleep_start();
  //Serial.println("This will never be printed");
}








void loop() {

//  Cayenne.loop();

  
  // try to parse packet
  int packetSize = LoRa.parsePacket();
  

  String data = "";



  if (packetSize) {
    // received a packets
    
    Serial.println("Received packet. ");
    //display.clear();
   
    //display.setFont(ArialMT_Plain_16);
    
    //display.drawString(20, 5, "Received packet value:  ");
    Serial.println("Received packet value:  ");
   
//    display.display();
   

    
    // read packet
    while (LoRa.available()) {   
            
      data = LoRa.readString();     
           
      //String data = String(LoRa.read());

      //Serial.print((char)LoRa.read());
            
     Serial.println(data);
     
    //Serial.print("kitsos");
    
  //  display.drawString(20,22, data);
    
  //  display.display();
}
    // print RSSI of packet
    Serial.print(" with RSSI ");
       Serial.println(LoRa.packetRssi());
        //display.drawString(20, 45, "RSSI:  ");
               String rssi = String(LoRa.packetRssi());
        //display.drawString(70, 45, String (LoRa.packetRssi());
                      
        
               //display.drawString(70, 45, String(rssi));
    //display.display();



     

 //Go to sleep now
  Serial.println("Going to sleep now");
  delay(1000);
  esp_deep_sleep_start();
  Serial.println("This will never be printed");
}
  }

  

// This function is called at intervals to send data to Cayenne.
CAYENNE_OUT(VIRTUAL_CHANNEL)
{
  //CAYENNE_LOG("Send data for Virtual Channel %d", VIRTUAL_CHANNEL);
  // This command writes the device's uptime in seconds to the Virtual Channel.
 //Cayenne.virtualWrite(VIRTUAL_CHANNEL, data);
}

can you try this code and see if it works Cayenne-MQTT-Arduino/ESP32.ino at master · myDevicesIoT/Cayenne-MQTT-Arduino · GitHub

Hi,

I did copy the code in the code I pasted above with no luck I am afraid. Which board type should I set

can you share a link to which board are you using.

it should work, can you share the error you are you getting for the basic sketch i shared above.

LORA_RECEIVER:223:12: error: expected constructor, destructor, or type conversion before ‘(’ token

CAYENNE_OUT(VIRTUAL_CHANNEL)

        ^

exit status 1
‘Cayenne’ was not declared in this scope

can you try the basic code from the link i shared above. that should solve the issue. The code you are using is missing } somewhere.

Hi,

Didi try it and got the following message

Multiple libraries were found for “WiFi.h”
Used: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.33.0_x86__mdqgnx93n4wtt\libraries\WiFi
Not used: C:\Users\xcxxx\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.4\libraries\2WiFi
exit status 1
Error compiling for board ESP32 Dev Module.

you have not selected the correct board,

I have tried sevearl but I end up with the same problems in conjunction with the cayenne.loop() function.

If I do not use the cayenne code the board compiles with no issues at all.

check whether this works for you:

#include <WiFi.h>

const char* ssid     = "your-ssid";
const char* password = "your-password";


void setup()
{
    Serial.begin(115200);
    delay(10);

    // We start by connecting to a WiFi network

    Serial.println();
    Serial.println();
    Serial.print("Connecting to ");
    Serial.println(ssid);

    WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }

    Serial.println("");
    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
}

Did try it with minor changes and gor similar error messages:

ore\core.a(main.cpp.o): In function `loopTask(void*)':

C:\Users\Spiros\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.4\cores\esp32/main.cpp:17: undefined reference to `loop()’

collect2.exe: error: ld returned 1 exit status

Multiple libraries were found for “WiFi.h”
Used: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.33.0_x86__mdqgnx93n4wtt\libraries\WiFi
Not used: C:\Users\xxxx\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.4\libraries\2WiFi
exit status 1
Error compiling for board ESP32 Dev Module.

can you remove all files related to “wifi.h” from your arduino library folder. Once done go to arduino ide —> preferences and add https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json in Additional board manager url. Next go to tools —> boards → boards manger and let it add the new esp32 package. Try now and it should hopefully work.

Thank you for the ESP32 info.

We got closer to a solution but there is still a conflict with WiFi library. The message received is:

Multiple libraries were found for “WiFi.h”
Used: C:\Users\xxxx\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi
Not used: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.33.0_x86__mdqgnx93n4wtt\libraries\WiFi
exit status 1
Error compiling for board ESP32 Dev Module.

can you join me on slack http://slack.mydevices.com/

Just did,

Sent a pm as well :slight_smile:

Iot Rookie is the name