QRCode
QRCode copied to clipboard
Not working with bigger string
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
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.
It is 6, but what it mean? Does this library support it?
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
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.
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.
(sorry clicked the wrong button)
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.
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...
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