• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » Base64 Encoding on ESP32 Arduino (Base64 for Images)

By Abhishek Ghosh March 12, 2019 6:40 pm Updated on March 12, 2019

Base64 Encoding on ESP32 Arduino (Base64 for Images)

Advertisement

Base64 images are easy to transmit over the network. Base64 encoding of images for CSS is highly discussed on our blog. Base64 is not new to our regular readers but the current application is different. Here is How to Use Base64 Encoding on ESP32 Arduino.

ESP32 lacks sufficient RAM which limits the actual capabillity. You can actually use HTTP POST (like we have shown with IBM Watson IoT Platform) to send data to IBM’s server. IBM IoT also has limit of sending images (you have to use bin instead of JSON/text).

Base64 Encoding on ESP32 Arduino

Original Arduino’s way of Base64 is the below (which many readers at least used for different projects):

Advertisement

---

Vim
1
2
3
4
5
6
7
8
9
10
#include <base64.h>
void setup() {
  Serial.begin(115200);
  String toEncode = "Hello World";
  String encoded = base64::encode(toEncode);
  Serial.println(encoded);
}
void loop() {}

ESP32 Arduino officially has the required library for basic functions around Base64 :

Vim
1
https://github.com/espressif/arduino-esp32/blob/a59eafbc9dfa3ce818c110f996eebf68d755be24/tools/sdk/include/wpa_supplicant/crypto/base64.h

Decoding a Base64 will go like this :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
extern "C" {
#include "crypto/base64.h"
}
void setup() {
  Serial.begin(115200);
  char * toDecode = "paste--base64---code--here";
  size_t outputLength;
  unsigned char * decoded = base64_decode((const unsigned char *)toDecode, strlen(toDecode), &amp;outputLength);
  Serial.print("Length of decoded message: ");
  Serial.println(outputLength);
  Serial.printf("%.*s", outputLength, decoded);
  free(decoded);
}
void loop() {}

Encoding of the phrase Hello World! will be in this way :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
extern "C" {
#include "crypto/base64.h"
}
void setup() {
  Serial.begin(115200);
  char * toEncode = "Hello World";
  size_t outputLength;
  unsigned char * encoded = base64_encode((const unsigned char *)toEncode, strlen(toEncode), &amp;outputLength);
  Serial.print("Length of encoded message: ");
  Serial.println(outputLength);
  Serial.printf("%.*s", outputLength, encoded);
  free(encoded);
}
void loop() {}

One can change ESP32 camera’s input to Base64 in this way :

Vim
1
2
3
4
5
6
7
8
9
10
size_t size = image.size;
const uint8_t* image = image.data;
 
uint8_t *buffer = calloc((size + 2 - ((size + 2) % 3)) / 3 * 4 + 1, sizeof(char));   // <--- equation from internet
size_t buff_size = 0;
int err = mbedtls_base64_encode(buffer, (size + 2 - ((size + 2) % 3)) / 3 * 4 + 1, &buff_size, image, size);
if (err != 0) {
ESP_LOGE(TAG, "error base64 encoding, error %d, buff size: %d", err, buff_size);  
return;
}

I beleive that using other kind of microprocessors with higher RAM is practical if the purpose is sending reasonable size image over web services, email. Camera with ESP32 with IoT works actually pushes it towards the end of capabillity due to hardware restriction. It is not abnormal to get hanged! You can resize image to tiny and send it.

Tagged With base64 for windows , arduino base64 decode esp32 , base64 arduino DECODE IMAGE , arfiomo bade64 omage , arduino mac libraries b64 , arduino encoder image base 64 , arduino crypto base64 , arduino base64 image , arduino base64 encode jpeg , https://thecustomizewindows com/2019/03/base64-encoding-on-esp32-arduino-base64-for-images/
Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Base64 Encoding on ESP32 Arduino (Base64 for Images)

  • How to Control Multiple Relays With Single Arduino ESP32?

    Before How to Control Multiple Relays With Single Arduino ESP32 Testing, You Need to Learn How to Create Multiple MQTT Channels & Fetch Data.

  • WROOM ESP32 Example Codes For IBM Watson IoT Platform

    Here Are Few WROOM ESP32 Example Codes For IBM Watson IoT Platform So That Anyone Can Get Started With Both of Them Without Huge Experience.

  • Nginx WordPress Installation Guide (All Steps)

    This is a Full Nginx WordPress Installation Guide With All the Steps, Including Some Optimization and Setup Which is Compatible With WordPress DOT ORG Example Settings For Nginx.

  • Connecting ESP32 Arduino with DHT11 with IBM Watson IoT

    Earlier, we described how to create graph on IBM Watson IoT dashboard by using the default widgets. In previous guide, we described how to use ESP32 Arduino with DHT11 sensor. Here is the Code and Diagram to Connect ESP32 Arduino with DHT11 with IBM Watson IoT and Get Odometer Like Gauges on Dashboard. For this […]

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Hybrid Multi-Cloud Environments Are Becoming UbiquitousJuly 12, 2023
  • Data Protection on the InternetJuly 12, 2023
  • Basics of BJT TransistorJuly 11, 2023
  • What is Confidential Computing?July 11, 2023
  • How a MOSFET WorksJuly 10, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy