Chapter 3
Add a Logviewer to HabPanel

This is optional. But; why we are starting with such a feature, that isn’t really related to Smart Home and automation and so on? The answer is: This will make the troubleshooting in case of any errors much easier. Also if we are starting to create some rules later on, we can use this feature to see what is going on and maybe also what went wrong. If you want to skip this chapter for now, feel free to do so and come back when you have some trouble.

To realize this feature, we will install a software called Frontail. It is nothing that is special for OpenHab but it is used to show Logs in Linux in general on a website. To start we need to connect to the Raspberry Pi via SSH using Putty.

Execute the following commands to install the components used by Frontail and Frontail itself:

curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo npm i frontail -g
sudo nano /lib/systemd/system/frontail.service

Now the Linux texteditor “Nano” will open. Copy this configuration parameters into the opened editor. Copy the text below (Ctrl+C) and paste it into the Putty session by performing a right mouseclick.
Attention! On some systems the line breaks are gone after pasting it to Nano. To avoid this, paste the text to a notepad (press Windows-Key+R, type “notepad” and press enter). Copy the text from the notepad window again and it will work!

#!/bin/sh -

[Unit]
Description=Frontail

[Service]
ExecStart=/usr/bin/frontail --ui-highlight -t dark /var/log/openhab2/openhab.log /var/log/openhab2/events.log
Restart=always
User=pi
Group=pi
Environment=PATH=/usr/bin/
Environment=NODE_ENV=production
WorkingDirectory=/usr/bin/

[Install]
WantedBy=multi-user.target
Alias=frontail.service

 

Your Putty session should look like this after you pasted the text:

Press Ctrl+O and enter to write the changes to the new file. Press Ctrl+X to leave the editor.
After this, we need to make the file we created executable and reload the service deamon of the operating system. Execute the following commands:

sudo chmod 644 /lib/systemd/system/frontail.service
sudo systemctl daemon-reload
sudo systemctl enable frontail.service
sudo systemctl start frontail.service

Finally you can access the OpenHab logs via browser by browsing to the URL http://<ip-of-raspberry>:9001. In our demo environment the link is http://192.168.0.144:9001.

After installing and configuring Frontail, we need to add it to the HabPanel. HabPanel is a customizable UI of OpenHab. I will go into more details in a different chapter. For now, just follow this advices:

  1. Go to http://<raspberry-ip>:8080 (i.e. http://192.168.0.144:8080)
  2. Click on the “HABPANEL” tile
  3. Click at the gear at the top right corner

  4. Click on “Add new dashboard”

  5. Name the new dashboard “System” and click “OK”

  6. Click on the big tile called “System” on the next screen

  7. Move your mouse over the “System” text at the top. A small pencil will appear at the right next to the text. Click the pencil to edit the dashboard.

  8. At the top right click “Add Widget” and select “Frame”.

  9. A new big tile will appear at the dashboard. Click the three dots at the top right corner of the tile and select “Edit…”.

  10. In the “Frame Settings” dialog enter “OpenHab Logs” in the Name-field, select “Static URL” in the URL Source-field and enter “http://<Raspberry-IP>:9001” (i.e. “http://192.168.0.144:9001”) in the URL-Field. Leave the Refresh Interval field empty and click “Save”.

  11. Optional: if you like to stretch the tile that will include the logs a little bit, you can hover over the tile and drag the bottom right corner to change the size of the tile. I personally like it if the tile is a little bit wider to make it easier to read long log lines.

  12. In the top left corner click on “Save” and after that on “Run”.

  13. Now you should see the running System-Dashboard that includes the logs of OpenHab. Here you can see what is going on and/or what is wrong in your configuration. Right now there should not be much in the logs and no or not much activity. In the next chapter we will add view to system resources (Memory, CPU, Disk use) of the Raspberry Pi to this dashboard.