LoginSignup
0
0

More than 1 year has passed since last update.

Arduino: Base64.h の使い方

Last updated at Posted at 2021-08-15

ArduinoUNO で Base64.h を使ってみました。
参考ページ

Base64/examples/Base64Encode/Base64Encode.ino

base64_test/base64_test.ino
// ---------------------------------------------------------------
/*
    base64_test.ino

                        Aug/15/2021
*/
// ---------------------------------------------------------------
#include <Base64.h>

// ---------------------------------------------------------------
void setup()
{
  Serial.begin(19200);
    delay (1000);
    Serial.println("*** start ***");
    delay(500);
    Serial.println("*** Base64 example ***");
    delay(500);

    char Buf[50];

    int llx = 8;
    String str_array[] = {"A","AB","ABC","ABCD","ABCDE","ABCDEF","ABCDEFG",
        "ABCDEFGH"};


Serial.println ("llx = " + String(llx));
delay(1000);

 for (int itt=0; itt < llx; itt++)
 {
        str_array[itt].toCharArray(Buf, 50);    
        String str_encoded = encode_proc(Buf);
        Serial.println(str_encoded);

   delay(300);
        }

    delay(500);
    Serial.println("*** setup *** end ***");
}

// ---------------------------------------------------------------
String encode_proc(char* input)
{
    Serial.println(input);

    int inputLen = strlen(input);

    int encodedLen = Base64.encodedLength(inputLen);
    char encoded[encodedLen];

    Base64.encode(encoded, input, inputLen); 

    return String(encoded);
}

// ---------------------------------------------------------------
void loop()
{
    Serial.println("*** loop ***");
    delay (3000); 
}

// ---------------------------------------------------------------

実行結果

*** start ***
*** Base64 example ***
llx = 8
A
QQ==
AB
QUI=
ABC
QUJD
ABCD
QUJDRA==
ABCDE
QUJDREU=
ABCDEF
QUJDREVG
ABCDEFG
QUJDREVGRw==
ABCDEFGH
QUJDREVGR0g=
*** setup *** end ***
*** loop ***

ライブラリーのインストール方法

ツール -> ライブラリを管理
library_base64.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0