I need help with esp32

Now after I uploaded the code to esp32, it appeared to me in the serial monitor that the space is full, and then I made erase by esptool and uploaded the code again to the board, but this always appears to me

10:04:09.632 -> ets Jun  8 2016 00:22:57
10:04:09.639 -> 
10:04:09.642 -> rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
10:04:09.653 -> configsip: 0, SPIWP:0xee
10:04:09.662 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
10:04:09.674 -> mode:DIO, clock div:1
10:04:09.680 -> load:0x3fff0018,len:4
10:04:09.684 -> load:0x3fff001c,len:928
10:04:09.689 -> ho 0 tail 12 room 4
10:04:09.693 -> load:0x40078000,len:8740
10:04:09.698 -> load:0x40080400,len:5788
10:04:09.702 -> entry 0x4008069c

What should I do

Start by posting your sketch

Feed the Watch Dog:

It looks like a Watch Dog Timer reset. This may be caused by blocking code like a tight loop. Sometimes, adding a yield() statement in such a loop can help.

(as I have now noticed @DrDiettrich has just said)

This my sketch

#include <WiFi.h>
#include <WiFiClient.h>
#include <HardwareSerial.h>
#include <UniversalTelegramBot.h>
#include <Adafruit_Sensor.h>
#include <TinyGPS++.h>
#include <Arducam_Mega.h>
#include <IRremote.h>
#include <DFRobot_VoiceRecorder.h>

// constants
#define WIFI_SSID "****" 
#define WIFI_PASSWORD "*******"

#define BOT_TOKEN "********"
#define CHAT_ID "****"

CAM_IMAGE_MODE imageMode = CAM_IMAGE_MODE_QVGA;

// variables
WiFiClient client;
UniversalTelegramBot bot(BOT_TOKEN, client);

#define CAM_SCL 21
#define CAM_SDA 22
#define CAM_VSYNC 23
#define CAM_HREF 25
#define CAM_D0 26
#define CAM_D1 27
#define CAM_D2 14
#define CAM_D3 12
#define CAM_D4 13
#define CAM_D5 15
#define CAM_D6 2
#define CAM_D7 0
#define CAM_RESET 4
#define CAM_PWDN 5

#define MIC_SEL 34
#define MIC_LRCL 35
#define MIC_DOUT 32
#define MIC_BCLK 33

#define GPS_PPS 19
#define GPS_RXD 17 
#define GPS_TXD 16

#define IR_RECEIVER 18

#define TAKE_PHOTO 0x1FE807F
#define START_AUDIO 0x1FE40BF
#define STOP_AUDIO 0x1FE20DF
#define GET_LOCATION 0x1FEF807


IRrecv irrecv(IR_RECEIVER);
decode_results results;

TinyGPSPlus gps;
double latitude = 0.0; 
double longitude = 0.0;
HardwareSerial swSer(17);

Arducam_Mega myCAM (21);

DFRobot_VoiceRecorder_I2C voicerecorder;

void setup() {

Serial.begin(115200);

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

irrecv.enableIRIn();
    
// Initialize camera
     myCAM.takePicture(CAM_IMAGE_MODE_WQXGA2,CAM_IMAGE_PIX_FMT_JPG);
//myCAM.setJPEGQuality(80);

// Initialize microphone
voicerecorder.begin();
    
}

void loop() {
  if (irrecv.decode(&results)) {
  if (results.value == TAKE_PHOTO) {
    // Take a photo and send it to the Telegram bot
myCAM.takePicture(imageMode,CAM_IMAGE_PIX_FMT_JPG);        
  }

       
  // Get the photo file name
  String photoFileName = "photo.jpg";

  // Upload the photo to the Telegram bot
  bot.sendPhoto(CHAT_ID, photoFileName);
}
            
      
if (results.value == START_AUDIO) {
  // Start recording audio
  int status = voicerecorder.recordvoiceStart();
  if (status != VOICE_SUCCESS) {
    Serial.println("Error starting audio recording");
  }
}

if (results.value == STOP_AUDIO) {  
  // Stop recording audio
  int status = voicerecorder.recordVoiceEnd();
  if (status != VOICE_SUCCESS) {
    Serial.println("Error stopping audio recording");
  }
}

  // Get the audio file name
  String audioFileName = "audio.mp3";

  // Upload the audio to the Telegram bot
  bot.sendMessage(CHAT_ID, audioFileName);

       
if (results.value == GET_LOCATION) {
  // Get the GPS location
   while (swSer.available() > 0)
    gps.encode(swSer.read());
      {
    delay(100);
  }


if (gps.location.isUpdated())
  {
    latitude = gps.location.lat();
    longitude = gps.location.lng();
  }


  // Send the location to the Telegram bot
  String locationMessage = "Location: " + String(latitude, 6) + ", " + String(longitude, 6);
  bot.sendMessage(CHAT_ID, locationMessage.c_str(), "");
}

    irrecv.resume();
  }


void takePhoto() {
  // Take a photo
  //myCAM.takePicture();
myCAM.takePicture(CAM_IMAGE_MODE_WQXGA2,CAM_IMAGE_PIX_FMT_JPG);
}

void startAudioRecording() {
  // Start audio recording
  int status = voicerecorder.recordvoiceStart();
  if (status != VOICE_SUCCESS) {
    Serial.println("Error starting audio recording");
  }
}

void stopAudioRecording() {
  // Stop audio recording
  int status = voicerecorder.recordVoiceEnd();
  if (status != VOICE_SUCCESS) {
    Serial.println("Error stopping audio recording");      
        }
     }
void getGPSLocation() {
  // Get the GPS location
  while (swSer.available() > 0 && !gps.location.isUpdated()) {
    gps.encode(swSer.read());
    delay(100);
  }

  if (gps.location.isUpdated()) {
    latitude = gps.location.lat();
    longitude = gps.location.lng();
  }
  // Send the location to the Telegram bot
  String locationMessage = "Location: " + String(latitude, 6) + ", " + String(longitude, 6);
  bot.sendMessage(CHAT_ID, locationMessage.c_str(), "");
} 

And how do I do that?

See post #4: add a yield(); in loop() so that the idleTask can feed the watchdog.

Also see this How To what NOT to do.

Well, what exactly can I do to put everything back as it was?

Did it work at some time ? Reverting to the original code would then seem to be a good idea then gradually introduce any changes and see where it breaks.

Here is a potentially long blocking loop, depending on the volume of serial data, and appears oddly structured:

 while (swSer.available() > 0)
      gps.encode(swSer.read());
    {
      delay(100);
    }

Otherwise just add a yield(); before irrecv.resume();

I added it as you said and the code became like this

#include <WiFi.h>
#include <WiFiClient.h>
#include <HardwareSerial.h>
#include <UniversalTelegramBot.h>
#include <Adafruit_Sensor.h>
#include <TinyGPS++.h>
#include <Arducam_Mega.h>
#include <IRremote.h>
#include <DFRobot_VoiceRecorder.h>

// constants
#define WIFI_SSID "*****"
#define WIFI_PASSWORD "******" 

#define BOT_TOKEN "*******"
#define CHAT_ID "******"

CAM_IMAGE_MODE imageMode = CAM_IMAGE_MODE_QVGA;

// variables
WiFiClient client;
UniversalTelegramBot bot(BOT_TOKEN, client);

#define CAM_SCL 21
#define CAM_SDA 22
#define CAM_VSYNC 23
#define CAM_HREF 25
#define CAM_D0 26
#define CAM_D1 27
#define CAM_D2 14
#define CAM_D3 12
#define CAM_D4 13
#define CAM_D5 15
#define CAM_D6 2
#define CAM_D7 0
#define CAM_RESET 4
#define CAM_PWDN 5

#define MIC_SEL 34
#define MIC_LRCL 35
#define MIC_DOUT 32
#define MIC_BCLK 33

#define GPS_PPS 19
#define GPS_RXD 17 
#define GPS_TXD 16

#define IR_RECEIVER 18

#define TAKE_PHOTO 0x1FE807F
#define START_AUDIO 0x1FE40BF
#define STOP_AUDIO 0x1FE20DF
#define GET_LOCATION 0x1FEF807


IRrecv irrecv(IR_RECEIVER);
decode_results results;

TinyGPSPlus gps;
double latitude = 0.0; 
double longitude = 0.0;
HardwareSerial swSer(17);

Arducam_Mega myCAM (21);

DFRobot_VoiceRecorder_I2C voicerecorder;

void setup() {

Serial.begin(115200);

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

irrecv.enableIRIn();
    
// Initialize camera
     myCAM.takePicture(CAM_IMAGE_MODE_WQXGA2,CAM_IMAGE_PIX_FMT_JPG);
//myCAM.setJPEGQuality(80);

// Initialize microphone
voicerecorder.begin();
    
}

void loop() {
  if (irrecv.decode(&results)) {
  if (results.value == TAKE_PHOTO) {
    // Take a photo and send it to the Telegram bot
myCAM.takePicture(imageMode,CAM_IMAGE_PIX_FMT_JPG);        
  }
     
  // Get the photo file name
  String photoFileName = "photo.jpg";

  // Upload the photo to the Telegram bot
  bot.sendPhoto(CHAT_ID, photoFileName);
}
            
      
if (results.value == START_AUDIO) {
  // Start recording audio
  int status = voicerecorder.recordvoiceStart();
  if (status != VOICE_SUCCESS) {
    Serial.println("Error starting audio recording");
  }
}

if (results.value == STOP_AUDIO) {  
  // Stop recording audio
  int status = voicerecorder.recordVoiceEnd();
  if (status != VOICE_SUCCESS) {
    Serial.println("Error stopping audio recording");
  }
}

  // Get the audio file name
  String audioFileName = "audio.mp3";

  // Upload the audio to the Telegram bot
  bot.sendMessage(CHAT_ID, audioFileName);

       
if (results.value == GET_LOCATION) {
  // Get the GPS location
   while (swSer.available() > 0)
    gps.encode(swSer.read());
      {
    delay(100);
  }


if (gps.location.isUpdated())
  {
    latitude = gps.location.lat();
    longitude = gps.location.lng();
  }


  // Send the location to the Telegram bot
  String locationMessage = "Location: " + String(latitude, 6) + ", " + String(longitude, 6);
  bot.sendMessage(CHAT_ID, locationMessage.c_str(), "");
}

    yield(); 
    irrecv.resume();
  }

void takePhoto() {
  // Take a photo
  //myCAM.takePicture();
myCAM.takePicture(CAM_IMAGE_MODE_WQXGA2,CAM_IMAGE_PIX_FMT_JPG);
}

void startAudioRecording() {
  // Start audio recording
  int status = voicerecorder.recordvoiceStart();
  if (status != VOICE_SUCCESS) {
    Serial.println("Error starting audio recording");
  }
}

void stopAudioRecording() {
  // Stop audio recording
  int status = voicerecorder.recordVoiceEnd();
  if (status != VOICE_SUCCESS) {
    Serial.println("Error stopping audio recording");      
        }
     }
void getGPSLocation() {
  // Get the GPS location
  while (swSer.available() > 0 && !gps.location.isUpdated()) {
    gps.encode(swSer.read());
    delay(100);
  }

  if (gps.location.isUpdated()) {
    latitude = gps.location.lat();
    longitude = gps.location.lng();
  }
  // Send the location to the Telegram bot
  String locationMessage = "Location: " + String(latitude, 6) + ", " + String(longitude, 6);
  bot.sendMessage(CHAT_ID, locationMessage.c_str(), "");
}

And in the serial monitor this appeared

13:06:26.270 -> ets Jun  8 2016 00:22:57
13:06:26.274 -> 
13:06:26.277 -> rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
13:06:26.280 -> configsip: 0, SPIWP:0xee
13:06:26.284 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
13:06:26.288 -> mode:DIO, clock div:1
13:06:26.291 -> load:0x3fff0018,len:4
13:06:26.295 -> load:0x3fff001c,len:928
13:06:26.299 -> ho 0 tail 12 room 4
13:06:26.303 -> load:0x40078000,len:8740
13:06:26.307 -> load:0x40080400,len:5788
13:06:26.311 -> entry 0x4008069c
13:06:34.609 -> ets Jun  8 2016 00:22:57
13:06:34.617 -> 
13:06:34.622 -> rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
13:06:34.629 -> configsip: 0, SPIWP:0xee
13:06:34.635 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
13:06:34.641 -> mode:DIO, clock div:1
13:06:34.647 -> load:0x3fff0018,len:4
13:06:34.653 -> load:0x3fff001c,len:928
13:06:34.659 -> ho 0 tail 12 room 4
13:06:34.665 -> load:0x40078000,len:8740
13:06:34.670 -> load:0x40080400,len:5788
13:06:34.675 -> entry 0x4008069c

while (swSer.available() > 0)
    gps.encode(swSer.read());
      {
    delay(100);
  }

Your brackets are in the wrong place.

Well, where should they be placed?
or delete them

That absolutely, but just for future reference on adding 'yield()'
At the end of loop() (so basically when the function is exited) yield() is called automatically,
So even though

loop() {
  if (something) return;
}

yield(0 doesn't appear to be called but it is.

Also when calling delay(), yield() is called automatically.
In fact, delay looks something like this

void delay(uint32_t wait) {
  uint32_t moment = millis();
  do {
      yield();
  } while (millis() - moment < wait)
}

delayMicroseconds() doesn't call yield();

yield() executes scheduled tasks and resets the wdt.

1 Like

Type CTRL+T and let the IDE format your code properly.

1 Like

They should surround whatever lines of code were intended to be within the while() loop.

1 Like

Try one of the three rules of programming (not in order of importance):

  1. Backup.
  2. Backup.
  3. Backup.
1 Like

Or version control: Git, SVN...

1 Like

Did you write this code yourself, or have you copied/pasted it from some other source?

If it is not your code, can you please post a link to where it came from?

Can you please tell us your electronics, programming, arduino, hardware experience?

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

1 Like

I have tried everything you mentioned, but unfortunately there is no point or benefit
I deleted the part about the GPS and completely dispensed with it, but the same thing appears in the serial monitor.
After all, I wrote another code, that's it

#include <Arduino.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <UniversalTelegramBot.h>
#include <Adafruit_Sensor.h>
#include <TinyGPS.h>
#include <IRremote.h>

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

#define BOT_TOKEN "*********"
#define CHAT_ID "********"

WiFiClient client;
UniversalTelegramBot bot(BOT_TOKEN, client);

#define CAM_SCL 21
#define CAM_SDA 22
#define CAM_VSYNC 23
#define CAM_HREF 25
#define CAM_D0 26
#define CAM_D1 27
#define CAM_D2 14
#define CAM_D3 12
#define CAM_D4 13
#define CAM_D5 15
#define CAM_D6 2
#define CAM_D7 0
#define CAM_RESET 4
#define CAM_PWDN 5

#define MIC_SEL 34
#define MIC_LRCL 35
#define MIC_DOUT 32
#define MIC_BCLK 33

#define GPS_PPS 19
#define GPS_RXD TXD0 
#define GPS_TXD RXD0

#define IR_RECEIVER 18

#define TAKE_PHOTO 0x1FE807F
#define START_AUDIO 0x1FE40BF
#define STOP_AUDIO 0x1FE20DF
#define START_VIDEO 0x1FEC03F
#define STOP_VIDEO 0x1FE20DF
#define GET_LOCATION 0x1FEF807


IRrecv irrecv(IR_RECEIVER);
decode_results results;

TinyGPS gps;

void setup() {

Serial.begin(115200);

WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}

Serial.println("Connected to WiFi");

irrecv.enableIRIn();

}

void loop() {

if (irrecv.decode(&results)) {
  if (results.value == TAKE_PHOTO) {
  // Code to take photo with camera module
  Serial.println("Taking photo..."); 
  
  // Code to send photo to Telegram bot
  bot.sendMessage(CHAT_ID, "Photo", "");
}
if (results.value == START_AUDIO) {
  // Code to start audio recording
  
  Serial.println("Starting audio recording...");
}

if (results.value == STOP_AUDIO) {  
  // Code to stop audio recording

  Serial.println("Stopping audio recording...");
  
  // Code to send audio clip to Telegram bot
  bot.sendMessage(CHAT_ID, "Audio", "");    
}

if (results.value == START_VIDEO) {
  // Code to start video recording
  
  Serial.println("Starting video recording...");
}

if (results.value == STOP_VIDEO) {
  // Code to stop video recording
  
  Serial.println("Stopping video recording...");

  // Code to send video to Telegram bot  
  bot.sendMessage(CHAT_ID, "Video", "");   
}

if (results.value == GET_LOCATION) {
  Serial.println("Getting GPS location...");
  
  // Code to get GPS location 
  
  // Code to send location to Telegram bot
  bot.sendMessage(CHAT_ID, "Location", "");
}

irrecv.resume(); 
}

}

And this code works well but it only sends a text message whether it is a picture word or a audio word or a video word or a location word.
And all I want is to send the real data, not just text.