Variable or field 'writeFile' declared void ESP32 CAM

Hi there,

I'm building an ESP32 Cam PIR Telegram using a mixture of Rui Santos's and Brian Lough's code.

I have added extra features as I discover more like Telegram app buttons to request temp, humidity, battery voltage etc. This is all working fine and I have impressed my self with getting this far!

I would like to now add data logging of the battery voltage using the onboard SD card slot on the ESP32 Cam module. I have trimmed Rui Santos's ESP32 (not cam) SD card example code down and managed to get it compiled and working on the my ESP32 Cam writing an int to the SD card. Code here.....


#include "FS.h"
#include "SD_MMC.h"

unsigned long aNumberIncreasingByOne = 100;

String dataMessage;

int readingID = 0;


void setup() {
  Serial.begin(115200);
  Serial.println("SDcard Testing....");

  if (!SD_MMC.begin()) {
    Serial.println("Card Mount Failed");
    return;
  }
  uint8_t cardType = SD_MMC.cardType();

  if (cardType == CARD_NONE) {
    Serial.println("No SD_MMC card attached");
    return;
  }

  Serial.print("SD_MMC Card Type: ");
  if (cardType == CARD_MMC) {
    Serial.println("MMC");
  } else if (cardType == CARD_SD) {
    Serial.println("SDSC");
  } else if (cardType == CARD_SDHC) {
    Serial.println("SDHC");
  } else {
    Serial.println("UNKNOWN");
  }

  uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024);
  Serial.printf("SD_MMC Card Size: %lluMB\n", cardSize);


  writeFile(SD_MMC, "/data.txt", "Hello ");

}



void loop() {

  dataMessage = String(readingID) + " )  " + String(aNumberIncreasingByOne) + "\r\n";
  Serial.print("Save data: ");
  Serial.println(dataMessage);
  appendFile(SD_MMC, "/data.txt", dataMessage.c_str());

  delay(1000);

  readingID++;
  Serial.println(readingID);

  aNumberIncreasingByOne++;

}



//Write a file in SD card
void writeFile(fs::FS &fs, const char * path, const char * message) {
  Serial.printf("Writing file: %s\n", path);

  File file = fs.open(path, FILE_WRITE);
  if (!file) {
    Serial.println("Failed to open file for writing");
    return;
  }


  //fwrite(fb->buf, 1, fb->len, file);
  if (file.print(message)) {
    Serial.println("File written");
  } else {
    Serial.println("Write failed");
  }
}



//Append to the end of file in SD card
void appendFile(fs::FS &fs, const char * path, const char * message) {
  Serial.printf("Appending to file: %s\n", path);

  File file = fs.open(path, FILE_APPEND);
  if (!file) {
    Serial.println("Failed to open file for appending");
    return;
  }
  if (file.print(message)) {
    Serial.println("Message appended");
  } else {
    Serial.println("Append failed");
  }
}



I am now trying to incorporate this code into my ESP32 Cam PIR Telegram code an am getting the compiling error "variable or field 'writeFile' declared void"

In the loop I will be calling a read of the battery voltage every 3 second then a writeFile to the on board SD card on the ESP32 Cam. Currently it is set up to just write readingID and aNumberIncreasingByOne. The relevant handlers are just below the loop FYi. Code here.......


/*

  to do
  1 PIR ON/OFF buttons                        ***DONE***
  2 ON Reminder                               ***DONE***
  3 Photoresistor PIR pic with flash no flash
  4 Take pic with flash no flash buttons      ***DONE***
  5 Low battery message @3.1v
  6 Light timeout                             ***DONE***
  7 Initial on LED                            ***Done***
  8 SD card read battery
  9 Brown out cap

  Notes

  Single cell PSU flashes @3.25v multimeter == 3.1v analog
  Single cell PSU flashes @2.95v multimeter == 2.82v analog
  Last indicator light on PSU flashes @  3.1v analog
  Still flashing @  2.86v analog
  Dropped out @  2.84v analog

*/

#include <Adafruit_ADS1015.h>

Adafruit_ADS1115 ads(0x48);
float battVoltage = 0.0;
float Light = 0.0;

int16_t adc0;
int16_t adc1;


int wifiWarningLed = 2;


#include <WiFi.h>
#include <WiFiClientSecure.h>
#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"
#include "esp_camera.h"
#include <UniversalTelegramBot.h>
#include <ArduinoJson.h>
#include <Wire.h>
#include "SparkFunBME280.h"

// Replace with your network credentials
const char* ssid = "WHATEVER";
const char* password = "WHATEVER";

// Use @myidbot to find out the chat ID of an individual or a group
// Also note that you need to click "start" on a bot before it can
// message you
String chatId = "WHATEVER";

// Initialize Telegram BOT
String BOTtoken = "WHATEVER";   //BARN   PiR CAM 1

bool sendPhoto = false;

WiFiClientSecure clientTCP;

UniversalTelegramBot bot(BOTtoken, clientTCP);

//CAMERA_MODEL_AI_THINKER
#define PWDN_GPIO_NUM     32
#define RESET_GPIO_NUM    -1
#define XCLK_GPIO_NUM      0
#define SIOD_GPIO_NUM     26
#define SIOC_GPIO_NUM     27

#define Y9_GPIO_NUM       35
#define Y8_GPIO_NUM       34
#define Y7_GPIO_NUM       39
#define Y6_GPIO_NUM       36
#define Y5_GPIO_NUM       21
#define Y4_GPIO_NUM       19
#define Y3_GPIO_NUM       18
#define Y2_GPIO_NUM        5
#define VSYNC_GPIO_NUM    25
#define HREF_GPIO_NUM     23
#define PCLK_GPIO_NUM     22

#define FLASH_LED_PIN 4


// Motion Sensor
bool motionDetected = false;

// Define I2C Pins for BME280
#define I2C_SDA 14
#define I2C_SCL 15

BME280 bme;

int botRequestDelay = 1000;   // mean time between scan messages
long lastTimeBotRan;     // last time messages' scan has been done

void handleNewMessages(int numNewMessages);
String sendPhotoTelegram();


// Indicates when motion is detected
static void IRAM_ATTR detectsMovement(void * arg) {
  //Serial.println("MOTION DETECTED!!!");
  motionDetected = true;
}

bool pirActive = true;

unsigned long previousReminderMillis = 0;
const long reminderInterval = 1800000;      // 300,000 = 5mins ,  3,600,000 = 1hour , 1,800,000 = Half hour

int initialPowerUpLed = 12;
const long initialPowerLedDuration = 10000;

bool flashActive = false;

bool lightOn = false;
unsigned long lightOnMillis = 0;
const long lightOnMaxTime = 20000;
bool lightOnMillisTest = true;
unsigned long nowLightOnMillis = 0;


// MicroSD Libraries
#include "FS.h"
#include "SD_MMC.h"

unsigned long aNumberIncreasingByOne = 100;

String dataMessage;

int readingID = 0;

unsigned long sDCardWriteCurrentTime = 0;
const long sDCardWriteInterval = 3000;
unsigned long sDCardWritePreviousTime = 0;



void setup() {

  WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);
  Serial.begin(115200);

  pinMode(FLASH_LED_PIN, OUTPUT);
  digitalWrite(FLASH_LED_PIN, LOW);

  pinMode(wifiWarningLed, OUTPUT);
  pinMode(initialPowerUpLed, OUTPUT);

  digitalWrite(initialPowerUpLed, HIGH);

  // Init BME280 sensor
  Wire.begin(I2C_SDA, I2C_SCL);
  bme.settings.commInterface = I2C_MODE;
  bme.settings.I2CAddress = 0x76;
  bme.settings.runMode = 3;
  bme.settings.tStandby = 0;
  bme.settings.filter = 0;
  bme.settings.tempOverSample = 1;
  bme.settings.pressOverSample = 1;
  bme.settings.humidOverSample = 1;
  bme.begin();

  WiFi.mode(WIFI_STA);
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    digitalWrite(wifiWarningLed, HIGH);
    delay(25);
    digitalWrite(wifiWarningLed, LOW);
    delay(150);
  }

  digitalWrite(wifiWarningLed, LOW);

  Serial.println();
  Serial.print("ESP32-CAM IP Address: ");
  Serial.println(WiFi.localIP());

  camera_config_t config;
  config.ledc_channel = LEDC_CHANNEL_0;
  config.ledc_timer = LEDC_TIMER_0;
  config.pin_d0 = Y2_GPIO_NUM;
  config.pin_d1 = Y3_GPIO_NUM;
  config.pin_d2 = Y4_GPIO_NUM;
  config.pin_d3 = Y5_GPIO_NUM;
  config.pin_d4 = Y6_GPIO_NUM;
  config.pin_d5 = Y7_GPIO_NUM;
  config.pin_d6 = Y8_GPIO_NUM;
  config.pin_d7 = Y9_GPIO_NUM;
  config.pin_xclk = XCLK_GPIO_NUM;
  config.pin_pclk = PCLK_GPIO_NUM;
  config.pin_vsync = VSYNC_GPIO_NUM;
  config.pin_href = HREF_GPIO_NUM;
  config.pin_sscb_sda = SIOD_GPIO_NUM;
  config.pin_sscb_scl = SIOC_GPIO_NUM;
  config.pin_pwdn = PWDN_GPIO_NUM;
  config.pin_reset = RESET_GPIO_NUM;
  config.xclk_freq_hz = 20000000;
  config.pixel_format = PIXFORMAT_JPEG;

  //init with high specs to pre-allocate larger buffers
  if (psramFound()) {
    config.frame_size = FRAMESIZE_UXGA;
    config.jpeg_quality = 10;  //0-63 lower number means higher quality
    config.fb_count = 2;
  } else {
    config.frame_size = FRAMESIZE_SVGA;
    config.jpeg_quality = 12;  //0-63 lower number means higher quality
    config.fb_count = 1;
  }

  // camera init
  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK) {
    Serial.printf("Camera init failed with error 0x%x", err);
    delay(500);
    ESP.restart();
  }

  // Drop down frame size for higher initial frame rate
  sensor_t * s = esp_camera_sensor_get();
  s->set_framesize(s, FRAMESIZE_CIF);  // UXGA|SXGA|XGA|SVGA|VGA|CIF|QVGA|HQVGA|QQVGA

  // PIR Motion Sensor mode INPUT_PULLUP
  //err = gpio_install_isr_service(0);
  err = gpio_isr_handler_add(GPIO_NUM_13, &detectsMovement, (void *) 13);
  if (err != ESP_OK) {
    Serial.printf("handler add failed with error 0x%x \r\n", err);
  }
  err = gpio_set_intr_type(GPIO_NUM_13, GPIO_INTR_POSEDGE);
  if (err != ESP_OK) {
    Serial.printf("set intr type failed with error 0x%x \r\n", err);
  }

  //if (text == "/start") {
  String welcome = "Welcome to BARN PiR CAM 1.\n";
  welcome += "/options : Gives you some buttons\n";

  bot.sendMessage(chatId, welcome, "Markdown");



  Serial.println("SDcard Testing....");

  if (!SD_MMC.begin()) {
    Serial.println("Card Mount Failed");
    return;
  }
  uint8_t cardType = SD_MMC.cardType();

  if (cardType == CARD_NONE) {
    Serial.println("No SD_MMC card attached");
    return;
  }

  Serial.print("SD_MMC Card Type: ");
  if (cardType == CARD_MMC) {
    Serial.println("MMC");
  } else if (cardType == CARD_SD) {
    Serial.println("SDSC");
  } else if (cardType == CARD_SDHC) {
    Serial.println("SDHC");
  } else {
    Serial.println("UNKNOWN");
  }

  uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024);
  Serial.printf("SD_MMC Card Size: %lluMB\n", cardSize);

  writeFile(SD_MMC, "/data.txt", "Hello ");

}




void loop() {

  if (sendPhoto) {
    //Serial.println("Preparing photo");
    sendPhotoTelegram();
    sendPhoto = false;
  }

  if (motionDetected && pirActive == true) {
    //bot.sendMessage(chatId, "Motion detected!!", "");
    //Serial.println("Motion Detected");
    //digitalWrite(FLASH_LED_PIN, HIGH);
    sendPhotoTelegram();
    motionDetected = false;

  }

  if (millis() > lastTimeBotRan + botRequestDelay) {
    int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
    while (numNewMessages) {
      //Serial.println("got response");
      handleNewMessages(numNewMessages);
      numNewMessages = bot.getUpdates(bot.last_message_received + 1);
    }
    lastTimeBotRan = millis();
  }

  adc0 = ads.readADC_SingleEnded(0);
  battVoltage = (adc0 * 0.1875) / 1000;

  adc1 = ads.readADC_SingleEnded(1);
  Light = (adc1 * 0.1875) / 1000;

  //Serial.print("AIN0: ");
  //Serial.print(adc0);
  //Serial.print("\tbattVoltage: ");
  //Serial.print(battVoltage, 7);
  ////Serial.print();
  //
  //Serial.print("    AIN1: ");
  //Serial.print(adc1);
  //Serial.print("\tLight: ");
  //Serial.println(Light, 7);
  //Serial.println();
  //
  //delay(100);


  unsigned long currentMillis = millis();

  if (currentMillis - previousReminderMillis >= reminderInterval) {
    //String onTime = getOnTime();
    //bot.sendMessage(chatId, onTime, "");
    bot.sendMessage(chatId, "SYSTEM ACTIVE REMINDER");
    previousReminderMillis = currentMillis;
  }


  if (millis() > initialPowerLedDuration) {
    digitalWrite(initialPowerUpLed, LOW);
  }


  if (lightOnMillisTest == true) {
    lightOnMillis = millis();
    lightOnMillisTest = false;
  }

  nowLightOnMillis = millis();

  if ((nowLightOnMillis - lightOnMillis >= lightOnMaxTime) && (lightOn == true)) {
    digitalWrite(FLASH_LED_PIN, LOW);
    lightOn = false;
  }


  sDCardWriteCurrentTime = millis();

  if (currentMillis - sDCardWritePreviousTime >= sDCardWriteInterval) {

    Serial.println("HOORAY");

    //dataMessage = String(readingID) + "," + String(dayStamp) + "," + String(timeStamp) + "," + String(temperature) + "\r\n";
    dataMessage = String(readingID) + " )  " + String(aNumberIncreasingByOne) + "\r\n";
    Serial.print("Save data: ");
    Serial.println(dataMessage);
    appendFile(SD_MMC, "/data.txt", dataMessage.c_str());
    //writeFile(SD_MMC, "/data.txt", dataMessage.c_str());


    delay(1000);

    readingID++;
    Serial.println(readingID);

    aNumberIncreasingByOne++;

    sDCardWritePreviousTime = sDCardWriteCurrentTime;
  }

}



//Write a file in SD card
void writeFile(fs::FS &fs, const char * path, const char * message) {
  Serial.printf("Writing file: %s\n", path);

  File file = fs.open(path, FILE_WRITE);
  if (!file) {
    Serial.println("Failed to open file for writing");
    return;
  }


  //fwrite(fb->buf, 1, fb->len, file);
  if (file.print(message)) {
    Serial.println("File written");
  } else {
    Serial.println("Write failed");
  }
}


//Append to the end of file in SD card
void appendFile(fs::FS &fs, const char * path, const char * message) {
  Serial.printf("Appending to file: %s\n", path);

  File file = fs.open(path, FILE_APPEND);
  if (!file) {
    Serial.println("Failed to open file for appending");
    return;
  }
  if (file.print(message)) {
    Serial.println("Message appended");
  } else {
    Serial.println("Append failed");
  }
}




String sendPhotoTelegram() {

  const char* myDomain = "api.telegram.org";
  String getAll = "";
  String getBody = "";


  if (flashActive == true)
  {
    digitalWrite(FLASH_LED_PIN, HIGH);   // FLASH ON
  }


  delay(100);
  camera_fb_t * fb = NULL;
  fb = esp_camera_fb_get();
  delay(100);                    // FLASH OFF
  digitalWrite(FLASH_LED_PIN, LOW);



  if (!fb) {
    Serial.println("Camera capture failed");
    delay(1000);
    ESP.restart();
    return "Camera capture failed";
  }

  //Serial.println("Connect to " + String(myDomain));



  if (clientTCP.connect(myDomain, 443)) {
    //Serial.println("Connection successful");

    String head = "--RandomNerdTutorials\r\nContent-Disposition: form-data; name=\"chat_id\"; \r\n\r\n" + chatId + "\r\n--RandomNerdTutorials\r\nContent-Disposition: form-data; name=\"photo\"; filename=\"esp32-cam.jpg\"\r\nContent-Type: image/jpeg\r\n\r\n";
    String tail = "\r\n--RandomNerdTutorials--\r\n";

    uint16_t imageLen = fb->len;
    uint16_t extraLen = head.length() + tail.length();
    uint16_t totalLen = imageLen + extraLen;

    clientTCP.println("POST /bot" + BOTtoken + "/sendPhoto HTTP/1.1");
    clientTCP.println("Host: " + String(myDomain));
    clientTCP.println("Content-Length: " + String(totalLen));
    clientTCP.println("Content-Type: multipart/form-data; boundary=RandomNerdTutorials");
    clientTCP.println();
    clientTCP.print(head);

    uint8_t *fbBuf = fb->buf;
    size_t fbLen = fb->len;
    for (size_t n = 0; n < fbLen; n = n + 1024) {
      if (n + 1024 < fbLen) {
        clientTCP.write(fbBuf, 1024);
        fbBuf += 1024;
      }
      else if (fbLen % 1024 > 0) {
        size_t remainder = fbLen % 1024;
        clientTCP.write(fbBuf, remainder);
      }
    }

    clientTCP.print(tail);

    esp_camera_fb_return(fb);

    int waitTime = 10000;   // timeout 10 seconds
    long startTimer = millis();
    boolean state = false;

    while ((startTimer + waitTime) > millis()) {
      Serial.print(".");
      delay(100);
      while (clientTCP.available()) {
        char c = clientTCP.read();
        if (c == '\n') {
          if (getAll.length() == 0) state = true;
          getAll = "";
        }
        else if (c != '\r') {
          getAll += String(c);
        }
        if (state == true) {
          getBody += String(c);
        }
        startTimer = millis();
      }
      if (getBody.length() > 0) break;
    }
    clientTCP.stop();
    Serial.println(getBody);
  }

  else {
    getBody = "Connected to api.telegram.org failed.";
    Serial.println("Connected to api.telegram.org failed.");
  }
  return getBody;
}





void handleNewMessages(int numNewMessages) {

  Serial.print("Handle New Messages: ");
  Serial.println(numNewMessages);

  for (int i = 0; i < numNewMessages; i++) {
    // Chat id of the requester
    String chat_id = String(bot.messages[i].chat_id);
    if (chat_id != chatId) {
      bot.sendMessage(chat_id, "Unauthorized user", "");
      continue;
    }

    // Print the received message
    String text = bot.messages[i].text;
    //Serial.println(text);

    String fromName = bot.messages[i].from_name;

    if (text == "LIGHT ON") {
      //flashState = !flashState;
      lightOn = true;
      lightOnMillisTest = true;
      digitalWrite(FLASH_LED_PIN, HIGH);
    }

    if (text == "LIGHT OFF") {
      //flashState = !flashState;
      lightOn = false;
      lightOnMillisTest = false;
      digitalWrite(FLASH_LED_PIN, LOW);
    }

    if (text == "TAKE FLASH PHOTO") {
      flashActive = true;
      sendPhoto = true;
      //Serial.println("New photo  request");
    }

    if (text == "TAKE PHOTO") {
      flashActive = false;
      sendPhoto = true;
      //Serial.println("New photo  request");
    }

    if (text == "TEMPERATURE AND HUMIDITY") {
      String readings = getReadings();
      bot.sendMessage(chatId, readings, "");
    }

    if (text == "BATTERY VOLTS") {
      String volts = getVolts();
      bot.sendMessage(chatId, volts, "");
    }

    if (text == "PIR ON") {
      pirActive = true;
      bot.sendMessage(chatId, "PIR ON");
    }

    if (text == "PIR OFF") {
      pirActive = false;
      bot.sendMessage(chatId, "PIR OFF");
    }

    if (text == "FLASH") {
      flashActive = true;
      bot.sendMessage(chatId, "USE FLASH");
    }

    if (text == "NO FLASH") {
      flashActive = false;
      bot.sendMessage(chatId, "DON'T USE FLASH");
    }

    if (text == "AUTO FLASH") {
      flashActive = false;
      bot.sendMessage(chatId, "USE AUTO FLASH");
    }

    if (text == "ON TIME") {
      String onTime = getOnTime();
      bot.sendMessage(chatId, onTime, "");
    }

    if (text == "PHOTORESISTOR") {
      String photoresistor = getPhotoresistor();
      bot.sendMessage(chatId, photoresistor, "");
    }
    //if (text == "/start") {
    //String welcome = "Welcome to the ESP32-CAM Telegram bot.\n";
    //welcome += "/photo : takes a new photo\n";
    //welcome += "/flash : toggle flash LED\n";
    //welcome += "/readings : request sensor readings\n";
    //welcome += "/volts : request sensor volts\n\n";
    //welcome += "You'll receive a photo whenever motion is detected.\n";
    //bot.sendMessage(chatId, welcome, "Markdown");
    //}

    if (text == "/options") {

      //String keyboardJson = "[ [\"PIR ON\", \"PIR OFF\"],  [\"FLASH\", \"NO FLASH\", \"AUTO FLASH\"],   [\"TAKE PHOTO\", \"TAKE FLASH PHOTO\"],  [\"TEMPERATURE AND HUMIDITY\", \"LIGHT\", \"BATTERY VOLTS\"],  [\"ON TIME\", \"PHOTORESISTOR\", \"SPARE\"]   ]";
      String keyboardJson = "[ [\"PIR ON\", \"PIR OFF\"],  [\"FLASH\", \"NO FLASH\", \"AUTO FLASH\"],   [\"TAKE PHOTO\", \"TAKE FLASH PHOTO\"],  [\"TEMPERATURE AND HUMIDITY\", \"ON TIME\", \"BATTERY VOLTS\"],  [\"LIGHT ON\", \"LIGHT OFF\", \"PHOTORESISTOR\"]   ]";


      bot.sendMessageWithReplyKeyboard(chat_id, "HERE ARE YOUR OPTIONS", "", keyboardJson, true);
    }


  }
}




// Get BME280 sensor readings and return them as a String variable
String getReadings() {
  float temperature, humidity;
  temperature = bme.readTempC();
  //temperature = bme.readTempF();
  humidity = bme.readFloatHumidity();
  String message = "TEMPERATURE: " + String(temperature) + " ºC \n";
  message += "HUMIDITY: " + String (humidity) + " % \n";
  return message;
}



// Get volts sensor readings and return them as a String variable
String getVolts() {

  int16_t adc0;
  int16_t adc1;
  adc0 = ads.readADC_SingleEnded(0);
  battVoltage = (adc0 * 0.1875) / 1000;
  String message = "BATTERY VOLTS: " + String(battVoltage) + " V \n";
  delay(50);
  return message;
}



String getOnTime() {

  unsigned long runMillis = millis();
  unsigned long allSeconds = millis() / 1000;
  int runHours = allSeconds / 3600;
  int secsRemaining = allSeconds % 3600;
  int runMinutes = secsRemaining / 60;
  int runSeconds = secsRemaining % 60;

  String message = "ON TIME: " + String(runHours) + " HRS " + String(runMinutes) + " MINS " + String(runSeconds) + " SECS \n";

  delay(50);

  return message;
}



// Get getPhotoresistor sensor readings and return them as a String variable
String getPhotoresistor() {

  int16_t adc0;
  int16_t adc1;
  adc1 = ads.readADC_SingleEnded(1);
  Light = (adc1 * 0.1875) / 1000;
  String message = "PHOTORESISTOR: " + String(Light) + " V \n";
  delay(50);
  return message;
}


I have made substantial conquests in my learning but this one has got stumpt. I have trawled the forums on this and there is quite a bit on it. Unfortunately I am struggling to understand what the problem is and what the solution is. I'm hoping it is something basic that I have missed/skipped/not got. In fact I'm pretty sure it me me skipping some basic rule!

I hope I have formatted this post correctly.

Any help greatly appreciated!

Kind regards

Added full compiler error here...

BARN_ESP32_CAM_DATA_LOGGER___B__SENT_TO_FORUM:395:16: error: variable or field 'writeFile' declared void
 void writeFile(fs::FS &fs, const char * path, const char * message) {
                ^
BARN_ESP32_CAM_DATA_LOGGER___B__SENT_TO_FORUM:395:16: error: 'fs' has not been declared
BARN_ESP32_CAM_DATA_LOGGER___B__SENT_TO_FORUM:395:24: error: 'fs' was not declared in this scope
 void writeFile(fs::FS &fs, const char * path, const char * message) {
                        ^
BARN_ESP32_CAM_DATA_LOGGER___B__SENT_TO_FORUM:395:28: error: expected primary-expression before 'const'
 void writeFile(fs::FS &fs, const char * path, const char * message) {
                            ^
BARN_ESP32_CAM_DATA_LOGGER___B__SENT_TO_FORUM:395:47: error: expected primary-expression before 'const'
 void writeFile(fs::FS &fs, const char * path, const char * message) {
                                               ^
BARN_ESP32_CAM_DATA_LOGGER___B__SENT_TO_FORUM:415:17: error: variable or field 'appendFile' declared void
 void appendFile(fs::FS &fs, const char * path, const char * message) {
                 ^
BARN_ESP32_CAM_DATA_LOGGER___B__SENT_TO_FORUM:415:17: error: 'fs' has not been declared
BARN_ESP32_CAM_DATA_LOGGER___B__SENT_TO_FORUM:415:25: error: 'fs' was not declared in this scope
 void appendFile(fs::FS &fs, const char * path, const char * message) {
                         ^
BARN_ESP32_CAM_DATA_LOGGER___B__SENT_TO_FORUM:415:29: error: expected primary-expression before 'const'
 void appendFile(fs::FS &fs, const char * path, const char * message) {
                             ^
BARN_ESP32_CAM_DATA_LOGGER___B__SENT_TO_FORUM:415:48: error: expected primary-expression before 'const'
 void appendFile(fs::FS &fs, const char * path, const char * message) {
                                                ^
C:\Users\BARN pc2\Documents\Arduino\BARN_ESP32_CAM_DATA_LOGGER___B__SENT_TO_FORUM\BARN_ESP32_CAM_DATA_LOGGER___B__SENT_TO_FORUM.ino: In function 'void setup()':
BARN_ESP32_CAM_DATA_LOGGER___B__SENT_TO_FORUM:280:42: error: 'writeFile' was not declared in this scope
   writeFile(SD_MMC, "/data.txt", "Hello ");
                                          ^
C:\Users\BARN pc2\Documents\Arduino\BARN_ESP32_CAM_DATA_LOGGER___B__SENT_TO_FORUM\BARN_ESP32_CAM_DATA_LOGGER___B__SENT_TO_FORUM.ino: In function 'void loop()':
BARN_ESP32_CAM_DATA_LOGGER___B__SENT_TO_FORUM:376:56: error: 'appendFile' was not declared in this scope
     appendFile(SD_MMC, "/data.txt", dataMessage.c_str());
                                                        ^
Multiple libraries were found for "SparkFunBME280.h"
 Used: C:\Users\BARN pc2\Documents\Arduino\libraries\SparkFun_BME280_Arduino_Library-master
 Not used: C:\Users\BARN pc2\Documents\Arduino\libraries\SparkFun_BME280
Multiple libraries were found for "UniversalTelegramBot.h"
 Used: C:\Users\BARN pc2\Documents\Arduino\libraries\UniversalTelegramBot
 Not used: C:\Users\BARN pc2\Documents\Arduino\libraries\ESP32-CAM-Video-Telegram-main
exit status 1
variable or field 'writeFile' declared void

Could you copy the full compiler error. There is extra information there

Thank you.

Added full compiler error.

Understood. I am not as experienced as you. It will not happen again.

#include "FS.h" is included in my code

#include "SD.h" is not but #include "SD_MMC.h" is. I have tried each and both no go

#include "SPI.h" was not included in my code. I have added but no go.

Slightly different compiler error now with them all added......

Arduino: 1.8.19 (Windows 10), TD: 1.56, Board: "ESP32 Dev Module, Enabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, None"


B_LOOP:107:16: error: variable or field 'writeFile' declared void

 void writeFile(fs::FS &fs, const char * path, const char * message) {

                ^

B_LOOP:107:16: error: 'fs' has not been declared

B_LOOP:107:24: error: 'fs' was not declared in this scope

 void writeFile(fs::FS &fs, const char * path, const char * message) {

                        ^

B_LOOP:107:28: error: expected primary-expression before 'const'

 void writeFile(fs::FS &fs, const char * path, const char * message) {

                            ^

B_LOOP:107:47: error: expected primary-expression before 'const'

 void writeFile(fs::FS &fs, const char * path, const char * message) {

                                               ^

B_LOOP:127:17: error: variable or field 'appendFile' declared void

 void appendFile(fs::FS &fs, const char * path, const char * message) {

                 ^

B_LOOP:127:17: error: 'fs' has not been declared

B_LOOP:127:25: error: 'fs' was not declared in this scope

 void appendFile(fs::FS &fs, const char * path, const char * message) {

                         ^

B_LOOP:127:29: error: expected primary-expression before 'const'

 void appendFile(fs::FS &fs, const char * path, const char * message) {

                             ^

B_LOOP:127:48: error: expected primary-expression before 'const'

 void appendFile(fs::FS &fs, const char * path, const char * message) {

                                                ^

C:\Users\BARN pc2\Documents\Arduino\BARN___ESP32-CAM___Telegram___PiR___G\A_SETUP.ino: In function 'void setup()':

A_SETUP:137:42: error: 'writeFile' was not declared in this scope

   writeFile(SD_MMC, "/data.txt", "Hello ");

                                          ^

C:\Users\BARN pc2\Documents\Arduino\BARN___ESP32-CAM___Telegram___PiR___G\B_LOOP.ino: In function 'void loop()':

B_LOOP:88:56: error: 'appendFile' was not declared in this scope

     appendFile(SD_MMC, "/data.txt", dataMessage.c_str());

                                                        ^

Multiple libraries were found for "SparkFunBME280.h"

 Used: C:\Users\BARN pc2\Documents\Arduino\libraries\SparkFun_BME280_Arduino_Library-master

 Not used: C:\Users\BARN pc2\Documents\Arduino\libraries\SparkFun_BME280

Multiple libraries were found for "SD.h"

 Used: C:\Users\BARN pc2\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\SD

 Not used: C:\Program Files (x86)\Arduino\libraries\SD

Multiple libraries were found for "UniversalTelegramBot.h"

 Used: C:\Users\BARN pc2\Documents\Arduino\libraries\UniversalTelegramBot

 Not used: C:\Users\BARN pc2\Documents\Arduino\libraries\ESP32-CAM-Video-Telegram-main

exit status 1

variable or field 'writeFile' declared void



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

post the full code. It smells like you are missing a { somewhere and that the function definition might be stuck within another function or something like that

Indenting the code would help see that

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project :wink: See About the Installation & Troubleshooting category.

1 Like

Understood, where should have I put it.

So I have learnt now from this that you need to get all #includes at the very beginning no if, buts, or hair cuts! This has probaly been the root of the problem. Testing that now!

Thanks a million. Will test shortly.

For me, the most sensible place is the Programming Questions section as the error message indicated a programming error. So that is where it was moved to.

1 Like

Why did you change #include <Adafruit_ADS1015.h> to #include <Adafruit_ADS1X15.h> ?

Does not compile for me unless I use #include <Adafruit_ADS1015.h> and Adafruit_ADS1115 ads(0x48);

I remember vaguely there was an issue with #include <Adafruit_ADS1X15.h> and using #include <Adafruit_ADS1015.h> was the work around.

Also why did you add void renameFile and void deleteFile? My working example of basic ESP32 Cam SD card write only uses void writeFile and void appendFile which is all I need.

For me I used the writeFile(SD_MMC, "/data.txt", "Hello "); to create the folder end of setup then use void appendFile to append that folder with the next reading.

This code says its writing in the serial monitor to the SD card but no directory/files are written. It is also boot looping the ESP32 Cam board and not engaging the code past the setup i.e........

String welcome = "Welcome to BARN PiR CAM 1.\n";
welcome += "/options : Gives you some buttons\n";

bot.sendMessage(chatId, welcome, "Markdown");

....is not going out to telegram at start up. Forgive me if that did not need mentioning.

Your code that now compiles with mentioned #include revert.......

#include "FS.h"
#include "SD.h"
#include "SPI.h"
/*

  to do
  1 PIR ON/OFF buttons                        ***DONE***
  2 ON Reminder                               ***DONE***
  3 Photoresistor PIR pic with flash no flash
  4 Take pic with flash no flash buttons      ***DONE***
  5 Low battery message @3.1v
  6 Light timeout                             ***DONE***
  7 Initial on LED                            ***Done***
  8 SD card read battery
  9 Brown out cap

  Notes

  Single cell PSU flashes @3.25v multimeter == 3.1v analog
  Single cell PSU flashes @2.95v multimeter == 2.82v analog
  Last indicator light on PSU flashes @  3.1v analog
  Still flashing @  2.86v analog
  Dropped out @  2.84v analog

*/

//#include <Adafruit_ADS1015.h>
#include <Adafruit_ADS1X15.h>

//Adafruit_ADS1115 ads(0x48);
Adafruit_ADS1X15 ads(0x48); //<<<<<<<<<<<uncomment and all the other lines where this driver is used.

float battVoltage = 0.0;
float Light = 0.0;

int16_t adc0;
int16_t adc1;


int wifiWarningLed = 2;


#include <WiFi.h>
#include <WiFiClientSecure.h>
#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"
#include "esp_camera.h"
#include <UniversalTelegramBot.h>
#include <ArduinoJson.h>
#include <Wire.h>
#include <SparkFunBME280.h>

// Replace with your network credentials
const char* ssid = "XXXXXXXXXXX";    //********************************************
const char* password = "XXXXXXXXXXX"; //********************************************

// Use @myidbot to find out the chat ID of an individual or a group
// Also note that you need to click "start" on a bot before it can
// message you
String chatId = "XXXXXXXXXXXXXXXXXXX";         //********************************************

// Initialize Telegram BOT
String BOTtoken = "XXXXXXXXXXXXXXXXXXX";   //BARN   PiR CAM 1    //********************************************

bool sendPhoto = false;

WiFiClientSecure clientTCP;

UniversalTelegramBot bot(BOTtoken, clientTCP);

//CAMERA_MODEL_AI_THINKER
#define PWDN_GPIO_NUM     32
#define RESET_GPIO_NUM    -1
#define XCLK_GPIO_NUM      0
#define SIOD_GPIO_NUM     26
#define SIOC_GPIO_NUM     27

#define Y9_GPIO_NUM       35
#define Y8_GPIO_NUM       34
#define Y7_GPIO_NUM       39
#define Y6_GPIO_NUM       36
#define Y5_GPIO_NUM       21
#define Y4_GPIO_NUM       19
#define Y3_GPIO_NUM       18
#define Y2_GPIO_NUM        5
#define VSYNC_GPIO_NUM    25
#define HREF_GPIO_NUM     23
#define PCLK_GPIO_NUM     22

#define FLASH_LED_PIN 4


// Motion Sensor
bool motionDetected = false;

// Define I2C Pins for BME280
#define I2C_SDA 14
#define I2C_SCL 15

BME280 bme;

int botRequestDelay = 1000;   // mean time between scan messages
long lastTimeBotRan;     // last time messages' scan has been done

void handleNewMessages(int numNewMessages);
String sendPhotoTelegram();


// Indicates when motion is detected
static void IRAM_ATTR detectsMovement(void * arg) {
  //Serial.println("MOTION DETECTED!!!");
  motionDetected = true;
}

bool pirActive = true;

unsigned long previousReminderMillis = 0;
const long reminderInterval = 1800000;      // 300,000 = 5mins ,  3,600,000 = 1hour , 1,800,000 = Half hour

int initialPowerUpLed = 12;
const long initialPowerLedDuration = 10000;

bool flashActive = false;

bool lightOn = false;
unsigned long lightOnMillis = 0;
const long lightOnMaxTime = 20000;
bool lightOnMillisTest = true;
unsigned long nowLightOnMillis = 0;


unsigned long aNumberIncreasingByOne = 100;

String dataMessage;

int readingID = 0;

unsigned long sDCardWriteCurrentTime = 0;
const long sDCardWriteInterval = 3000;
unsigned long sDCardWritePreviousTime = 0;



void setup() {

  WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);
  Serial.begin(115200);

  pinMode(FLASH_LED_PIN, OUTPUT);
  digitalWrite(FLASH_LED_PIN, LOW);

  pinMode(wifiWarningLed, OUTPUT);
  pinMode(initialPowerUpLed, OUTPUT);

  digitalWrite(initialPowerUpLed, HIGH);

  // Init BME280 sensor
  Wire.begin(I2C_SDA, I2C_SCL);
  bme.settings.commInterface = I2C_MODE;
  bme.settings.I2CAddress = 0x76;
  bme.settings.runMode = 3;
  bme.settings.tStandby = 0;
  bme.settings.filter = 0;
  bme.settings.tempOverSample = 1;
  bme.settings.pressOverSample = 1;
  bme.settings.humidOverSample = 1;
  bme.begin();

  WiFi.mode(WIFI_STA);
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    digitalWrite(wifiWarningLed, HIGH);
    delay(25);
    digitalWrite(wifiWarningLed, LOW);
    delay(150);
  }

  digitalWrite(wifiWarningLed, LOW);

  Serial.println();
  Serial.print("ESP32-CAM IP Address: ");
  Serial.println(WiFi.localIP());

  camera_config_t config;
  config.ledc_channel = LEDC_CHANNEL_0;
  config.ledc_timer = LEDC_TIMER_0;
  config.pin_d0 = Y2_GPIO_NUM;
  config.pin_d1 = Y3_GPIO_NUM;
  config.pin_d2 = Y4_GPIO_NUM;
  config.pin_d3 = Y5_GPIO_NUM;
  config.pin_d4 = Y6_GPIO_NUM;
  config.pin_d5 = Y7_GPIO_NUM;
  config.pin_d6 = Y8_GPIO_NUM;
  config.pin_d7 = Y9_GPIO_NUM;
  config.pin_xclk = XCLK_GPIO_NUM;
  config.pin_pclk = PCLK_GPIO_NUM;
  config.pin_vsync = VSYNC_GPIO_NUM;
  config.pin_href = HREF_GPIO_NUM;
  config.pin_sscb_sda = SIOD_GPIO_NUM;
  config.pin_sscb_scl = SIOC_GPIO_NUM;
  config.pin_pwdn = PWDN_GPIO_NUM;
  config.pin_reset = RESET_GPIO_NUM;
  config.xclk_freq_hz = 20000000;
  config.pixel_format = PIXFORMAT_JPEG;

  //init with high specs to pre-allocate larger buffers
  if (psramFound()) {
    config.frame_size = FRAMESIZE_UXGA;
    config.jpeg_quality = 10;  //0-63 lower number means higher quality
    config.fb_count = 2;
  } else {
    config.frame_size = FRAMESIZE_SVGA;
    config.jpeg_quality = 12;  //0-63 lower number means higher quality
    config.fb_count = 1;
  }

  // camera init
  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK) {
    Serial.printf("Camera init failed with error 0x%x", err);
    delay(500);
    ESP.restart();
  }

  // Drop down frame size for higher initial frame rate
  sensor_t * s = esp_camera_sensor_get();
  s->set_framesize(s, FRAMESIZE_CIF);  // UXGA|SXGA|XGA|SVGA|VGA|CIF|QVGA|HQVGA|QQVGA

  // PIR Motion Sensor mode INPUT_PULLUP
  //err = gpio_install_isr_service(0);
  err = gpio_isr_handler_add(GPIO_NUM_13, &detectsMovement, (void *) 13);
  if (err != ESP_OK) {
    Serial.printf("handler add failed with error 0x%x \r\n", err);
  }
  err = gpio_set_intr_type(GPIO_NUM_13, GPIO_INTR_POSEDGE);
  if (err != ESP_OK) {
    Serial.printf("set intr type failed with error 0x%x \r\n", err);
  }

  //if (text == "/start") {
  String welcome = "Welcome to BARN PiR CAM 1.\n";
  welcome += "/options : Gives you some buttons\n";

  bot.sendMessage(chatId, welcome, "Markdown");



  Serial.println("SDcard Testing....");

  if (!SD.begin())
  {
    log_i("Card Mount Failed");
  }

  //if (!SD_MMC.begin()) {
  //  Serial.println("Card Mount Failed");
  //  return;
  //}
  //uint8_t cardType = SD_MMC.cardType();

  //if (cardType == CARD_NONE) {
  //   Serial.println("No SD_MMC card attached");
  //   return;
  // }

  //Serial.print("SD_MMC Card Type: ");
  //if (cardType == CARD_MMC) {
  // Serial.println("MMC");
  //} else if (cardType == CARD_SD) {
  //  Serial.println("SDSC");
  //} else if (cardType == CARD_SDHC) {
  //  Serial.println("SDHC");
  //} else {
  //  Serial.println("UNKNOWN");
  // }

  //uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024);
  //Serial.printf("SD_MMC Card Size: %lluMB\n", cardSize);
  appendFile(SD, "/data.txt", "Hello ");
  //writeFile(SD_MMC, "/data.txt", "Hello ");

}




void loop() {

  if (sendPhoto) {
    //Serial.println("Preparing photo");
    sendPhotoTelegram();
    sendPhoto = false;
  }

  if (motionDetected && pirActive == true) {
    //bot.sendMessage(chatId, "Motion detected!!", "");
    //Serial.println("Motion Detected");
    //digitalWrite(FLASH_LED_PIN, HIGH);
    sendPhotoTelegram();
    motionDetected = false;

  }

  if (millis() > lastTimeBotRan + botRequestDelay) {
    int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
    while (numNewMessages) {
      //Serial.println("got response");
      handleNewMessages(numNewMessages);
      numNewMessages = bot.getUpdates(bot.last_message_received + 1);
    }
    lastTimeBotRan = millis();
  }

  adc0 = ads.readADC_SingleEnded(0); //<<<<<uncomment
  battVoltage = (adc0 * 0.1875) / 1000;

  adc1 = ads.readADC_SingleEnded(1); //<<<<<uncomment
  Light = (adc1 * 0.1875) / 1000;

  //Serial.print("AIN0: ");
  //Serial.print(adc0);
  //Serial.print("\tbattVoltage: ");
  //Serial.print(battVoltage, 7);
  ////Serial.print();
  //
  //Serial.print("    AIN1: ");
  //Serial.print(adc1);
  //Serial.print("\tLight: ");
  //Serial.println(Light, 7);
  //Serial.println();
  //
  //delay(100);


  unsigned long currentMillis = millis();

  if (currentMillis - previousReminderMillis >= reminderInterval) {
    //String onTime = getOnTime();
    //bot.sendMessage(chatId, onTime, "");
    bot.sendMessage(chatId, "SYSTEM ACTIVE REMINDER");
    previousReminderMillis = currentMillis;
  }


  if (millis() > initialPowerLedDuration) {
    digitalWrite(initialPowerUpLed, LOW);
  }


  if (lightOnMillisTest == true) {
    lightOnMillis = millis();
    lightOnMillisTest = false;
  }

  nowLightOnMillis = millis();

  if ((nowLightOnMillis - lightOnMillis >= lightOnMaxTime) && (lightOn == true)) {
    digitalWrite(FLASH_LED_PIN, LOW);
    lightOn = false;
  }


  sDCardWriteCurrentTime = millis();

  if (currentMillis - sDCardWritePreviousTime >= sDCardWriteInterval) {

    Serial.println("HOORAY");

    //dataMessage = String(readingID) + "," + String(dayStamp) + "," + String(timeStamp) + "," + String(temperature) + "\r\n";
    dataMessage = String(readingID) + " )  " + String(aNumberIncreasingByOne) + "\r\n";
    Serial.print("Save data: ");
    Serial.println(dataMessage);
    appendFile(SD, "/data.txt", dataMessage.c_str());

    //writeFile(SD_MMC, "/data.txt", dataMessage.c_str());

    delay(1000);

    readingID++;
    Serial.println(readingID);

    aNumberIncreasingByOne++;

    sDCardWritePreviousTime = sDCardWriteCurrentTime;
  }

}
///
void appendFile(fs::FS &fs, const char * path, const char * message) {
  //log_i("Appending to file: %s\n", path);
  File file = fs.open(path, FILE_APPEND);
  if (!file)
  {
    log_i("Failed to open file for appending");
    return;
  } else {
    file.print(message);
    file.close();
  }
}
////
void renameFile(fs::FS &fs, const char * path1, const char * path2) {
  log_i("Renaming file %s to %s\n", path1, path2);
  if (fs.rename(path1, path2)) {
    log_i("File renamed");
  } else {
    log_i("Rename failed");
  }
}
////
//void renameFile(fs::FS &fs, const char * path1, const char * path2) {
//  log_i("Renaming file %s to %s\n", path1, path2);
//  if (fs.rename(path1, path2)) {
//    log_i("File renamed");
//  } else {
//    log_i("Rename failed");
//  }
//}
////
void deleteFile(fs::FS &fs, const char * path) {
  log_i("Deleting file: %s\n", path);
  if (fs.remove(path)) {
    log_i("File deleted");
  } else {
    log_i("Delete failed");
  }
}

//
////Write a file in SD card
//void writeFile(fs::FS &fs, const char * path, const char * message) {
//  Serial.printf("Writing file: %s\n", path);
//
//  File file = fs.open(path, FILE_WRITE);
//  if (!file) {
//    Serial.println("Failed to open file for writing");
//    return;
//  }
//
//
//  //fwrite(fb->buf, 1, fb->len, file);
//  if (file.print(message)) {
//    Serial.println("File written");
//  } else {
//    Serial.println("Write failed");
//  }
//}

//
////Append to the end of file in SD card
//void appendFile(fs::FS &fs, const char * path, const char * message) {
//  Serial.printf("Appending to file: %s\n", path);
//
//  File file = fs.open(path, FILE_APPEND);
//  if (!file) {
//    Serial.println("Failed to open file for appending");
//    return;
//  }
//  if (file.print(message)) {
//    Serial.println("Message appended");
//  } else {
//    Serial.println("Append failed");
//  }
//}




String sendPhotoTelegram() {

  const char* myDomain = "api.telegram.org";
  String getAll = "";
  String getBody = "";


  if (flashActive == true)
  {
    digitalWrite(FLASH_LED_PIN, HIGH);   // FLASH ON
  }


  delay(100);
  camera_fb_t * fb = NULL;
  fb = esp_camera_fb_get();
  delay(100);                    // FLASH OFF
  digitalWrite(FLASH_LED_PIN, LOW);



  if (!fb) {
    Serial.println("Camera capture failed");
    delay(1000);
    ESP.restart();
    return "Camera capture failed";
  }

  //Serial.println("Connect to " + String(myDomain));



  if (clientTCP.connect(myDomain, 443)) {
    //Serial.println("Connection successful");

    String head = "--RandomNerdTutorials\r\nContent-Disposition: form-data; name=\"chat_id\"; \r\n\r\n" + chatId + "\r\n--RandomNerdTutorials\r\nContent-Disposition: form-data; name=\"photo\"; filename=\"esp32-cam.jpg\"\r\nContent-Type: image/jpeg\r\n\r\n";
    String tail = "\r\n--RandomNerdTutorials--\r\n";

    uint16_t imageLen = fb->len;
    uint16_t extraLen = head.length() + tail.length();
    uint16_t totalLen = imageLen + extraLen;

    clientTCP.println("POST /bot" + BOTtoken + "/sendPhoto HTTP/1.1");
    clientTCP.println("Host: " + String(myDomain));
    clientTCP.println("Content-Length: " + String(totalLen));
    clientTCP.println("Content-Type: multipart/form-data; boundary=RandomNerdTutorials");
    clientTCP.println();
    clientTCP.print(head);

    uint8_t *fbBuf = fb->buf;
    size_t fbLen = fb->len;
    for (size_t n = 0; n < fbLen; n = n + 1024) {
      if (n + 1024 < fbLen) {
        clientTCP.write(fbBuf, 1024);
        fbBuf += 1024;
      }
      else if (fbLen % 1024 > 0) {
        size_t remainder = fbLen % 1024;
        clientTCP.write(fbBuf, remainder);
      }
    }

    clientTCP.print(tail);

    esp_camera_fb_return(fb);

    int waitTime = 10000;   // timeout 10 seconds
    long startTimer = millis();
    boolean state = false;

    while ((startTimer + waitTime) > millis()) {
      Serial.print(".");
      delay(100);
      while (clientTCP.available()) {
        char c = clientTCP.read();
        if (c == '\n') {
          if (getAll.length() == 0) state = true;
          getAll = "";
        }
        else if (c != '\r') {
          getAll += String(c);
        }
        if (state == true) {
          getBody += String(c);
        }
        startTimer = millis();
      }
      if (getBody.length() > 0) break;
    }
    clientTCP.stop();
    Serial.println(getBody);
  }

  else {
    getBody = "Connected to api.telegram.org failed.";
    Serial.println("Connected to api.telegram.org failed.");
  }
  return getBody;
}





void handleNewMessages(int numNewMessages) {

  Serial.print("Handle New Messages: ");
  Serial.println(numNewMessages);

  for (int i = 0; i < numNewMessages; i++) {
    // Chat id of the requester
    String chat_id = String(bot.messages[i].chat_id);
    if (chat_id != chatId) {
      bot.sendMessage(chat_id, "Unauthorized user", "");
      continue;
    }

    // Print the received message
    String text = bot.messages[i].text;
    //Serial.println(text);

    String fromName = bot.messages[i].from_name;

    if (text == "LIGHT ON") {
      //flashState = !flashState;
      lightOn = true;
      lightOnMillisTest = true;
      digitalWrite(FLASH_LED_PIN, HIGH);
    }

    if (text == "LIGHT OFF") {
      //flashState = !flashState;
      lightOn = false;
      lightOnMillisTest = false;
      digitalWrite(FLASH_LED_PIN, LOW);
    }

    if (text == "TAKE FLASH PHOTO") {
      flashActive = true;
      sendPhoto = true;
      //Serial.println("New photo  request");
    }

    if (text == "TAKE PHOTO") {
      flashActive = false;
      sendPhoto = true;
      //Serial.println("New photo  request");
    }

    if (text == "TEMPERATURE AND HUMIDITY") {
      String readings = getReadings();
      bot.sendMessage(chatId, readings, "");
    }

    if (text == "BATTERY VOLTS") {
      String volts = getVolts();
      bot.sendMessage(chatId, volts, "");
    }

    if (text == "PIR ON") {
      pirActive = true;
      bot.sendMessage(chatId, "PIR ON");
    }

    if (text == "PIR OFF") {
      pirActive = false;
      bot.sendMessage(chatId, "PIR OFF");
    }

    if (text == "FLASH") {
      flashActive = true;
      bot.sendMessage(chatId, "USE FLASH");
    }

    if (text == "NO FLASH") {
      flashActive = false;
      bot.sendMessage(chatId, "DON'T USE FLASH");
    }

    if (text == "AUTO FLASH") {
      flashActive = false;
      bot.sendMessage(chatId, "USE AUTO FLASH");
    }

    if (text == "ON TIME") {
      String onTime = getOnTime();
      bot.sendMessage(chatId, onTime, "");
    }

    if (text == "PHOTORESISTOR") {
      String photoresistor = getPhotoresistor();
      bot.sendMessage(chatId, photoresistor, "");
    }
    //if (text == "/start") {
    //String welcome = "Welcome to the ESP32-CAM Telegram bot.\n";
    //welcome += "/photo : takes a new photo\n";
    //welcome += "/flash : toggle flash LED\n";
    //welcome += "/readings : request sensor readings\n";
    //welcome += "/volts : request sensor volts\n\n";
    //welcome += "You'll receive a photo whenever motion is detected.\n";
    //bot.sendMessage(chatId, welcome, "Markdown");
    //}

    if (text == "/options") {

      //String keyboardJson = "[ [\"PIR ON\", \"PIR OFF\"],  [\"FLASH\", \"NO FLASH\", \"AUTO FLASH\"],   [\"TAKE PHOTO\", \"TAKE FLASH PHOTO\"],  [\"TEMPERATURE AND HUMIDITY\", \"LIGHT\", \"BATTERY VOLTS\"],  [\"ON TIME\", \"PHOTORESISTOR\", \"SPARE\"]   ]";
      String keyboardJson = "[ [\"PIR ON\", \"PIR OFF\"],  [\"FLASH\", \"NO FLASH\", \"AUTO FLASH\"],   [\"TAKE PHOTO\", \"TAKE FLASH PHOTO\"],  [\"TEMPERATURE AND HUMIDITY\", \"ON TIME\", \"BATTERY VOLTS\"],  [\"LIGHT ON\", \"LIGHT OFF\", \"PHOTORESISTOR\"]   ]";


      bot.sendMessageWithReplyKeyboard(chat_id, "HERE ARE YOUR OPTIONS", "", keyboardJson, true);
    }


  }
}




// Get BME280 sensor readings and return them as a String variable
String getReadings() {
  float temperature, humidity;
  temperature = bme.readTempC();
  //temperature = bme.readTempF();
  humidity = bme.readFloatHumidity();
  String message = "TEMPERATURE: " + String(temperature) + " ºC \n";
  message += "HUMIDITY: " + String (humidity) + " % \n";
  return message;
}



// Get volts sensor readings and return them as a String variable
String getVolts() {

  int16_t adc0;
  int16_t adc1;
  adc0 = ads.readADC_SingleEnded(0); // <<<<<<<<<<<<<<<<<<<<<<<uncomment
  battVoltage = (adc0 * 0.1875) / 1000;
  String message = "BATTERY VOLTS: " + String(battVoltage) + " V \n";
  delay(50);
  return message;
}



String getOnTime() {

  unsigned long runMillis = millis();
  unsigned long allSeconds = millis() / 1000;
  int runHours = allSeconds / 3600;
  int secsRemaining = allSeconds % 3600;
  int runMinutes = secsRemaining / 60;
  int runSeconds = secsRemaining % 60;

  String message = "ON TIME: " + String(runHours) + " HRS " + String(runMinutes) + " MINS " + String(runSeconds) + " SECS \n";

  delay(50);

  return message;
}



// Get getPhotoresistor sensor readings and return them as a String variable
String getPhotoresistor() {

  int16_t adc0;
  int16_t adc1;
  adc1 = ads.readADC_SingleEnded(1); //<<<<<<<<<<<<<<<<un comment >>>>>>>>>>>>>>>
  Light = (adc1 * 0.1875) / 1000;
  String message = "PHOTORESISTOR: " + String(Light) + " V \n";
  delay(50);
  return message;
}

Compiler error......

Arduino: 1.8.19 (Windows 10), TD: 1.56, Board: "ESP32 Dev Module, Enabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, None"

BARN_SD_CARD_ESP32_CAM_THAT_MIGHT_WORK:31:26: error: no matching function for call to 'Adafruit_ADS1X15::Adafruit_ADS1X15(int)'

 Adafruit_ADS1X15 ads(0x48); //<<<<<<<<<<<uncomment and all the other lines where this driver is used.

                          ^

In file included from C:\Users\BARN pc2\Documents\Arduino\BARN_SD_CARD_ESP32_CAM_THAT_MIGHT_WORK\BARN_SD_CARD_ESP32_CAM_THAT_MIGHT_WORK.ino:28:0:

C:\Users\BARN pc2\Documents\Arduino\libraries\Adafruit_ADS1X15/Adafruit_ADS1X15.h:148:7: note: candidate: Adafruit_ADS1X15::Adafruit_ADS1X15()

 class Adafruit_ADS1X15 {

       ^

C:\Users\BARN pc2\Documents\Arduino\libraries\Adafruit_ADS1X15/Adafruit_ADS1X15.h:148:7: note:   candidate expects 0 arguments, 1 provided

C:\Users\BARN pc2\Documents\Arduino\libraries\Adafruit_ADS1X15/Adafruit_ADS1X15.h:148:7: note: candidate: constexpr Adafruit_ADS1X15::Adafruit_ADS1X15(const Adafruit_ADS1X15&)

C:\Users\BARN pc2\Documents\Arduino\libraries\Adafruit_ADS1X15/Adafruit_ADS1X15.h:148:7: note:   no known conversion for argument 1 from 'int' to 'const Adafruit_ADS1X15&'

C:\Users\BARN pc2\Documents\Arduino\libraries\Adafruit_ADS1X15/Adafruit_ADS1X15.h:148:7: note: candidate: constexpr Adafruit_ADS1X15::Adafruit_ADS1X15(Adafruit_ADS1X15&&)

C:\Users\BARN pc2\Documents\Arduino\libraries\Adafruit_ADS1X15/Adafruit_ADS1X15.h:148:7: note:   no known conversion for argument 1 from 'int' to 'Adafruit_ADS1X15&&'

Multiple libraries were found for "SD.h"

 Used: C:\Users\BARN pc2\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\SD

 Not used: C:\Program Files (x86)\Arduino\libraries\SD

Multiple libraries were found for "UniversalTelegramBot.h"

 Used: C:\Users\BARN pc2\Documents\Arduino\libraries\UniversalTelegramBot

 Not used: C:\Users\BARN pc2\Documents\Arduino\libraries\ESP32-CAM-Video-Telegram-main

Multiple libraries were found for "SparkFunBME280.h"

 Used: C:\Users\BARN pc2\Documents\Arduino\libraries\SparkFun_BME280_Arduino_Library-master

 Not used: C:\Users\BARN pc2\Documents\Arduino\libraries\SparkFun_BME280

exit status 1

no matching function for call to 'Adafruit_ADS1X15::Adafruit_ADS1X15(int)'


This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I know my libraries are a bit of a mess.

Thanks for all your help so far definitely. Much appreciated!

Actually, I see that I'm unable to help you. Just delete the code I said that works and go back to your old code. Perhaps someone else can solve your issue. Good luck and sorry to have bothered you.

Ahh-man! Ok.

Thank you for having a go mate!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.