Code Monkey home page Code Monkey logo

Comments (3)

bblanchon avatar bblanchon commented on May 24, 2024

Hi @BoostedPenguin,

What does the ArduinoJson Troubleshooter say?

Best regards,
Benoit

from arduinojson.

AleksandarGT avatar AleksandarGT commented on May 24, 2024

I can fix the overflow by following the Troubleshooter tips, however I cannot fix the garbage output string. If I hardcode a base64 string in the program itself, without capturing an image and then converting it to base64 the output string is correct. However, if I encode a captured image from the CAM it always produces garbage output.

Printing the value of the encoded string is always correct base64, but when I provide it to jsonDocument the output always goes wrong at a specific place:

/9j/4AAQSkZJRgABAQEAAAAAAAD
/9j/4AAQSkZJRgABAQEr

`

JsonDocument jsonDocument;

Serial.println("Capturing image...");

camera_fb_t *fb = nullptr;

// Skip 3 frames :)
for (int i = 0; i < 5; i++)
{
    fb = esp_camera_fb_get();
    esp_camera_fb_return(fb);
    fb = nullptr;
}

fb = esp_camera_fb_get();

Serial.println("Captured");

if (!fb)
{
    return;
}

String encoded = base64::encode(fb->buf, fb->len);

Serial.println("Encoded...");
// Release the frame buffer
esp_camera_fb_return(fb);
Serial.println("Released");

Serial.println(encoded);
jsonDocument.clear();
jsonDocument["image"] = encoded;
jsonDocument["email"] = "TestEmail";
jsonDocument["deviceName"] = "MyDevice1";
String jsonBody;

jsonDocument.shrinkToFit(); // optional

Serial.println("Serializing");

serializeJson(jsonDocument, jsonBody);
Serial.println("Overflow: " + String(jsonDocument.overflowed()));

Serial.println(jsonBody.substring(0, 80));

Serial.println("Generating HTTP request");

`

from arduinojson.

bblanchon avatar bblanchon commented on May 24, 2024

If I hardcode a base64 string in the program itself, without capturing an image and then converting it to base64 the output string is correct. However, if I encode a captured image from the CAM it always produces garbage output.

This is the sign of a dangling pointer.
What did the Troubleshooter say?

from arduinojson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.