QR-code scanner fails at second scan

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). 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.


Figure 1: flow of the reduced app


Figure 2: Screenshot of the reduced app

flows.json (9.2 KB)


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.

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

@zenofmud Thanks for your interest! I've uploaded a video with the scanning sequence (2x) here
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

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?

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

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...

[{"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}]
1 Like

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!!

1 Like

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