In this tutorial we will show how to make a content display running a webpage with dynamic content, getting updated, at a given interval. We assume you already have a website you wish to show and gives all the instructions on how to set up a Raspberry Pi to show the website, and refresh the site, to account for dynamic content.
The idea is of course that you, with a bit of web skills, can design your own content page (webpage), pulling in dynamic content from various sources and showing an always updated view of this on a display. Hopefully you will find interesting use cases for this.
Some background on our use case (optional read)
We used it to solve the boring problem of having a display showing the lab opening hours. Our content is located on a WordPress site, where we can’t access the source code. Therefore, programming the needed features directly into the webpage is not an option. To deal with this we created a workaround where a server script produces a images of our opening hours calendar (an exchange calendar), that WordPress then can point to. The calendar image gets updated every second minute, but in order to also get updated the image on the display, we need WordPress to auto refresh the page. Otherwise it would keep showing the image from when the system was first started.
Raspberry Pi 4, with:
– The latest Raspberry Pi OS, and a stable internet connection.
– (we used the OS version released 2021-05-07)
– Power supply, keyboard, and mouse.
Display (HDMI enabled), with:
– Power cable
– HDMI to micro HDMI cable
How it works
The setup uses two main software components, which is a combination of two command line tools. Xdotool for refreshing the browser with a terminal command and Watch for timing this to happen at a specified interval. The needed commands for these tools are put into a script, together with the command for starting the browser in full screen, with a given URL (the page you want it to show). This script is then set to launch every time the Pi boots up, to ensure stability of the system.
In our case we use a vertical screen, so the display orientation also needs to be flipped, and the browser zoom settings needs to get adjusted for the best view of the content.
Below are all the steps you need to do to make your own content/info display. Connect the hardware, boot up the Pi, and go through the steps 🙂
1) Installing Xdotool
First we need to ensure we have the two command line tools in place. Watch comes with the OS, but we need to install the Xdotool by running the following command in a terminal window:
sudo apt-get install xdotool
2) Prepare the script
The next thing is to prepare the script with the commands for Watch and Xdotool. Make sure you are in the home folder (/home/pi) of the terminal window, and do the following steps.
Create script file with nano text editor: nano start_URLrefresh.sh
Copy this script code:
bin/sleep 6 /usr/bin/lxterminal --command watch -n 30 xdotool key ctrl+F5 & echo "opening watch window" /usr/bin/lxterminal --command chromium-browser --start-fullscreen https://airlab.itu.dk/opening-hours/ echo "starting browser in full screen"
Paste the script code into the nano text editor (use the mouse, keyboard shortcuts won’t work)
Change the webpage URL (https://airlab.itu.dk/opening-hours/) to the one you wish to use
Close the nano editor: ctrl+x
Save changes: shift+y
Change permissions for the file: sudo chmod 755 start_URLrefresh.sh
Make the file executable: sudo chmod +x start_URLrefresh.sh
Test the script with this command: ./start_URLrefresh.sh
After a few seconds the Chromium browser should start with your webpage in full screen, refreshing the page every 30 seconds.
NB: if you want to stop the setup, close both the browser window and the Watch window, since the watch window is triggering the keyboard shortcut for updating the browser, and this can give problems when operating the Pi.
In order to change the refresh interval, open the script file again with: nano start_URLrefresh.sh
Change the number 30 to your wished interval (in seconds) in this line:
/usr/bin/lxterminal –command watch -n 30 xdotool key ctrl+F5 &
2) Running the script at system boot
Open the autostart settings file by typing the following command in a terminal window:
sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
Add the following line to the bottom of the document:
Close and save the settings file: (press) ctrl+x to exit, then: shift+y to save
Test that the autostart works by rebooting the Pi. The same thing should now happen at boot, as when you manually runs the start_URLrefresh.sh script.
Now the system is actually set up. The following two small steps was needed for our setup, but might no apply for you.
3) Change display orientation (optional)
Since our screen is mounted vertically, we needed to change the setting for this. With the Pi 4 models this have luckily been made very easy inside the GUI.
PI MENU: Preferences -> Screen Configuration (new window opens)
TOP MENU: Configure -> Screens -> HDMI-1 -> Orientation -> Left
TOP MENU: Configure -> Apply
The orientation change is applied, and a dialogue opens where you need to click OK, to make the change permanent.
4) Adjust zoom level (optional)
In our case the browser window needs to be displayed with zoom level 75% to give the best view of the content page.
You can set this up in the Chromium browsers from the menu (3 vertical dots). This change is permanent.