We have a Pi3 connected to a TV on a remote worksite.
Sometimes, the remote site has a power outage, and when power is restored, the TV and Pi get power at the same time.
The problem is that the TV takes a while to power up, so when the Pi starts up, as far as it can tell, there's nothing plugged into its HDMI port.
Unfortunately, using the 2018-11-13-raspbian-stretch-full.img raspbian image (with the GUI), unless the TV is already powered up and plugged into the Pi when the Pi is starting up, the Pi will output nothing to the TV.
There's an option in /boot/config.txt called
hdmi_force_hotplug=1 which is commented out by default. Uncommenting it causes the HDMI to be hot-pluggable.
The problem now is that if you plug a TV or monitor in after the Pi starts up, the resolution is horrible. It is way, way below the regular 1920x1080 that it normally runs at.
Our Pi automatically opens up a browser on boot to a particular page, and is totally unattended - there's no one to notice, or fix the resolution on site. We need it to be able to automatically fix itself if the TV is not detected on boot.
Does anyone know any way to fix this?
Edit: While there are a few answers below that are helpful, none really make the HDMI hot-pluggable. When a Desktop OS like Ubuntu/Fedora/Windows has a new monitor plugged into it, it detects it immediately, and adjusts the resolution on it immediately. It doesn't require a reboot, or a hard-coded resolution. The ideal solution would do something similar.
I would think that one way to do it would be to have a service constantly query the HDMI device for an EDID, and cache it. If the EDID changes, the device must have changed, and if the new device has a different preferred resolution, it should change the active resolution to match that.
I have no problems writing a service that can query the EDID, cache it, and see if a resolution change needs to be made. I'm just not sure how to use the terminal to change the Desktop's active resolution without a reboot. I'm not sure if I should be looking for a way to change the framebuffer resolution, or X Server's resolution, or the Desktop Environment's resolution, or all of the above.