hasanhatem's avatar

How to connect qr code scanner machine with my website laravel and react

Hello guy,

I have project, so all the users will have unique QR Code it will be generated depend on the user id

so when the user use this qr code the website will recognize him depend on the id in this qr code so know the problem is with the qr code reader, if i have this reader

qr code reader (This image from amazon)

this device we can use it with computer by USB

so how can i get the data from this device and send it to the website to recognize the user id .. the website will be open on the browser all the time.

i am using React Js, with laravel 9 in the backend

Thanks ☺️

0 likes
13 replies
Snapey's avatar

This is a 'keyboard wedge' interface, so plug it into USB, configure it by scanning on the barcodes then when you have a form input field, put your cursor on it and scan the QR code.

At the end of the day, a QR code is just a string of text that will be pasted into anything waiting for keyboard input

1 like
hasanhatem's avatar

@Snapey I am so sorry bro, I'm a little confused. Because it's first time using this device.

There is a lot of libraries and packages working with (webcam) its give you the QR string direct in your code (ex: to any variable you want), without any form and input.

Can i do that with the QR device, or i should have form input??

And should I use webcam with library, or this device can do what i want?

I wanna use this device to scan user QR code and when the user scan the code i will start the quiz questions directly without password.

So the user will click on Start Quiz Button on Touch screen, after that he should scan the QR Code, after the system recognize him, the quiz will start directly.

I can do all that with the any package using webcam but it will not give you a good performance. That's the reason i wanna use Scanner Device.

hasanhatem's avatar

@Snapey Today i will get the device and i will try handle it. I will back to you with the result. Thank you very much for the helping

Tomorrow evening i will back to let you know the result

hasanhatem's avatar

@Snapey Hello bro, i listen to the qr code scanner. I got the data from the qr code. with ('keypress') event. but it's like an array it's loop in string and console it letter by letter. it's ok i can combine this letters together but how to know when the string finish to set it in state or fetch data from api depend on that string.

is there any way to know?

this is my code:

document.addEventListener('keypress', (event) => {
        var name = event.key;
        var code = event.code;
        console.log(`Key pressed ${name} \r\n Key code value: ${code}`);
    }, false);
Snapey's avatar

@hasanhatem two thoughts

  1. add a timeout function when the stream stops, send it to your API

  2. contact the vendor. ask them if there is a way to program the scanner to send additional character at the end of the scan such as enter key

1 like
hasanhatem's avatar

@Snapey I solve the problem. So when I tested the device i found every string i get it from the qr code the device add ENTER to the end of the string. So i thing this is a good way to handle this issue

useEffect(() => {
        if (!isScaned) {
            const detectKeyboard = (e) => {
                var name = e.key;

                if (name !== 'Enter') {
                    tempString += name;
                }
                if (name === 'Enter' && qrCode !== tempString) {
                    setQrCode(tempString);
                    setIsScaned(true);
                    console.log('sd');
                }
            }

            document.addEventListener('keypress', detectKeyboard, false);

            return () => {
                document.removeEventListener('keypress', detectKeyboard, false);
            }
        }

    }, [isScaned]);
Snapey's avatar

Thats good. Please mark it as solved

1 like

Please or to participate in this conversation.