# Read USB keyboard or RFC reader connected to USB at the Raspi

**URL:** <https://discourse.nodered.org/t/read-usb-keyboard-or-rfc-reader-connected-to-usb-at-the-raspi/27846>\
**Category:** Hardware\
**Created:** [5 June 2020 18:54 UTC](https://discourse.nodered.org/t/read-usb-keyboard-or-rfc-reader-connected-to-usb-at-the-raspi/27846 "2020-06-05T18:54:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)\
**Post date:** [5 June 2020 18:54 UTC](https://discourse.nodered.org/t/read-usb-keyboard-or-rfc-reader-connected-to-usb-at-the-raspi/27846/1 "2020-06-05T18:54:02Z")

</div>

I want to read a RFC tag with a RFC reader connected to my Raspberry Pi via USB.  
It acts like a keyboard with a 10-digit output on the active tty.  
How do I read that input with Node-RED?  
I saw a post on a Siemens forum, but that did not help me:  
[https://support.industry.siemens.com/tf/WW/en/posts/usb-keyboard-and-node-red/164793?page=0](https://support.industry.siemens.com/tf/WW/en/posts/usb-keyboard-and-node-red/164793?page=0)  
I don't want to use the RPI keyboard node which scans only single keypresses with up and down, but return one single string as msg.payload.

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [5 June 2020 20:13 UTC](https://discourse.nodered.org/t/read-usb-keyboard-or-rfc-reader-connected-to-usb-at-the-raspi/27846/2 "2020-06-05T20:13:29Z")

</div>

Have you tried the serial in node?

---

<div class="post-metadata">

**Author:** ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)\
**Post date:** [30 June 2020 10:39 UTC](https://discourse.nodered.org/t/read-usb-keyboard-or-rfc-reader-connected-to-usb-at-the-raspi/27846/3 "2020-06-30T10:39:25Z")

</div>

I have found a solution:

```auto
#!/bin/sh
# start only when called from the console
if [! "$TERM" = "linux"] ; then
exit 0
fi

ok=false
while [$ok = false]
do
read choice
case $choice in
	123456789) sudo init 0
	;;
	*) echo `date +%Y-%m-%d_%H:%M:%S`: $choice>>/home/pi/keyboard-archive.txt
	   echo $choice>/run/user/1000/keyboard.txt
	;;
esac
done

```

I start the bash script from ~/.bashrc (last command)

In Node-RED I check for changes in the archive via the watch node and read the content of the keyboard.txt via the file in node, because the watch node has this...

> Note: The directory or file must exist in order to be watched. If the file or directory gets deleted it may no longer be monitored even if it gets re-created.

To prevent massive SD card writes, the archive file could also be stored in `/run/user/1000/` (tempfs)

When the transponder with the number 123456789 is read, the raspi will shutdown.

---

<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:** [29 August 2020 10:39 UTC](https://discourse.nodered.org/t/read-usb-keyboard-or-rfc-reader-connected-to-usb-at-the-raspi/27846/4 "2020-08-29T10:39:26Z")

</div>

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