6

I'm having a raspberry pi running debian linux and I have an RFID reader connected to it. The RFID reader behaves like a keyboard. Every time I scan a tag it types then number of the tag and then carriage return.

My problem is that I want to redirect the output of the RFID reader to my SSH session. That means anything that is typed to the physical keyboard of the pi should be displayed in my SSH window.

I have tried with: cat /dev/tty0 but it wont work because the user is not logged in.

Is there a way to disable the login screen after the pi boots and then redirect all input through SSH?

dimme
  • 195
  • 2
  • 9
  • @sawdust: At least 1D barcode readers *do* often act as keyboard-like input devices; it's not unusual. – u1686_grawity Sep 12 '12 at 23:22
  • Yeap, I know that. – dimme Sep 12 '12 at 23:38
  • *"The RFID reader behaves like a keyboard'* - Please confirm that this reader has a keyboard interface (emits scan codes) or an EIA-232 (aka RS-232 or serial) interface (emits ASCII codes). A (quick) google search turns up serial, USB and network outputs. Keyboard interface would be practical since it provides power. – sawdust Sep 12 '12 at 23:51
  • It doesn't matter how it connects to the rpi. I just want to forward the letters from the normal screen to the ssh session. – dimme Sep 13 '12 at 00:04
  • 1
    Actually it would if you have to specify the device name. The request for the username and password are issued by the `getty` program. Replace `getty` with a script that redirects the "keyboard" input to a "screen" pipe or file. You will have to inspect your distro's startup/runlevel scheme. Some are easier to hack than others. – sawdust Sep 13 '12 at 00:29
  • @sawdust +1 for getty and the pipe. Yet, @Dimme, stick with `getty` in order to get a tty in the first place, but let it use your script as the login program like so `getty -l "sh -c $SCRIPTPATH"`. In order to decouple the grab process from the forwarding/display process you might want to use a named pipe. – wnrph Sep 13 '12 at 09:59

2 Answers2

1

I have this exact use case (raspi with RFID reader that emulates a USB keyboard).

I solved the issue by creating a new systemd unit to start my script in a screen (so I can see what's going on by mirroring the session via ssh).

1. Create /etc/systemd/system/my-tty1.service:

[Unit]
Description=my tty1-service
After=getty.target
Conflicts=getty@tty1.service

[Service]
Type=simple
ExecStart=/usr/bin/screen -S myTTY1 /path/to/my/script
StandardInput=tty-force
StandardOutput=inherit
StandardError=inherit

[Install]
WantedBy=multi-user.target

This starts your script (or program) to handle the input in a screen session named myTTY1.

2. Enable the service so it starts after boot:

systemctl enable my-tty1.service

3. Stop getty, start your service:

systemctl stop getty@tty1.service
systemctl start my-tty1.service

4. You can now connect to your screen session with screen -x myTTY1 via ssh. Disconnect by detaching the screen with CTRL+A, followed by D.

1

One solution is changing the init system, so a getty process gets a tty and invokes your script. Your script might then initialize a named pipe (aka fifo) and redirect stdin to it.

Then you can login via ssh and read from that pipe.

wnrph
  • 3,633
  • 1
  • 26
  • 39