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);
}