I have tried ti uninstall the arduino IDE app and download it again, but the error still occurs.
This is my code:
#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 <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
//isi dengan alamat dan password wifi
const char* ssid = "Awan";
const char* password = "__o8z3__";
//konfigurasi komponen
const int knockSensor = 12;
const int programSwitch = 15;
const int Solenoid = 14;
const int greenLED = 4;
const int threshold = 100;
const int rejectValue = 25;
const int averageRejectValue = 15;
const int knockFadeTime = 150;
const int lockTurnTime = 2000;
const int maximumKnocks = 20;
const int knockComplete = 1200;
int secretCode[maximumKnocks] = {25, 25, 35, 50, 40, 50, 0, 0, 0, 0};
int knockReadings[maximumKnocks];
int knockSensorValue = 0;
int programButtonPressed = false;
int buzzerDoor = 2;
//kamera
String BOTtoken = "6986562297:AAFp-ujtEgNaSWB_GeQhlY5A9VGuJoTuWmc"; // isi dengan token dari botfather telegram
String chatId = " "; //isi dengan id chat dari id bot
bool sendPhoto = false;
WiFiClientSecure clientTCP;
UniversalTelegramBot bot(BOTtoken, clientTCP);
//pintu
const String label1 = "Pintu terkunci";
const String label2 = "Initialize...";
const String label3 = "Silahkan masuk";
const String label4 = "Merekam";
const String label5 = "Program Siap";
const String label6 = "Silahkan Ketuk";
const String label7 = "Ketukan tersimpan";
//konfigurasi pin
#define SDA_PIN 0
#define SCL_PIN 16
//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 FLASHpin 4
bool flashState = LOW;
bool adaGerakan = false;
int botRequestDelay = 1000; // setiap 1 detik akan check bot
long lastTimeBotRan;
void handleNewMessages(int numNewMessages);
String sendPhotoTelegram();
static void IRAM_ATTR detectsMovement(void * arg){
//Serial.println("ADA GERAKAN!!!");
adaGerakan = true;
}
void setup(){
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);
Serial.begin(115200);
pinMode(FLASHpin, OUTPUT);
digitalWrite(FLASHpin, flashState);
WiFi.mode(WIFI_STA);
Serial.println();
Serial.print("menghubungkan wifi: ");
Serial.println(ssid);
WiFi.begin(ssid, password);
clientTCP.setCACert(TELEGRAM_CERTIFICATE_ROOT); // Add root certificate for api.telegram.org
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.println("WiFi connected");
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(1000);
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); // pin sensor yg di gunakan
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);
}
//pintu
lcd.backlight();
Wire.begin(SDA_PIN, SCL_PIN);
lcd.begin(16, 2);
pinMode(Solenoid, OUTPUT);
//pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(buzzerDoor, OUTPUT);
pinMode(programSwitch, INPUT);
Serial.begin(9600);
Serial.println("mulai program");
digitalWrite(greenLED, HIGH);
clearLCDLine(0);
lcd.print(label2);
delay(2000);
clearLCDLine(0);
lcd.print(label5);
delay(1000);
clearLCDLine(0);
lcd.print(label6);
clearLCDLine(1);
lcd.print(label1);
}
void loop(){
if (sendPhoto){
Serial.println("persiapan foto");
sendPhotoTelegram();
sendPhoto = false;
}
if(adaGerakan){
bot.sendMessage(chatId, "ADA GERAKAN !!!", "");
Serial.println("Ada gerakan");
sendPhotoTelegram();
adaGerakan = 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();
}
//pintu
knockSensorValue = analogRead(knockSensor);
if (digitalRead(programSwitch)==HIGH){
programButtonPressed = true;
clearLCDLine(1);
lcd.print("Recording");
Serial.println("Recording");
} else {
programButtonPressed = false;
clearLCDLine(1);
lcd.print("Pintu Terkunci");
Serial.println("Pintu Terkunci");
}
if (knockSensorValue >=threshold){
listenToSecretKnock();
}
}
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 == "/flash") {
flashState = !flashState;
digitalWrite(FLASHpin, flashState);
}
if (text == "/foto") {
sendPhoto = true;
Serial.println("New photo request");
}
if (text == "/start"){
String welcome = "at-mo production\n";
welcome += "klik tulisan biru\n";
welcome += "/foto : untuk ambil gambar langsung\n";
welcome += "/flash : untuk on off lampu flash\n";
welcome += "system ini otomatis kirim foto saat terjadi gerakan.\n";
bot.sendMessage(chatId, welcome, "Markdown");
}
}
}
//pintu
void listenToSecretKnock(){
clearLCDLine(1);
lcd.print("Silahkan Ketuk Pintu");
Serial.println("silahkan ketuk pintu");
int i = 0;
for (i=0;i<maximumKnocks;i++){
knockReadings[i]=0;
}
int currentKnockNumber=0;
int startTime=millis();
int now=millis();
digitalWrite(greenLED, LOW);
if (programButtonPressed==true){
}
delay(knockFadeTime);
digitalWrite(greenLED, HIGH);
if (programButtonPressed==true){
digitalWrite(buzzerDoor, HIGH);
tone(buzzerDoor, 1000);
}
do {
knockSensorValue = analogRead(knockSensor);
if (knockSensorValue >=threshold){
clearLCDLine(1);
lcd.print("mengetuk");
Serial.println("mengetuk");
now=millis();
knockReadings[currentKnockNumber] = now-startTime;
currentKnockNumber ++;
startTime=now;
digitalWrite(greenLED, LOW);
if (programButtonPressed==true){
}
delay(knockFadeTime);
digitalWrite(greenLED, HIGH);
if (programButtonPressed==true){
digitalWrite(buzzerDoor, HIGH);
tone(buzzerDoor, 1000);
}
}
now=millis();
} while ((now-startTime < knockComplete) && (currentKnockNumber < maximumKnocks));
if (programButtonPressed==false){
if (validateKnock() == true){
triggerDoorUnlock();
} else {
clearLCDLine(1);
lcd.print("ketukan salah");
Serial.println("ketukan salah");
digitalWrite(greenLED, LOW);
for (i=0;i<4;i++){
digitalWrite(buzzerDoor, HIGH);
tone(buzzerDoor, 1000);
delay(100);
digitalWrite(buzzerDoor, LOW);
noTone(buzzerDoor);
delay(100);
}
clearLCDLine(1);
digitalWrite(greenLED, HIGH);
}
} else {
validateKnock();
clearLCDLine(0);
lcd.print("Silahkan ketuk");
clearLCDLine(1);
lcd.print(label7);
lcd.print("Ketukan tersimpan");
delay(1000);
clearLCDLine(1);
lcd.print(label1);
lcd.print("Pintu terkunci");
Serial.println("ketukan baru");
digitalWrite(greenLED, HIGH);
for (i=0;i<3;i++){
delay(50);
digitalWrite(buzzerDoor, HIGH);
tone(buzzerDoor, 1000);
digitalWrite(greenLED, LOW);
delay(100);
digitalWrite(buzzerDoor, LOW);
noTone(buzzerDoor);
digitalWrite(greenLED, HIGH);
}
}
}
void triggerDoorUnlock(){
clearLCDLine(1);
lcd.print(label3);
lcd.print("Silahkan masuk");
Serial.println("Silahkan Masuk");
int i=0;
digitalWrite(Solenoid, HIGH);
delay (lockTurnTime);
digitalWrite(Solenoid, LOW);
for (i=0; i < 5; i++){
digitalWrite(greenLED, LOW);
delay(100);
digitalWrite(greenLED, HIGH);
delay(100);
}
clearLCDLine(1);
lcd.print("pintu terkunci");
Serial.println("pintu terkunci");
}
boolean validateKnock(){
int i=0;
int currentKnockCount = 0;
int secretKnockCount = 0;
int maxKnockInterval = 0;
for (i=0;i<maximumKnocks;i++){
if (knockReadings[i] > 0){
currentKnockCount++;
}
if (secretCode[i] > 0){
secretKnockCount++;
}
if (knockReadings[i] > maxKnockInterval){
maxKnockInterval = knockReadings[i];
}
}
if (programButtonPressed==true){
for (i=0;i<maximumKnocks;i++){
secretCode[i]= map(knockReadings[i],0, maxKnockInterval, 0, 50);
}
digitalWrite(greenLED, LOW);
delay(1000);
digitalWrite(greenLED, HIGH);
delay(50);
for (i = 0; i < maximumKnocks ; i++){
digitalWrite(greenLED, LOW);
if (secretCode[i] > 0){
delay( map(secretCode[i],0, 50, 0, maxKnockInterval));
digitalWrite(greenLED, HIGH);
}
delay(50);
}
return false;
}
if (currentKnockCount != secretKnockCount){
return false;
}
int totaltimeDifferences=0;
int timeDiff=0;
for (i=0;i<maximumKnocks;i++){
knockReadings[i]= map(knockReadings[i],0, maxKnockInterval, 0, 50);
timeDiff = abs(knockReadings[i]-secretCode[i]);
if (timeDiff > rejectValue){
return false;
}
totaltimeDifferences += timeDiff;
}
if (totaltimeDifferences/secretKnockCount>averageRejectValue){
return false;
}
return true;
}
void clearLCDLine(int line){
for(int n = 0; n < 20; n++) { // 20 indicates symbols in line. For 2x16 LCD write - 16
lcd.setCursor(n,line);
lcd.print(" ");
}
lcd.setCursor(0,line); // set cursor in the beginning of deleted line
}
and this is the eror compiling:
c:/users/acer/appdata/local/arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: sketch\codingan_finish__sempurna_.ino.cpp.o:(.literal.Z4loopv+0x24): undefined reference to sendPhotoTelegram()' c:/users/acer/appdata/local/arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: sketch\codingan_finish__sempurna_.ino.cpp.o: in function
loop()':
C:\Users\acer\OneDrive\Documents\File Kurniawan\HASIL TUGAS AKHIR\codingan_finish__sempurna/codingan_finish__sempurna_.ino:358: undefined reference to sendPhotoTelegram()' c:/users/acer/appdata/local/arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:\Users\acer\OneDrive\Documents\File Kurniawan\HASIL TUGAS AKHIR\codingan_finish__sempurna_/codingan_finish__sempurna_.ino:369: undefined reference to
sendPhotoTelegram()'
collect2.exe: error: ld returned 1 exit status
Multiple libraries were found for "WiFi.h"
Used: C:\Users\acer\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.14\libraries\WiFi
Not used: C:\Program Files (x86)\Arduino\libraries\WiFi
exit status 1
Error compiling for board ESP32 Wrover Module.