RFID Tag Scanner to enable buttons/menus

Hi

I am trying to disable a button until an RFID tag is scanned with a valid code on it.

I am struggling with this as I am fairly new to Node-Red.

The RFID scanner acts just like a keyboard. I have had it scan into a text entry box on a dashboard page.

I want to be able to look for a valid tag, and enable particular buttons all of the time, without having to display the code on the page. I also do not want someone to have to set focus on a text entry box before they can scan.

Please can anyone assist with pointing me in the right direction for this.

Thanks Loz

1 Like

There are numerous “bits” to this. Which bit can’t you do?
Have you got it working in your dashboard page?
If you have, then look at the standard “switch” node (not the dashboard switch node)

Hi

Thanks for your response. At the moment I can scan a tag to a dashboard text box, which proves the scanner is working and sending information. The problem is you have to set focus to a visible text box.

Really I do not want the text box visible. I would like to scan a tag, and if it is a valid number set a boolean variable to allow certain buttons to become active. This would be like a user entry system, where inly certain features are available if you have tagged in.

Thanks Loz

so as @ukmoose suggests look at the normal (not ui) switch node - in there you can compare the tag with a good value and send to one output or if not send (or not send) to another output - the output can then be used (via a change node or two) to set msg.enabled to true or false to feed the buttons you want to enable/disable.

Thanks again for response. I think we maybe talking at cross purposes here, or I am not explaining myself properly. In short how can I get the data from the RFID scanner without anything showing on the screen. I need a text input that is invisible and in focus all the time in the background.

Ah right... so...

on the Pi we do have a keyboard input node that gets data from the raw keyboard buffer (so doesn't care about focus) - but that is a) only on Pi and b) on server side.

On browser side - I think you would need to use a ui_template so you could add the autofocus property to your own input field... not sure a) if that can then work if set hidden as well and b) how to ensure it stays focussed as you would no doubt want to interact with other parts of the page.

OK. not sure the way forward here.

  1. This is not on a Pi

  2. Server is Ubuntu server

  3. RFID Scanner is connected to a thin client via usb.

Did try the keyboard input node, but did not work as on the thin client, as you point out, and not on the server.

Any other ideas appreciated

As an alternative would it be possible to place a pin number to enable a button when it is first pressed

Does this have to be in the browser, or could the scanning be on the server machine?

The pin would have to be entered in the browser of the thin client, as it is remote to the server.

Hi,

I've made a template node that may help you, it captures all keys pressed in the browser window, and if it receives an "Enter" key press then sends the key presses as a string payload.

[{"id":"85b23e9.71badc","type":"ui_template","z":"80363def.202","group":"ab6812b4.6e15b","name":"Key Capture","order":2,"width":0,"height":0,"format":"<script>\n(function(scope) {\n  var buffer = '';\n\n  // Make sure we only have one 'global' key press listener,\n  //  or we get problems if we do a 'Restart Flows'\n  if (window.doKeyPress) {\n      window.removeEventListener('keypress', window.doKeyPress);\n  }\n  \n  window.doKeyPress = function (e) {\n      if (e.key == 'Enter') {\n          scope.send({payload:buffer});\n          buffer = '';\n          return;\n      }\n      \n      buffer = buffer + e.key;\n  };\n\n  window.addEventListener('keypress', window.doKeyPress);\n})(this.scope);\n</script>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":90,"y":40,"wires":[["f32a12f6.9b677"]]},{"id":"f32a12f6.9b677","type":"debug","z":"80363def.202","name":"Captured Keypresses","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":280,"y":40,"wires":[]},{"id":"ab6812b4.6e15b","type":"ui_group","z":"","name":"Status","tab":"78f99d66.99acc4","order":1,"disp":true,"width":"6","collapse":true},{"id":"78f99d66.99acc4","type":"ui_tab","z":"","name":"Lights","icon":"fa-lightbulb-o","disabled":false,"hidden":false}]

This does what I think you want, or the receiving the scanned code bit anyway, with a couple of assumptions:

  • The browser window is selected
  • Your scanner does act like a normal keyboard
  • It terminates the scan with an 'Enter'

First time I've tried to write a node like this, so let me know if it works for you and how you get on with it.

YMMV,
C. Chinchilla

1 Like

Chinchilla

That works perfectly. I can't thank you enough.

Now to set it up in my situation. Will let you know how it goes.

Thanks Laurie

1 Like