Saving data to feed causes ESP32 to reset

Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Locked
User avatar
AaronHe
 
Posts: 5
Joined: Sat Jul 09, 2022 6:20 am

Saving data to feed causes ESP32 to reset

Post by AaronHe »

Hi all! I'm new to Adafruit IO and have been test driving numerous example sketches on my ESP32 boards and for the most part I have been having great success however I am stuck with one issue in uploading an image from my WROVER board that uses an OV2640 camera that I was hoping someone might be able to help me with.

The board resets with the following when the line "cameraFeed->save(encrypt)" is executed:

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13516
load:0x40080400,len:3604
entry 0x400805f0


If I grab the value of "encrypt" and upload it to the feed data via the API (https://io.adafruit.com/api/v2/<myUsern ... key=<myKey>) the image saves and displays fine so I am certain the base64 value is ok.

Hopefully I have just done something stupid in my code and one of you awesome gurus out there can steer me right.


Here's my code:

Code: Select all

#include "config.h"
#include "esp_camera.h"
#include "base64.h"

#define PWDN_GPIO_NUM    -1
#define RESET_GPIO_NUM   -1
#define XCLK_GPIO_NUM    21
#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      19
#define Y4_GPIO_NUM      18
#define Y3_GPIO_NUM       5
#define Y2_GPIO_NUM       4
#define VSYNC_GPIO_NUM   25
#define HREF_GPIO_NUM    23
#define PCLK_GPIO_NUM    22

unsigned long lastUpdate;
camera_config_t config;
AdafruitIO_Feed *cameraFeed = io.feed("camera");

void setup() {
  Serial.begin(115200);
  Serial.setDebugOutput(true);
  Serial.println();

  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;
  config.frame_size = FRAMESIZE_SVGA;
  config.jpeg_quality = 12;
  config.fb_count = 1;

  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();
  } else {
    Serial.println("Camera configuration complete!");
  }

  sensor_t * s = esp_camera_sensor_get();
  s->set_framesize(s, FRAMESIZE_CIF);  // UXGA|SXGA|XGA|SVGA|VGA|CIF|QVGA|HQVGA|QQVGA

  Serial.print("Connecting to Adafruit IO");
  io.connect();
  while(io.status() < AIO_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println();
  Serial.println(io.statusText());

  log_d("Total heap: %d", ESP.getHeapSize());
  log_d("Free heap: %d", ESP.getFreeHeap());
  log_d("Total PSRAM: %d", ESP.getPsramSize());
  log_d("Free PSRAM: %d", ESP.getFreePsram());
  
}

void loop() {
  io.run();
  if (millis() > (lastUpdate + 5000)) {
    camera_fb_t *fb = NULL;
    fb = esp_camera_fb_get();
    if (fb != NULL) {
      String encrypt = base64::encode(fb->buf, fb->len);
      esp_camera_fb_return(fb);
      Serial.println(encrypt);
      cameraFeed->save(encrypt);      
    } else {
      Serial.println("Camera Error");
    }
    lastUpdate = millis();
  }  
}


User avatar
brubell
Learn User Page
 
Posts: 2010
Joined: Fri Jul 17, 2015 10:33 pm

Re: Saving data to feed causes ESP32 to reset

Post by brubell »

Hi, the stack trace from the ESP32 is unfortunately not helpful without the decoded output.

Install https://github.com/me-no-dev/EspExceptionDecoder and follow the usage steps (https://github.com/me-no-dev/EspExceptionDecoder#usage). You should end up with a human-readable error output. Please copy and paste that here so someone can assist you.

User avatar
AaronHe
 
Posts: 5
Joined: Sat Jul 09, 2022 6:20 am

Re: Saving data to feed causes ESP32 to reset

Post by AaronHe »

Thanks brubell. Here's the decoded output of the backtrace:

0x40083901: panic_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/panic.c line 402
0x4008d379: esp_system_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/esp_system.c line 128
0x400928fd: __assert_func at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/assert.c line 85
0x40083d5e: heap_caps_free at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/heap_caps.c line 324
0x4009292d: free at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/heap.c line 39
0x400dbc16: String::invalidate() at C:\Users\aaron\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h line 343
0x400dbc25: String::~String() at C:\Users\aaron\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32\WString.cpp line 159
0x400d3f9b: AdafruitIO_Feed::save(String, double, double, double) at C:\Users\aaron\Documents\Arduino\libraries\Adafruit_IO_Arduino\src\AdafruitIO_Feed.cpp line 152
0x400d37ba: loop() at C:\Users\aaron\Desktop\adadfruit_io_camera_test/adadfruit_io_camera_test.ino line 93
0x400dc0fd: loopTask(void*) at C:\Users\aaron\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32\main.cpp line 50

User avatar
brubell
Learn User Page
 
Posts: 2010
Joined: Fri Jul 17, 2015 10:33 pm

Re: Saving data to feed causes ESP32 to reset

Post by brubell »

Could you isolate part of the code which sends the camera feed's string out of the code (make a new sketch and try sending the b64 string to IO)?

User avatar
AaronHe
 
Posts: 5
Joined: Sat Jul 09, 2022 6:20 am

Re: Saving data to feed causes ESP32 to reset

Post by AaronHe »

Thanks for the advice brubell. I stripped the code back however it still crashed. Here's my code, however I had to remove the value of "encrpyt" as the forum rules would not let me post it (it violated the banned spam rules):

Code: Select all

#include "config.h"
AdafruitIO_Feed *cameraFeed = io.feed("camera");

void setup() {
  Serial.begin(115200);
  Serial.setDebugOutput(true);
  Serial.println();
  Serial.print("Connecting to Adafruit IO");
  io.connect();
  while(io.status() < AIO_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  String encrypt = "<base64 encoded string>";
  cameraFeed->save(encrypt); 
}

void loop() {
 
}
Decoding stack results:
0x40083a5b: find_containing_heap at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/heap_caps.c line 316
0x40083bf9: heap_caps_free at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/heap_caps.c line 338
0x40091c95: free at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/heap.c line 39
0x400d6b96: String::invalidate() at C:\Users\aaron\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32/WString.h line 343
0x400d6ba5: String::~String() at C:\Users\aaron\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32\WString.cpp line 159
0x400d2df3: AdafruitIO_Feed::save(String, double, double, double) at C:\Users\aaron\Documents\Arduino\libraries\Adafruit_IO_Arduino\src\AdafruitIO_Feed.cpp line 152
0x400d274e: setup() at C:\Users\aaron\Desktop\adadfruit_io_camera_test_basic/adadfruit_io_camera_test_basic.ino line 15
0x400d6eaa: loopTask(void*) at C:\Users\aaron\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\cores\esp32\main.cpp line 42

User avatar
brubell
Learn User Page
 
Posts: 2010
Joined: Fri Jul 17, 2015 10:33 pm

Re: Saving data to feed causes ESP32 to reset

Post by brubell »

You could try increasing the MQTT library's max buffer size, https://github.com/adafruit/Adafruit_MQ ... QTT.h#L110

User avatar
AaronHe
 
Posts: 5
Joined: Sat Jul 09, 2022 6:20 am

Re: Saving data to feed causes ESP32 to reset

Post by AaronHe »

Thanks again brubell. I tried increasing the value of MAXBUFFERSIZE from the default 150 in small increments up to 300 and I also tried much larger values up to 4096 and unfortunately it still isn't working.

User avatar
brubell
Learn User Page
 
Posts: 2010
Joined: Fri Jul 17, 2015 10:33 pm

Re: Saving data to feed causes ESP32 to reset

Post by brubell »

AaronHe wrote:Thanks again brubell. I tried increasing the value of MAXBUFFERSIZE from the default 150 in small increments up to 300 and I also tried much larger values up to 4096 and unfortunately it still isn't working.
Could you try sending the data using the Adafruit MQTT library only, to isolate the issue, https://github.com/adafruit/Adafruit_MQTT_Library

User avatar
AaronHe
 
Posts: 5
Joined: Sat Jul 09, 2022 6:20 am

Re: Saving data to feed causes ESP32 to reset

Post by AaronHe »

Hi again brudbell, I can confirm that using the Adafruit MQTT library works fine.
In my test, the MAXBUFFERSIZE had to be increased to 12500 otherwise the value was truncated to 125 chars.

Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”