Solving error Base64 on Arduino IDE

Pls anyone who can help to solve this error code as below?

C:\Users\user\Documents\Arduino\libraries\WaziDev\src\WaziDev.cpp:188:18: error: 'base64_enc_len' was not declared in this scope
int encLen = base64_enc_len(len);
^~~~~~~~~~~~~~
C:\Users\user\Documents\Arduino\libraries\WaziDev\src\WaziDev.cpp:190:5: error: 'base64_encode' was not declared in this scope
base64_encode(h, buf, len);
^~~~~~~~~~~~~

Hi, @davitronix
Welcome to the forum.

To add code please click this link;

Can you please post your code?
What model Arduino are you using?

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

Did you include a Base64 library that defines those functions?

@davitronix it's difficult for others to reproduce your error if you don't post the code that causes it.

Yes I included the Base64 library

This is the code as below

#include <LowPower.h>

#include <WaziDev.h>
#include <xlpp.h>
#include <Base64.h>
//#include <i2c_sI7021.h>

//////////////
#include <DHT.h>
#define DHTPIN 2 // what pin on the arduino is the DHT22 data line connected to
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor for normal Arduino
///////////////

// NwkSKey (Network Session Key) and Appkey (AppKey) are used for securing LoRaWAN transmissions.
// You need to copy them from/to your LoRaWAN server or gateway.
// You need to configure also the devAddr. DevAddr need to be different for each devices!!
// Copy'n'paste the DevAddr (Device Address): 26011D00
unsigned char devAddr[4] = {0x26, 0x01, 0x1D, 0x00};

// Copy'n'paste the key to your Wazigate: 23158D3BBC31E6AF670D195B5AED5525
unsigned char appSkey[16] = {0x23, 0x15, 0x8D, 0x3B, 0xBC, 0x31, 0xE6, 0xAF, 0x67, 0x0D, 0x19, 0x5B, 0x5A, 0xED, 0x55, 0x25};

// Copy'n'paste the key to your Wazigate: 23158D3BBC31E6AF670D195B5AED5525
unsigned char nwkSkey[16] = {0x23, 0x15, 0x8D, 0x3B, 0xBC, 0x31, 0xE6, 0xAF, 0x67, 0x0D, 0x19, 0x5B, 0x5A, 0xED, 0x55, 0x25};

int transm = 1;
int counter =0;

//SI7021 si7021;

WaziDev wazidev;

//int pwr = 6;

int readBase64(const void buf, int len);
//char
h = (char*) malloc(encLen);
//base64_decode(h, buf, len);
//Serial.print(h);
//free(h);
//return encLen

void setup()
{
Serial.begin(38400);
wazidev.setupLoRaWAN(devAddr, appSkey, nwkSkey);
}

XLPP xlpp(120);

void loop(void)
{
//////////////////
float temp = dht.readTemperature();
float hum = dht.readHumidity();
/////////////////
// 1
// Create xlpp payload.

Serial.println(temp);
Serial.println(hum);

delay(500);

xlpp.reset();
xlpp.addTemperature(1, temp); // °C
xlpp.addRelativeHumidity(1, hum); // %
xlpp.addTemperature(2, transm);
// xlpp.addGPS(1, -1.4, 0.234, 34);

// 2.
// Send paload with LoRaWAN.
serialPrintf("LoRaWAN send ... ");
uint8_t e = wazidev.sendLoRaWAN(xlpp.buf, xlpp.len);
if (e != 0)
{
serialPrintf("Err %d\n", e);
delay(60000);
return;
}
serialPrintf("OK\n");

// 3.
// Receive LoRaWAN message (waiting for 6 seconds only).
serialPrintf("LoRa receive ... ");
uint8_t offs = 0;
long startSend = millis();
e = wazidev.receiveLoRaWAN(xlpp.buf, &xlpp.offset, &xlpp.len, 6000);
long endSend = millis();
if (e != 0)
{
if (e == ERR_LORA_TIMEOUT){
serialPrintf("nothing received\n");
}
else
{
serialPrintf("Err %d\n", e);
}
delay(60000);
return;
}
serialPrintf("OK\n");

serialPrintf("Time On Air: %d ms\n", endSend-startSend);
serialPrintf("LoRa SNR: %d\n", wazidev.loRaSNR);
serialPrintf("LoRa RSSI: %d\n", wazidev.loRaRSSI);
serialPrintf("LoRaWAN frame size: %d\n", xlpp.offset+xlpp.len);
serialPrintf("LoRaWAN payload len: %d\n", xlpp.len);
serialPrintf("Payload: ");
char payload[100];
base64_decode(payload, xlpp.getBuffer(), xlpp.len);
serialPrintf(payload);
serialPrintf("\n");

delay(60000);
}

My guess is that you have a second "Base64.h" that doesn't define the same functions as the "Base64.h" from WaziDev. In Preferences, enable "Show verbose output during compilation". That should show you what libraries are included and what libraries aren't.

Hi,
I´m facing the same issue.
This is the sketch i want to run:
Arduino/ESP32-CAM_MQTT.ino at master · fustyles/Arduino (github.com)

and thats the part of Base64:

String sendImage() {
  camera_fb_t * fb = NULL;
  fb = esp_camera_fb_get();  
  if(!fb) {
    Serial.println("Camera capture failed");
    return "Camera capture failed";
  }  

  char *input = (char *)fb->buf;
  char output[base64_enc_len(3)];
  String imageFile = "data:image/jpeg;base64,";
  for (int i=0;i<fb->len;i++) {
    base64_encode(output, (input++), 3);
    if (i%3==0) imageFile += String(output);
  }
  int fbLen = imageFile.length();
  
  String clientId = "ESP32-";
  clientId += String(random(0xffff), HEX);
  if (client.connect(clientId.c_str(), MQTT_USER, MQTT_PASSWORD)) {
    //https://github.com/knolleary/pubsubclient/blob/master/src/PubSubClient.h
    
    client.beginPublish(MQTT_PUBLISH_TOPIC, fbLen, true);

    String str = "";
    for (size_t n=0;n<fbLen;n=n+2048) {
      if (n+2048<fbLen) {
        str = imageFile.substring(n, n+2048);
        client.write((uint8_t*)str.c_str(), 2048);
      }
      else if (fbLen%2048>0) {
        size_t remainder = fbLen%2048;
        str = imageFile.substring(n, n+remainder);
        client.write((uint8_t*)str.c_str(), remainder);
      }
    }  
    
    client.endPublish();
    
    esp_camera_fb_return(fb);
    
    return "";
  }
  esp_camera_fb_return(fb);
  return "failed, rc="+client.state();
}

I did a second fresh install of IDE on a new computer, downloaded just downloaded board informations for ESP32 - same error.

I tried this solution - but still the same error.
error: 'String' does not name a type. (base64.h) · Issue #7516 · esp8266/Arduino (github.com)

The only compile error I get is 'code2' is set but not used. If I comment out the two lines that reference 'code2' (lines 122 and 139) it compiles for "AI Thinker ESP32-CAM".

Did you forget to include the Base64.h and Base64.cpp in the sketch folder?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.