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
  • 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 7 '13 at 11:29
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.