Skip to content

Open-Authenticator/qr-code-generator-component

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

qr-code-generator

library to generate the bitmap array of qrcode on esp32.

Table of Contents

About the QR code

A QR code is a machine-readable matrix barcode and it stands for “quick response” code.You can use the camera app on any phone to scan a QR code. It can store the data of about 4kb.

Version

The version of a QR code is a number between 1 and 40 (inclusive), which indicates the size of the QR code. The width and height of a QR code are always equal (it is square) and are equal to 4 * version + 17. To get more information on size refer Data Capacities

Error Correction

The level of error correction is a number between 0 and 3 (inclusive), or can be one of the symbolic names ECC_LOW, ECC_MEDIUM, ECC_QUARTILE and ECC_HIGH. Higher levels of error correction sacrifice data capacity, but allow a larger portion of the QR code to be damaged or unreadable. The level of Error correction supported are listed below

qrcodegen_Ecc_LOW = 0 ,  // The QR Code can tolerate about  7% erroneous codewords
qrcodegen_Ecc_MEDIUM  ,  // The QR Code can tolerate about 15% erroneous codewords
qrcodegen_Ecc_QUARTILE,  // The QR Code can tolerate about 25% erroneous codewords
qrcodegen_Ecc_HIGH    ,  // The QR Code can tolerate about 30% erroneous codewords

Mode

The mode of a QR code is determined by the data being encoded. Each mode is encoded internally using a compact representation, so lower modes can contain more data.

  • NUMERIC: numbers (0-9)
  • ALPHANUMERIC: uppercase letters (A-Z), numbers (0-9), the space ( ), dollar sign ($), percent sign (%), asterisk (*), plus (+), minus (-), decimal point (.), slash (/) and colon (:).
  • BYTE: any character The modes supported are as follows
qrcodegen_Mode_NUMERIC      = 0x1,
qrcodegen_Mode_ALPHANUMERIC = 0x2,
qrcodegen_Mode_BYTE         = 0x4,

Generating QR code

The Qr code can be generated by using the following functions

bool qrcodegen_encodeText(const char *text, uint8_t tempBuffer[], uint8_t qrcode[],enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl)
  • Arguments
    • text: text to be encoded in the qrcode
    • tempBuffer: temporary buffer to hold qrcode Data
    • qrcode : buffer that will contain the qrcode Data
    • ecl : Error Correction level
    • minVersion : minimum version of QR codd to generate
    • maxVersion : maximum version of QR codd to generate
    • mask : masking of QR code, for automatic implementation put mask=-1
    • boostEcl : boost error correction level if true

Bitmap

The bitmap is the type of image formating like png, jpeg etc.. In embedded systems to display the QR code on the displays like Oled , led, we need to have the bitmap array of the qrcode. To get the bitmap array we used this function:-

void qrcode_to_bitmap(const uint8_t qrcode[],uint8_t *arr_bitmap,uint8_t version)
  • Arguments
  • qrcode :buffer that contains the qrcode Data
  • arr_bitmap : The array that will contain the bitmap data
  • version : The version of the QR code

Example Usage

#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "esp_log.h"

#include "qrcodegen.h"
#include "bitmap.h"

#define TAG "QRCODE"

int app_main()
{

   // Text to be written as QRcode
   const char *text = "http:192.168.1.1";

   // setting the error correction level
   enum qrcodegen_Ecc errCorLvl = qrcodegen_Ecc_LOW;

   // setting the version of the qrcode
   uint8_t version = 1;

   // creating the qrcode buffer
   uint8_t qrcode[qrcodegen_BUFFER_LEN_FOR_VERSION(version)];
   uint8_t tempBuffer[qrcodegen_BUFFER_LEN_FOR_VERSION(version)];

   // creating the QR code
   bool ok = qrcodegen_encodeText(text, tempBuffer, qrcode, errCorLvl, version, version, qrcodegen_Mask_AUTO, true);
   if (ok)
   {
      ESP_LOGI(TAG, "QRcode successfully created");
   }

   uint8_t size = qrcodegen_getSize(qrcode);

   uint8_t arr_bitmap[(size * ((2 * size + 7) / 8))];
   memset(arr_bitmap, 0, sizeof(arr_bitmap));

   // converting the qrcode buffer to bitmap array
   qrcode_to_bitmap(qrcode, (uint8_t *)&arr_bitmap, version);

   // printing the bitmap array
   printf("Bitmap Array:-\n");
   for (int i = 0; i < sizeof(arr_bitmap); i++)
   {
      printf("%d ,", arr_bitmap[i]);
   }

   return 0;
}

Data Capacities


Version Size Error Correction Mode
Numeric Alphanumeric Byte
1 21 x 21 LOW412517
MEDIUM342014
QUARTILE271611
HIGH17107
2 25 x 25 LOW774732
MEDIUM633826
QUARTILE482920
HIGH342014
3 29 x 29 LOW1277753
MEDIUM1016142
QUARTILE774732
HIGH583524
4 33 x 33 LOW18711478
MEDIUM1499062
QUARTILE1116746
HIGH825034
5 37 x 37 LOW255154106
MEDIUM20212284
QUARTILE1448760
HIGH1066444
6 41 x 41 LOW322195134
MEDIUM255154106
QUARTILE17810874
HIGH1398458
7 45 x 45 LOW370224154
MEDIUM293178122
QUARTILE20712586
HIGH1549364
8 49 x 49 LOW461279192
MEDIUM365221152
QUARTILE259157108
HIGH20212284
9 53 x 53 LOW552335230
MEDIUM432262180
QUARTILE312189130
HIGH23514398
10 57 x 57 LOW652395271
MEDIUM513311213
QUARTILE364221151
HIGH288174119
11 61 x 61 LOW772468321
MEDIUM604366251
QUARTILE427259177
HIGH331200137
12 65 x 65 LOW883535367
MEDIUM691419287
QUARTILE489296203
HIGH374227155
13 69 x 69 LOW1022619425
MEDIUM796483331
QUARTILE580352241
HIGH427259177
14 73 x 73 LOW1101667458
MEDIUM871528362
QUARTILE621376258
HIGH468283194
15 77 x 77 LOW1250758520
MEDIUM991600412
QUARTILE703426292
HIGH530321220
16 81 x 81 LOW1408854586
MEDIUM1082656450
QUARTILE775470322
HIGH602365250
17 85 x 85 LOW1548938644
MEDIUM1212734504
QUARTILE876531364
HIGH674408280
18 89 x 89 LOW17251046718
MEDIUM1346816560
QUARTILE948574394
HIGH746452310
19 93 x 93 LOW19031153792
MEDIUM1500909624
QUARTILE1063644442
HIGH813493338
20 97 x 97 LOW20611249858
MEDIUM1600970666
QUARTILE1159702482
HIGH919557382
21 101 x 101 LOW22321352929
MEDIUM17081035711
QUARTILE1224742509
HIGH969587403
22 105 x 105 LOW240914601003
MEDIUM18721134779
QUARTILE1358823565
HIGH1056640439
23 109 x 109 LOW262015881091
MEDIUM20591248857
QUARTILE1468890611
HIGH1108672461
24 113 x 113 LOW281217041171
MEDIUM21881326911
QUARTILE1588963661
HIGH1228744511
25 117 x 117 LOW305718531273
MEDIUM23951451997
QUARTILE17181041715
HIGH1286779535
26 121 x 121 LOW328319901367
MEDIUM254415421059
QUARTILE18041094751
HIGH1425864593
27 125 x 125 LOW351721321465
MEDIUM270116371125
QUARTILE19331172805
HIGH1501910625
28 129 x 129 LOW366922231528
MEDIUM285717321190
QUARTILE20851263868
HIGH1581958658
29 133 x 133 LOW390923691628
MEDIUM303518391264
QUARTILE21811322908
HIGH16771016698
30 137 x 137 LOW415825201732
MEDIUM328919941370
QUARTILE23581429982
HIGH17821080742
31 141 x 141 LOW441726771840
MEDIUM348621131452
QUARTILE247314991030
HIGH18971150790
32 145 x 145 LOW468628401952
MEDIUM369322381538
QUARTILE267016181112
HIGH20221226842
33 149 x 149 LOW496530092068
MEDIUM390923691628
QUARTILE280517001168
HIGH21571307898
34 153 x 153 LOW525331832188
MEDIUM413425061722
QUARTILE294917871228
HIGH23011394958
35 157 x 157 LOW552933512303
MEDIUM434326321809
QUARTILE308118671283
HIGH23611431983
36 161 x 161 LOW583635372431
MEDIUM458827801911
QUARTILE324419661351
HIGH252415301051
37 165 x 165 LOW615337292563
MEDIUM477528941989
QUARTILE341720711423
HIGH262515911093
38 169 x 169 LOW647939272699
MEDIUM503930542099
QUARTILE359921811499
HIGH273516581139
39 173 x 173 LOW674340872809
MEDIUM531332202213
QUARTILE379122981579
HIGH292717741219
40 177 x 177 LOW708942962953
MEDIUM559633912331
QUARTILE399324201663
HIGH305718521273

Acknowledgement

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published