# QR-code scanner fails at second scan

**URL:** <https://discourse.nodered.org/t/qr-code-scanner-fails-at-second-scan/55037>\
**Category:** General\
**Created:** [11 December 2021 10:44 UTC](https://discourse.nodered.org/t/qr-code-scanner-fails-at-second-scan/55037 "2021-12-11T10:44:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tbobek](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tbobek/32/45711_2.png) [@tbobek](https://discourse.nodered.org/u/tbobek)\
**Post date:** [11 December 2021 10:44 UTC](https://discourse.nodered.org/t/qr-code-scanner-fails-at-second-scan/55037/1 "2021-12-11T10:44:24Z")

</div>

## The problem

Currently I'm setting up a Node-red app to allow colleagues in the plant to scan three QR-codes from product, batch and template, check if the components fit together and send a feedback about the success of the check. This process is repeated every time new components need to be combined. A reset button is used to empty the input fields before each scanning procedure.

The hardware used is a _Inateck BCST-51_ scanner ([product page](https://www.inateck.de/products/inateck-2d-wired-usb-barcode-scanner-bcst-51)). It is configured to append a Tab character after successful scan.

The simplified flow is like this shown in Fig. 1 below. The flow code is attached.

After starting up the application the scanning procedure is executed perfectly for the first time, stepping through the three input fields by scanning only, without use of the keyboard. An "OK" or "NOT OK" is displayed in the "Validate" group. As expected, the "RESET" button empties the input fields. Until here, everything is fine.

But, in the second iteration, the validation is not made any more and also the RESET button is not working any more as expected. I can observe in the debug window that the topmost green debug node is receiving an `msg.payload = ""`, so this message should also be received by the text-input nodes. However, the old text remains in the text input fields.

## Things I've tried

1. Re-checked the scanner settings
2. toggled the options for _if message arrives on input, pass through to output_ and also _send value on focus leave_ but unfortunately without success.
3. manually pressing _Return_ in each input field puts the text input into the initial state again. After this "treatment", the validation is made again, but only once.

## My questions

I'd be glad if someone has a hint on this, I'm somehow lost.

- What prevents the insertion of the empty string into the text field at the second time? Can the text-input be resetted in another manner?
- Why isn't the text input sending a message upon _focus leave_ when the QR-code scanner sends tab and the cursor indeed moves to the next text input?

Thanks in advance for any comments on that!!!

Below I've added screenshots, flow code and also the QR-codes used in this reduced app.

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/b/1b67d488291b26a2571105d6d4c07a0a8b00659e.png)  
Figure 1: flow of the reduced app

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/1/f1a766218d91754928c8d29e45e2306cd7e2ad4a.png)  
Figure 2: Screenshot of the reduced app

[flows.json](https://discourse.nodered.org/uploads/short-url/f97e2AVWg6qdZWwGU92SJgW9T5r.json) (9.2 KB)

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/0/904906636a31f57a670264d9bdea03297bcc91c1.png)  
Figure 3: QR-codes used

I'm using NodeRed version 2.1.4. Firstly I ran the above app on a Raspberry Pi 4, now also on a Linux x86\_64 PC.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [11 December 2021 11:32 UTC](https://discourse.nodered.org/t/qr-code-scanner-fails-at-second-scan/55037/2 "2021-12-11T11:32:38Z")

</div>

Can you provide step by step instructions for recreating the issue with your example flow.

---

<div class="post-metadata">

**Author:** ![tbobek](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tbobek/32/45711_2.png) [@tbobek](https://discourse.nodered.org/u/tbobek)\
**Post date:** [11 December 2021 13:19 UTC](https://discourse.nodered.org/t/qr-code-scanner-fails-at-second-scan/55037/3 "2021-12-11T13:19:20Z")

</div>

@zenofmud Thanks for your interest! I've uploaded a video with the scanning sequence (2x) [here](https://share.vidyard.com/watch/EDWUfuUDSLqUAuPGr4wnkc?)  
The sound (klicking) and the appearing text in the input boxes indicate the moments when the QR-code is scanned. You should see the following:

1. The scanning of PRODUCTCODE, BATCHCODE, TEMPLATECODE
2. RESET pressed
  - input fields are empty (placeholders visible)
  - fields on the right side change to NOT OK (due to message from input text)

3. 2nd scanning cycle of PRODUCT-, BATCH- and TEMPLATECODE
4. **UNEXPECTED** : validation fields on the right side are not updated
5. RESET pressed
6. **UNEXPECTED** : input fields are not emptied

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [11 December 2021 14:01 UTC](https://discourse.nodered.org/t/qr-code-scanner-fails-at-second-scan/55037/4 "2021-12-11T14:01:53Z")

</div>

What node are you using to get the data from the reader?  
What do you see if you connect a debug node to the output of that node?

---

<div class="post-metadata">

**Author:** ![tbobek](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tbobek/32/45711_2.png) [@tbobek](https://discourse.nodered.org/u/tbobek)\
**Post date:** [11 December 2021 14:53 UTC](https://discourse.nodered.org/t/qr-code-scanner-fails-at-second-scan/55037/5 "2021-12-11T14:53:11Z")

</div>

The reader behaves like a keyboard, there is no node for this. Placing the cursor in the input field is sufficient to start scanning. So the characters appearing there are directly from the scanner

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [11 December 2021 15:25 UTC](https://discourse.nodered.org/t/qr-code-scanner-fails-at-second-scan/55037/6 "2021-12-11T15:25:34Z")

</div>

If you set the delay to 200 or 300 ms, it will send the text out after you stop typing. Also, set the inputs to pass `msg` though, then there is no need to wire the `text` nodes with a reset.

Try this flow...

```auto
[{"id":"fdf1a8d47f505c0f","type":"ui_text_input","z":"c6ecb8c5c651ca06","name":"","label":"Product","tooltip":"","group":"bbd7fcca7fad57eb","order":1,"width":0,"height":0,"passthru":true,"mode":"text","delay":"200","topic":"topic","sendOnBlur":true,"topicType":"msg","className":"","x":440,"y":140,"wires":[["82cb81c85b02e721","56429a8ff28f6c67"]]},{"id":"6992b31ef3661c1b","type":"ui_text_input","z":"c6ecb8c5c651ca06","name":"","label":"Batch","tooltip":"","group":"bbd7fcca7fad57eb","order":2,"width":0,"height":0,"passthru":true,"mode":"text","delay":"200","topic":"topic","sendOnBlur":true,"topicType":"msg","className":"","x":430,"y":200,"wires":[["e204f86a9f25fdf7","602e34a53d66468a"]]},{"id":"f90742774a7f1f45","type":"ui_text_input","z":"c6ecb8c5c651ca06","name":"","label":"Template","tooltip":"","group":"bbd7fcca7fad57eb","order":3,"width":0,"height":0,"passthru":true,"mode":"text","delay":"200","topic":"topic","sendOnBlur":true,"topicType":"msg","className":"","x":440,"y":260,"wires":[["597e241f0541dfd3","a49be28ab8d13a5d"]]},{"id":"4b761eb693aff0bd","type":"ui_text","z":"c6ecb8c5c651ca06","group":"f52a3a64c65f6533","order":0,"width":0,"height":0,"name":"","label":"Product","format":"{{msg.payload}}","layout":"row-spread","className":"","x":860,"y":140,"wires":[]},{"id":"82cb81c85b02e721","type":"function","z":"c6ecb8c5c651ca06","name":"validate product","func":"if(msg.payload == \"PRODUCTCODE\") {\n msg.payload = \"OK\"; \n} else {\n msg.payload = \"NOT OK\"; \n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":630,"y":140,"wires":[["4b761eb693aff0bd"]]},{"id":"e204f86a9f25fdf7","type":"function","z":"c6ecb8c5c651ca06","name":"validate batch","func":"if(msg.payload == \"BATCHCODE\") {\n msg.payload = \"OK\"; \n} else {\n msg.payload = \"NOT OK\"; \n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":640,"y":200,"wires":[["62ec9e7f6946f07a"]]},{"id":"597e241f0541dfd3","type":"function","z":"c6ecb8c5c651ca06","name":"validate template","func":"if(msg.payload == \"TEMPLATECODE\") {\n msg.payload = \"OK\"; \n} else {\n msg.payload = \"NOT OK\"; \n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":650,"y":260,"wires":[["d1a0a2a48feac2c0"]]},{"id":"62ec9e7f6946f07a","type":"ui_text","z":"c6ecb8c5c651ca06","group":"f52a3a64c65f6533","order":0,"width":0,"height":0,"name":"","label":"Product","format":"{{msg.payload}}","layout":"row-spread","className":"","x":860,"y":200,"wires":[]},{"id":"d1a0a2a48feac2c0","type":"ui_text","z":"c6ecb8c5c651ca06","group":"f52a3a64c65f6533","order":0,"width":0,"height":0,"name":"","label":"Product","format":"{{msg.payload}}","layout":"row-spread","className":"","x":860,"y":260,"wires":[]},{"id":"254de6d8f80d080e","type":"ui_button","z":"c6ecb8c5c651ca06","name":"","group":"bbd7fcca7fad57eb","order":4,"width":0,"height":0,"passthru":false,"label":"RESET","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":180,"y":220,"wires":[["3d18d30e2b7011b7"]]},{"id":"3d18d30e2b7011b7","type":"change","z":"c6ecb8c5c651ca06","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":315,"y":200,"wires":[["fdf1a8d47f505c0f","6992b31ef3661c1b","f90742774a7f1f45"]],"l":false},{"id":"d3ad5e25c27b5344","type":"inject","z":"c6ecb8c5c651ca06","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":190,"y":160,"wires":[["3d18d30e2b7011b7"]]},{"id":"56429a8ff28f6c67","type":"debug","z":"c6ecb8c5c651ca06","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":320,"wires":[]},{"id":"602e34a53d66468a","type":"debug","z":"c6ecb8c5c651ca06","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":380,"wires":[]},{"id":"a49be28ab8d13a5d","type":"debug","z":"c6ecb8c5c651ca06","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":440,"wires":[]},{"id":"bbd7fcca7fad57eb","type":"ui_group","name":"Input","tab":"612290270848b177","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"f52a3a64c65f6533","type":"ui_group","name":"Validate","tab":"612290270848b177","order":2,"disp":true,"width":"6","collapse":false,"className":""},{"id":"612290270848b177","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![tbobek](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tbobek/32/45711_2.png) [@tbobek](https://discourse.nodered.org/u/tbobek)\
**Post date:** [11 December 2021 15:42 UTC](https://discourse.nodered.org/t/qr-code-scanner-fails-at-second-scan/55037/7 "2021-12-11T15:42:16Z")

</div>

Wow, works like a charm! I always thought I need to set the delay to 0 ms to use the Tab character for sending the message. But that was wrong! Great! Thanks a lot! You made my day!!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [25 December 2021 15:42 UTC](https://discourse.nodered.org/t/qr-code-scanner-fails-at-second-scan/55037/8 "2021-12-25T15:42:39Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
