Building a OpenHamClock Server + Browser on a PI 4 / 1Gb or 2Gb

What we are looking to do here is replicate the functionality that many of us had with the original HamClock, which was in effect

  1. Basic App Server + Web Server
  2. A graphical interface to attach a Monitor or screen
  3. (optional) Remote VNC Control

So we will start with the basic hardware, that we may have, which is the Raspberry PI 4 2Gb or better (I will be honest and state my testing is with a 2Gb unit, but all indications are that this will run on a 1Gb Pi 4).

If you decide just to run the OpenClockServer (only, with no browser), the image below is the typical load after close to 10 minutes of run time.

As we mentioned with the Pi Zero 2W, one of the prime considerations, for something that might run 24×7 on a Raspberry Pi, is to reduce the amount of constant writing to the SD Card. We can’t avoid the server application writing which should not be too much, but if your server requires utilising the Swap file, heavy swap usage can increase SD Card wear and reduce performance.

One other consideration, whenever you are implementing a Raspberry PI Server with a graphic screen, is that you do not need a full blown Raspberry PI OS with desktop, so this build is going to use the following components :

  • OpenHamClock server
  • Openbox (this is instead of the Pi Desktop) – Openbox is a lightweight window manager for the X Window System
  • Chromium (the Browser)
  • (optional) VNC Server

So lets start with our known details

Operating System : Raspberry Pi OS Lite (64-bit) Debian Trixie
Storage : 16Gb SD Card (8gb will probably be fine, but only have 16Gb+ cards available to me)
Hostname : openhamclock
Username : openhamclock
IP Address of PI : 192.168.1.10 (now this should be a free network IP address on your home/shack network, not necessarily this address)
This guide’s purpose is not to explain how to setup up networking, as there are thousands of guides on this and many choices on how to this which can include:

  • Local Static IP Address (setting and IP address on your PI)
  • DHCP Static IP Address (if your router or local DHCP Server supports this)

Just a couple of quick notes :

  • For years PI OS imager has been a good tool for quickly creating images for the PI. However, the last few releases have been buggy (2.06 being the last one at the time of writing), in particular around the localisation selections. To this end, trying to set some countries/cities, have been screwed up, where for Australian cities, it has no selections. This has been reported but nothing seems to have been done, so you may have to select a similar overeas City, then manually select the Country. In the previous version, it was also impossible to select as the selector was doing stupid things.You will need to fix this manually one the OS is running. It has been reported by other users as well, including Hong Kong and a few other locations. This bug is on the Linux version as well.
  • For most of the setup, especially if you don’t want to sit on top of your Pi with keyboard, you are going to need an SSH application, like Putty or other SSH App.
  • You will note that we are not enabling Raspberry PI Connect as part of the setup as we are not using a GUI/Desktop. The reason for this, it for most of it we just need via SSH.

So before we start, you need to create an image for your Raspberry Pi SD Card, and you do this with the Raspberry Pi Imager (https://www.raspberrypi.com/software/)
The main things options you need to select when using the Raspberry PI image is the following:

  • Device : Raspberry Pi 4 2Gb
  • Operating System : Raspberry Pi OS Lite (64Bit) Trixie with no Desktop Environment (Found under Raspberry Pi OS (Other)
  • Storage Device : Make sure it is your SD Card you inserted that is being used, what ever you select will be overwritten
  • Hostname : openhamclock
  • Localisation :
    • Capital City : Adelaide
    • Timezone : Australia/Adelaide
    • Keyboard Layout : us
  • Username : openhamclock
  • Password : {your choice, but write down}
  • WI-FI : {enter your wifi details here including your SSID and Passphrase)
  • Remote Access : Enable SSH – use password authentication
  • Enable Raspberry Pi Connect : disabled

Now you can write to your SD Card.

Ok, if everything went well, you should now have a SD Card with a bootable image. Drop it into your Pi 4 and boot up.

Login to your Raspberry Pi with a keyboard usin the login and password you set (and wrote down). If you did not have a way of setting the IP Address (e.g. DHCP Static), then at the console prompt, type

sudo nmcli

which will display your current interfaces and assigned IP addresses (this is assuming your wireless details were set correctly when you built your image). Now you can remain using the keyboard if you prefer, or you can remotely connect to your Pi with SSH (e.g. Putty or your favourite SSH Terminal) and connect to the Pi. Again, your login and password will be what you set. Using SSH to connect to the Pi remotely makes it a lot easier to cut and paste commands.

You also have access to the interactive network configuration tool as well, so you can set a static IP address for your Pi

sudo nmtui

As I mentioned, setting up a static IP address for your PI, is beyond the scope of this guide, and there are plenty guides on the net.

The first thing we want to do is a step that could be part of your routine when building Linux systems and that is bringing the O/S up to date wit the lastest updates.

sudo apt update

sudo apt upgrade

That should bring your Raspberry Pi OS up to date.

Next thing we want to do, is set Console Autologin enabled via raspi-config. In simple terms we want the Pi to login automatically when it reboots or is turned on, without needing to find a keyboard, plug it in, and login to get the server going after a power failure. To so this we perform the following command:

sudo raspi-config

You will come up with text based menu, and the main area we want is

System Options >>>>> Auto Login >>>> and select YES to “would you like to automatically login to the console”

Next we need to fix localisation issues, so remain in the raspi-config menu and from the top menu goto. (note : that you may not need this if you are not in one of the affected countries, or you have used a later version of the PI imager where it has been fixed)

Localisation >>>> Locale >>> select en_AU.UTF-8 UTF-8 (if Australia) and set this as the default locale as well.
Localisation >>>>Timezone >>>> Select your correct Geographic Area >>>> Australia (in my case) >>>>> and then the correct city.

Ok that is all the work we need to do under raspi-config

Now we install the openhamclock server component and its dependencies. We will start from openhamclocks home directory.

cd ~

We need to install git with the following command

sudo apt install git

Now we need download and and execute NVM (Node Version Manager) directly from GitHub

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash

Note the above command may not work in the future as they update the install file. you can go to this url and read https://github.com/nvm-sh/nvm/tree/master?tab=readme-ov-file, it will generally show you install instructions, with a command very similar, and the latest up to date install release number. The above command was correct at the time of writing. When it finishes installing, you can try the command it provides, or just close the SSH terminal window and open it again.

Copy and paste the following command, so you can use NVM immediately

export NVM_DIR=”$HOME/.nvm”
[ -s “$NVM_DIR/nvm.sh” ] && . “$NVM_DIR/nvm.sh” # This loads nvm
[ -s “$NVM_DIR/bash_completion” ] && . “$NVM_DIR/bash_completion” # This loads nvm bash_completion

We are now going to reload our shell.

source ~/.bashrc

Now we are going to install node.js, which includes npm

nvm install 22

We install V22 as that is what the developer recommends. we can check the node and npm versions…..with the following commands

node -v

npm -v

Now we need to use git to obtain the openhamclock code.

git clone https://github.com/accius/openhamclock.git (note we are not using sudo)

cd openhamclock

npm install

Don’t worry too much abou the Deprecated Warnings

npm start

Ctrl – C to break it

now edit the .env file and add your settings. Note, the ones in bold are the main ones you want to change. You can play with the rest later. We just want to get the basics up and running.

sudo nano .env

# Your amateur radio callsign
CALLSIGN=put your callsign in here

# Your Maidenhead grid locator (4 or 6 character)
LOCATOR=(put your 4 or 6 character maidenhead) in here

# ===========================================
# SERVER SETTINGS (Backend API)
# ===========================================

# Backend API server port
# Dev default: 3001 (see DEV PORTS note above)

PORT=3000

# Host/IP to bind to
# localhost = only accessible from this computer
# 0.0.0.0 = accessible from other devices on your network
HOST=0.0.0.0 (change this from local host)

# Change these so it to enable automatic updates

# ===========================================
# AUTO UPDATE (GIT)
# ===========================================

# Enable automatic updates (requires git installation and repo clone)
AUTO_UPDATE_ENABLED=true

# Check interval in minutes
AUTO_UPDATE_INTERVAL_MINUTES=60

# Run a check shortly after startup (true/false)
AUTO_UPDATE_ON_START=true

# Exit after update so a supervisor (systemd/pm2) can restart (true/false)
AUTO_UPDATE_EXIT_AFTER=true

# This will sync your settings between your PI Browser and the browser that you are using on your PC - it forces it to use a common JSON config file


# Just some basic settings - the main one being Metric instead of imperial

# ===========================================
# DISPLAY PREFERENCES
# ===========================================

# Units: 'imperial' or 'metric'
UNITS=metric

Save this file

If you want to see that it is working, just perform the following command again

npm start

Use your browser to connect back to the IP address of your Pi/ It should show your call sign

If that looks ok, CTRL-C again, so we can finish it off and you can customise it as much as you want.

To finish off, we need to set it to start on boot, so we will set this up as a service, so perform the following commands:

sudo nano /etc/systemd/system/openhamclock.service

add the following to the file

[Unit]
Description=OpenHamClock Server
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=openhamclock
WorkingDirectory=/home/openhamclock/openhamclock
Environment=NODE_ENV=production
ExecStart=/bin/bash -c “source /home/openhamclock/.nvm/nvm.sh && npm start”
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

save it and now perform the following commands

sudo systemctl daemon-reload
sudo systemctl enable openhamclock
sudo systemctl start openhamclock

That last command should have interactively started OpenHamClock as a service. So give it a minute or so, and try your browser again It should come up.

Reboot your Pi and wait about a minute or two (as it takes little while for the server to start up, but quicker than the Pi Zero 2W) and then try to access it from the browser. This will confirm that we have everything running.

If this fails, a couple of quick commands that may help locate the issue

journalctl -u openhamclock -f

This will show you some logs pertaining to the starting of openhamclock.

There is the possibility, that the npm version you have installed differs from the one we have in the service file. You can check what your correct version is and its location with the following command.

which npm

At this point, if you just want a server running on your Pi 4, you can stop here just start exploring and enjoy

However if you want to run a Graphic screen on this unit, keep moving on. We will now install OpenBox and Chromium and have them start automatically.

If your experience with Linux is limited, you may not recognise the format of the command line below. It is a one line command, so if you cut and paste, take the whole line, not one line at a time.

sudo apt install –no-install-recommends \
xserver-xorg \
xinit \
openbox \
chromium \
x11-xserver-utils \
fonts-liberation \
fonts-freefont-ttf

Now we need to create/edit .xinitrc with the following command

nano ~/.xinitrc

and add the following lines to the file

sleep 30
openbox-session &

xset s off
xset -dpms
xset s noblank

exec chromium \
–kiosk \
–ozone-platform=x11 \
–force-device-scale-factor=1 \
–disable-gpu \
–disable-session-crashed-bubble \
–noerrdialogs \
–disable-infobars \
–app=http://127.0.0.1:3000

Now we probably need to explain these lines a little, as they may not been needed for your setup, and you may want to tweak them.

The sleep 30 line, stops the script running for 30 seconds to give the OpenHamClock Service time to start and settle, otherwise your browser window, will not come up with the page.

You can change this, and there are more elegant ways of doing this, but trying to keep it simple, and you may find that you might want to change this sleep time to say 5 minutes (and I will reveal reasons in the openhamclock tips and tricks later). At least you know you can come to this script, and adjust the time here.

The xset commands, were needed for my monitor, they may not be needed for yours, but it is more around the removing the monitor time out / eco features. Otherwise after 5 minutes my monitor went to sleep even though OpenHamClock was active on the screen. I turn the monitor on and off manually (or at least a remote control) as I want to see the screen whenever I turn to the screen, not have to locate the remote turn it on, lose my train of thought. And when I am finished in the shack, I turn it off.

Finally the Exec Chromium line is what I found works reliably. You might, once you have it running, wish to play with these lines, but these work quite well. Naturally the app line points back to the localhost (where your OpenHamClock Server is running).

One more thing we need to do to this script is make it executable with the following command

chmod +x ~/.xinitrc

and finally the last part, we need to autostart X on login, and add the following commands to your bash_profile

nano ~/.bash_profile

if [ -z “$DISPLAY” ] && [ “$XDG_VTNR” = “1” ]; then
exec startx
fi

guess what, that is it…..reboot and you should see your OpenHamClock displayed on your screen connecting to the OpenHamClock Server running on your Raspberry Pi.

However, one of the annoying things is that especially the first time after an update, it will display a “what’s new” window, which means getting a mouse connected to your Pi, to clear the window. Not ideal for a Kiosk style system, and not something you want to do every time an update comes out. Hopefully the developers will offer a flag or option to disable this screen in the future. However one of the other things is that you might want remote control of your OpenHamClock graphic screen, so we are going to add VNC. I tried a few of the remote control options and VNC appears to work best with this setup, with minimal memory/cpu impact compared to the others.

So to do this, we do it using the raspi-config wiht the following command (via remote ssh is fine)

sudo raspi-config

Interface options >>>> VNC >>> VNC Enable >> Yes

Once you do this it will install the dependencies needed. We probably don’t need half of what is being loaded, but it is quick, and simple. You don’t need to reboot as it installs the VNC Server and enables it and starts it. So once it is complete, you can run a VNC Client on your remote workstation, and be remotely controlling it from your workstation. It will probably ask for you login and password that you originally set for your Raspberry Pi (before we setup auto-login). I personally run the RealVNC client, but just be aware, some other VNC Clients may not support some of the newer security protocols and will not connect. Just in case your VNC client needs the connection line added, it’s {your raspberry pi IP address}::5900 (TCP)

Let’s just look on how well the Raspberry Pi 4 is handling the CPU load and memory, and as you can see we are running in 750Mb or ram, no SWAP usage which is good, and that CPU load is not that bad.

And whilst actually connected via VNC Sessions, slight increases in memory, and a little more heavy use of the CPU, but not excessive. It’s not like you are going to be connecting via VNC 100% of the time.