Automatically start a fullscreen browser on a Raspberry Pi - show openHAB HABpanel
The Raspberry Pi with the touch display for the home automation system is coming along nicely. One problem to solve: how to display the openHAB HABpanel, and which browser to use?
Firefox and Chrome don't run on Raspbian. However "Chromium" (the open source part of the Chrome browser) is. That's a good start. But how to start the browser automatically, and in full screen?
Let's start by installing Chromium and a few additional components. As always, that is integrated into an Ansible Playbook, so I can easily re-do or modify the entire installation:
- name: Install browser packages
apt:
name:
- chromium-browser
- chromium-browser-l10n
- rpi-chromium-mods
- webext-ublock-origin
state: present
I want an icon on the desktop, which lets the user start the browser with a click. Raspbian uses the lightweight LXDE, all I have to do is drop a ".desktop" file into "~/Desktop/". First the ".desktop" file for the browser:
[Desktop Entry]
Name=Fullscreen Browser
Comment=Browser
Icon=/home/pi/chromium_icon.xpm
Exec=/usr/bin/chromium-browser
Type=Application
Encoding=UTF-8
Terminal=false
Categories=None;
Path=/home/pi
I copied the browser XPM file from the Chromium project into my Playbook directory (another possible way is to download the icon straight away in the Playbook), and place it in the home directory of the "pi" user. Now let's upload everything to the Pi:
- name: Copy Chromium icon
copy:
src: '{{ playbook_dir }}/files/chromium_icon.xpm'
dest: '/home/pi/chromium_icon.xpm'
owner: pi
group: pi
mode: 0644
- name: Copy Browser.desktop to Desktop
copy:
src: '{{ playbook_dir }}/files/Browser.desktop'
dest: '/home/pi/Desktop/Browser.desktop'
owner: pi
group: pi
mode: 0755
So far, so good. But this does not start the browser in full screen, and it does not automatically jump to the openHAB HABpanel website, and most important: it does not start the browser when the Pi starts.
First things first, I need to modify the ".desktop" file and add a few more options:
[Desktop Entry]
Name=Fullscreen Browser
Comment=Fullscreen Browser
Icon=/home/pi/chromium_icon.xpm
Exec=/usr/bin/chromium-browser --start-fullscreen --noerrdialogs --disable-session-crashed-bubble --force-device-scale-factor=0.50 http://openhab/habpanel/#/view/Home
Type=Application
Encoding=UTF-8
Terminal=false
Categories=None;
Path=/home/pi
The modified "Browser.desktop" file will start Chromium in full screen mode, scale down the display size to "50%" (which seems to be the right size to show the HABpanel on a 7" screen), and avoid popping up the "restore session" dialog if the browser crashed. It also adds a URL which the browser will navigate to, once it starts. In my case that is the "Home" view on my openHAB installation, you might want to change that to a separate view.
Last but not least: the autostart. LXDE has an autostart option. All you have to do is place the ".desktop" file in the "~/.config/autostart/" folder. Of course the folder doesn't exist in the beginning, therefore it needs to be created. Ansible can do that as well:
- name: Create LXDE autostart directory
file:
path: /home/pi/.config/autostart
state: directory
owner: pi
group: pi
mode: 0700
- name: Copy Browser.desktop to autostart
copy:
src: '{{ playbook_dir }}/files/Browser.desktop'
dest: '/home/pi/.config/autostart/Browser.desktop'
owner: pi
group: pi
mode: 0755
The next time the Pi starts, it will open a browser in full screen, and navigate to your openHAB installation.
Comments
Display comments as Linear | Threaded