Page 1 of 1

Run startup script only if no HDMI?

Posted: Thu Dec 18, 2014 8:53 pm
by jdunson
What I would like to do is set up Raspbian so that it does the following:
* If a HDMI monitor (of whatever size or type) is plugged in, boot completely normally.
* If no HDMI monitor is plugged in, boot normally at first, but instead of simply waiting for a user to log in, run a specific script.

The initial use case will be a card / OS set up such that it boots and functions normally when attached to a screen (and presumably keyboard); but if booted with no screen, runs a script that calls a python program that displays an unattended holiday light show on the (presumed) attached Unicorn HAT.

Optionally, I'd like to be able to detect the presence of specific HATs, and run a different script based on whether certain ones are installed; and optionally shut down cleanly if neither a HDMI monitor nor any supported "kiosk" HATs are detected. Another interesting variant might include detection of a keyboard, to set up a third boot state: with-monitor-without-keyboard going into a slideshow, for instance.

I'm generally familiar with Linux and shell scripting, but I'm not clear on how to read the state of the Raspberry Pi monitor detection from a shell script, or where the best place for "do this last" / kiosk style scripts are in the Raspbian boot hierarchy.

For the optional / expansion idea, while I've skimmed some of the HAT info and understand that they have an ID EEPROM, it's not clear what the "stock" method of querying from user-land (shell script, python program, etc.) whether a HAT is present at all, and if so which one is attached.

Re: Run startup script only if no HDMI?

Posted: Thu Dec 18, 2014 9:31 pm
by ghans
Play around with the tvservice tool , it should be able to
do what you want.

ghans

Re: Run startup script only if no HDMI?

Posted: Thu Dec 18, 2014 11:20 pm
by DirkS
I have played around with this code in /etc/rc.local:

Code: Select all

echo "is it HDMI or DVI?" > /home/pi/tft.log
/usr/bin/tvservice -s >> /home/pi/tft.log
if (/usr/bin/tvservice -s | /bin/egrep 'HDMI|DVI') ; then
    echo "HDMI / DVI screen" >> /home/pi/tft.log
else
    echo "No HDMI / DVI; run script" >> /home/pi/tft.log
    /full/path/to/your/script   # replace this with full path to script
fi
Addit *before* the line 'exit 0'.
The stuff sent to /home/pi/tft.log is just meant for debugging.
The script is run as root.

Gr
Dirk.

Re: Run startup script only if no HDMI?

Posted: Mon Apr 03, 2017 7:03 pm
by john.t
Do i have to make my own tft.log to make this work?
thnx
john

Re: Run startup script only if no HDMI?

Posted: Mon Apr 03, 2017 8:03 pm
by ghans
The file should be automatically created on first run.

ghans