#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
//#include <Adafruit_Sensor.h>
#include <TinyGPS.h>
#include <IRremote.h>
#include <Adafruit_ZeroI2S.h>
#include <Esp32cam.h>
#define WIFI_SSID "***********"
#define WIFI_PASSWORD "************"
#define BOT_TOKEN "*******************"
#define CHAT_ID "********"
#define CAMERA_XCLK 32
#define CAMERA_PWDN -1
#define CAMERA_RESET -1
#define CAMERA_SDA 22
#define CAMERA_SCL 21
#define CAMERA_D0 26
#define CAMERA_D1 27
#define CAMERA_D2 14
#define CAMERA_D3 12
#define CAMERA_D4 13
#define CAMERA_D5 15
#define CAMERA_D6 2
#define CAMERA_D7 0
#define CAMERA_VSYNC 23
#define CAMERA_HREF 25
#define IR_RECEIVER_PIN 18
ESP32-cam mycam;
Adafruit_ZeroI2S i2s;
WiFiClientSecure client;
UniversalTelegramBot bot(BOT_TOKEN, client);
TinyGPS gps;
HardwareSerial gpsSerial(2);
IRrecv irReceiver(IR_RECEIVER_PIN);
decode_results results;
bool isRecordingAudio = false;
bool isRecordingVideo = false;
int zoomLevel = 0;
int focusDistance = INFINITE;
void connectWiFi() {
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.println("WiFi connected");
}
void setupCamera() {
mycam.setPins(CAMERA_XCLK, CAMERA_PWDN, CAMERA_RESET, CAMERA_SDA, CAMERA_SCL, CAMERA_D0, CAMERA_D1, CAMERA_D2, CAMERA_D3, CAMERA_D4, CAMERA_D5, CAMERA_D6, CAMERA_D7, CAMERA_VSYNC, CAMERA_HREF);
mycam.setResolution(FRAMESIZE_UXGA);
mycam.init();
mycam.run(true);
}
void setupGPS() {
gpsSerial.begin(9600, SERIAL_8N1, 16, 17); // Serial2 RXD2 (IO16), TXD2 (IO17)
}
void setupIRReceiver() {
irReceiver.enableIRIn();
}
void setup() {
Serial.begin(115200);
connectWiFi();
setupCamera();
setupGPS();
setupIRReceiver();
// Set the default zoom level and focus distance
cam.setZoom(zoomLevel);
cam.setFocus(focusDistance);
}
void captureAndSendPhoto() {
camera_fb_t *fb = cam.capture();
if (!fb) {
Serial.println("Failed to capture photo");
return;
}
if (bot.sendPhoto(CHAT_ID, fb->buf, fb->len)) {
Serial.println("Photo sent");
} else {
Serial.println("Failed to send photo");
}
cam.release(fb);
}
void startAudioRecording() {
isRecordingAudio = true;
i2s.begin();
i2s.setBlockSize(1024);
i2s.setSampleRate(16000);
i2s.startRecording();
}
void stopAudioRecording() {
isRecordingAudio = false;
i2s.stopRecording();
}
void captureAndSendAudio() {
if (!isRecordingAudio) {
Serial.println("Audio recording not in progress");
return;
}
stopAudioRecording();
size_t bufferSize = i2s.available();
if (bufferSize == 0) {
Serial.println("No audio data recorded");
return;
}
uint8_t* buffer = (uint8_t*)malloc(bufferSize);
i2s.read(buffer, bufferSize);
if (bot.sendAudio(CHAT_ID, buffer, bufferSize)) {
Serial.println("Audio sent");
} else {
Serial.println("Failed to send audio");
}
free(buffer);
}
void startVideoRecording() {
isRecordingVideo = true;
cam.startCapture();
}
void stopVideoRecording() {
isRecordingVideo = false;
cam.stopCapture();
}
void captureAndSendVideo() {
if (!isRecordingVideo) {
Serial.println("Video recording not in progress");
return;
}
stopVideoRecording();
size_t bufferSize = cam.getFrameLength();
uint8_t* buffer = (uint8_t*)malloc(bufferSize);
cam.getCapture(buffer, bufferSize);
if (bot.sendVideo(CHAT_ID, buffer, bufferSize)) {
Serial.println("Video sent");
} else {
Serial.println("Failed to send video");
}
free(buffer);
}
void captureAndSendLocation() {
float latitude, longitude;
unsigned long fixAge;
gps.f_get_position(&latitude, &longitude, &fixAge);
if (fixAge == TinyGPS::GPS_INVALID_AGE) {
Serial.println("Failed to get GPS fix");
return;
}
String location = String(latitude, 6) + "," + String(longitude, 6);
if (bot.sendLocation(CHAT_ID, latitude, longitude)) {
Serial.println("Location sent");
} else {
Serial.println("Failed to send location");
}
}
void loop() {
if (irReceiver.decode(&results)) {
switch (results.value) {
case 0x1FE807F: // Zoom in
controlZoomAndFocus(1, INFINITE);
break;
case 0x1FE40BF: // Zoom out
controlZoomAndFocus(-1, INFINITE);
break;
case 0x1FE20DF: // Take photo
captureAndSendPhoto();
break;
else if (results.value == 0x1FE40BF) {
if (isRecordingAudio) {
stopAudioRecording();
captureAndSendAudio();
}
case 0x1FEC03F: // Start video recording
startVideoRecording();
break;
case 0x1FE10EF: // Stop video recording
stopVideoRecording();
break;
case 0x1FEF807: // Capture and send location
captureAndSendLocation();
break;
default:
break;
}
irReceiver.resume();
}
while (gpsSerial.available() > 0) {
if (gps.encode(gpsSerial.read())) {
if (gps.location.isUpdated()) {
Serial.println("GPS Location Updated");
}
if (gps.speed.isUpdated()) {
Serial.println("GPS Speed Updated");
}
}
}
}
First I use ArduinoDroid and I do not use Arduino IDE
When I click on compile this message appears : sketch_sep09a.ino:34:1: error: 'esp32cam' does not name a type
And I erased the library and installed it more than once and the problem was not solved