2

Is there any way to detect if a Pi is running headless on raspbian. I would like to automatically start tightvncserver if headless.

I developed a script which detects when using RCA video and starts tightvncserver.

I still have trouble getting this to run on startup.

I put the following into rc.local

This runs (before the login prompt) and I can see the output on the console when I have a display (hdmi) attached, but it does not seem to work with no display.

I can run the script if I login via ssh

# If running headless (i.e. default RCA video) start tightvncserver
if /opt/vc/bin/tvservice -s | grep 'NTSC\|PAL'; then
  echo $(hostname) is running Headless
  /usr/bin/tightvncserver
else
  echo $(hostname) is running hdmi
fi
Milliways
  • 59,890
  • 31
  • 101
  • 209
  • By default, if no HDMI is detected, the raspberry will fall back to RCA. So if you normally use HDMI, you can detect if it is headless, by checking if it is running in Composite 'mode', by checking the resolution of the framebuffer. – Gerben Aug 12 '13 at 13:22
  • You mention "checking the resolution of the framebuffer", but do not explain how. In fact my script detects RCA. The remaining problem is why it doesn't work before login (or how I can check what it actually doing without a display). – Milliways Sep 07 '13 at 11:29

1 Answers1

3

you may get some info using CEC if your TV is connected over HDMI, however, if you use RCA jack, there might be no reliable way to tell if there's something connected or not.

lenik
  • 11,541
  • 1
  • 30
  • 37