Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working with bigger string #9

Open
vforv opened this issue Jul 22, 2019 · 9 comments
Open

Not working with bigger string #9

vforv opened this issue Jul 22, 2019 · 9 comments

Comments

@vforv
Copy link

vforv commented Jul 22, 2019

Hello

I am using ESP8266 and E paper display
Problem is when I want to generate qr code from bigger string, here is my function that generate qr code:

void qrCard(const char *code)
{
  display.fillRect(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, GxEPD_WHITE);
  display.update();

  byte box_x = 33;
  byte box_y = 33;
  byte box_s = 4.5;
  byte init_x = box_x;

  display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, false);

  // Create the QR code
  QRCode qrcode;
  uint8_t qrcodeData[qrcode_getBufferSize(4)];
  qrcode_initText(&qrcode, qrcodeData, 4, 0, code);

  for (uint8_t y = 0; y < qrcode.size; y++)
  {
    // Each horizontal module
    for (uint8_t x = 0; x < qrcode.size; x++)
    {

      // Print each module (UTF-8 \u2588 is a solid block)
      //Serial.print(qrcode_getModule(&qrcode, x, y) ? "\u2588\u2588": "  ");
      if (qrcode_getModule(&qrcode, x, y))
      {
        //Serial.println(py+ps);
        display.fillRect(box_x, box_y, box_s, box_s, GxEPD_BLACK);
      }
      else
      {
        //Serial.println(py+ps);
        display.fillRect(box_x, box_y, box_s, box_s, GxEPD_WHITE);
      }
      box_x = box_x + box_s;
    }
    display.updateWindow(0, box_y, 200, box_s, true);
    box_y = box_y + box_s;
    box_x = init_x;
  }
}

This is string which I try to use to generate qr code:

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb2RlIjoiYjdlODg2NzAtNjJiNi0xMWU5LThlODEtYzk4YzQxODQwMzg4IiwiaWF0IjoxNTYzODAwMDQ0fQ.06H2CZHUoDdezXBFPk4kocK8Qqjgy3zmAR-OgMk4AH0

In console I get this error:

HTTPS Connecting
ets Jan 8 2013,rst cause:4, boot mode:(3,6)

wdt reset
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v8b899c12
~ld
D�Done

Found out that this function creating error:
qrcode_initText

When I use smaller string it works. Any solution for this? Also is it possible to update qr code at once not part by part?

#EDIT: Did little debuging, first time error occure here:

bb_initGrid(&modulesGrid, modules, size); in this function qrcode_initBytes

@Adrianotiger
Copy link

Adrianotiger commented Jul 31, 2019

The longest string (alphanumeric) is 114 with your version: 4 and without error correction: 0.
Even with version 5, you will not be able to show this string.

Check the readme to see what a version you need to show your string of 168 chars.

@vforv
Copy link
Author

vforv commented Jul 31, 2019

It is 6, but what it mean? Does this library support it?

@Adrianotiger
Copy link

Don't know why it is called version.
It is just the size of the QR code. 6 means 17 + [6] * 4 points. The smallstest QR code has 21 points. Then 25, then 29, then 33, ...
Bigger QR codes can contains more characters.

I don't know if it works with 6. I was trying to put my string of 30 characters on a version 2 QR code and it doesn't work with this library. Don't know why. And also the error correction seems that does not work always... Just try :P

@ricmoo
Copy link
Owner

ricmoo commented Jul 31, 2019

I agree, the name “version” is confusing, but that’s the name in the specification. :)

Yes, version 6 should work fine. I’ve tested it with all version numbers and levels against other implementations, and it have. It found any issues. If you have a problem, please include the version, EC level, mode and message and I’ll investigate.

A very common mistake is to use the alphanumeric mode incorrectly; alphanumeric in the QR code specification is VERY strict, and only supports upper case letters and a handful of symbols. So, if you specify alphanumeric with a string like “http://foobar.com”, you have likely just caused a buffer overflow.

When I get a chance, I’ll add more introspection APIs, to discover a strings type and the QR code version required to store it.

@ricmoo
Copy link
Owner

ricmoo commented Jul 31, 2019

Oh, actually. Just checked the code (it’s been quite a while since I’ve worked on it). It won’t buffer overflow. It will return -1 though. So, check the return status of init_*. If it isn’t 0, that means you didn’t provide a big enough hunk of memory for the QR code for that data and you either need to reduce the size of the data, increase the version or decrease the EC level.

@ricmoo ricmoo closed this as completed Jul 31, 2019
@ricmoo ricmoo reopened this Jul 31, 2019
@ricmoo
Copy link
Owner

ricmoo commented Jul 31, 2019

(sorry clicked the wrong button)

@Adrianotiger
Copy link

A very common mistake is to use the alphanumeric mode incorrectly; alphanumeric in the QR code specification is VERY strict, and only supports upper case letters and a handful of symbols. So, if you specify alphanumeric with a string like “http://foobar.com”, you have likely just caused a buffer overflow.

Yes, I was trying to create a WiFi-settings string with ';', upper and lower case characters.
Probably I created always a -1 string and this was not possible to read with the QRcode reader.

@vforv
Copy link
Author

vforv commented Jul 31, 2019

It has not problem with urls but with big string like this:

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb2RlIjoiYjdlODg2NzAtNjJiNi0xMWU5LThlODEtYzk4YzQxODQwMzg4IiwiaWF0IjoxNTYzODAwMDQ0fQ.06H2CZHUoDdezXBFPk4kocK8Qqjgy3zmAR-OgMk4AH0

When I reduce string size it works fine...

Just try to run the code I wrote in my main thread...

@Mike4U
Copy link

Mike4U commented Nov 17, 2019

The error code return alway returns 0. The code says:
// @todo: Return error if data is too big.

I'll make this a new issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants