Category Archives: Raspberry Pi

Simple Raspberry Pi RTSP stream Dashboard

So, you have a Raspberry Pi and want to use it as a dashboard to display a rtsp stream without having to install a full desktop environment.  This is useful if you want to display security camera streams etc without requiring a full desktop environment or window manager.  This way it keeps your solution simple and lightweight.

Parts needed

  • – Raspberry Pi
  • – Screen

Setup your Pi

You can install the raspberry pi OS lite edition.  Once that is up and running you need to update it:

sudo apt update && sudo apt upgrade -y

Next, install the required packages:

sudo apt install -y xserver-xorg ffmpeg

Now reboot:

sudo reboot

Once that is installed, create a service file in /etc/systemd/system/ :

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

and paste the following:

[Unit] 
Description=RTSP Stream to attached Screen with ffplay 
After=multi-user.target rescue.service rescue.target display-manager.service 

[Service]
Type=simple 
User=1000 # User UID to run service under
Group=1000 # Group GID to run service under
ExecStart=/usr/bin/ffplay -autoexit -rtsp_transport tcp -sync video -fflags nobuffer -framedrop  -i rtsp://hotname:port
Environment="XDG_RUNTIME_DIR=/run/user/1000" #change 1000 to the user above
Restart=always 
RestartSec=20 

[Install] 
WantedBy=multi-user.target

Once that file is saved, run the following commands

Sudo systemctl daemon-reload
sudo systemctl enable stream.service
sudo systemctl start stream.service

That’s it.  All going well your RTSP stream should now automatically come up at boot.  Enjoy

Hardware Watchdog on Linux Machines

On any modern Linux operating system that uses systemd you can configure systemd to interact with the hardware watchdog on your behalf, rather than doing it with watchdog service (apt install watchdog) or using a separate user-space daemon.

To enable the builtin systemd hardware watchdog, edit the following file:

 sudo nano /etc/systemd/system.conf

uncomment and set the following values

RuntimeWatchdogSec=10 
RebootWatchdogSec=2min 
WatchdogDevice=/dev/watchdog0

The first entry RuntimeWatchdogSec enables the systemd watchdog, RebootWatchdogSec sets the wait time after boot to start feeding the watchdog and WatchdogDevice is the hardware device to be fed.

Most modern hardware has a watchdog timer including Rapsberry Pis and most Intel chips beyond generation 7.

A bit more on the built-in systemd watchdog..

Systemd’s watchdog can be mainly used for 3 different actions:

  • hardware reset (leveraging the CPU hardware watchdog exposed at /dev/watchdog). This is enabled by the RuntimeWatchdogSec= option in /etc/systemd/system.conf
  • application reset, as long as this is foreseen in the systemd unit definition (see below service example)
  • system reset as a fallback measure in response to multiple unsuccessful application resets. Also defined in the systemd unit

example unit file:

[Unit]
Description=My Little Daemon
Documentation=man:mylittled(8)

[Service]
ExecStart=/usr/bin/mylittled
WatchdogSec=30s
Restart=on-failure
StartLimitInterval=5min
StartLimitBurst=4
StartLimitAction=reboot-force

The example is taken from: http://0pointer.de/blog/projects/watchdog.html, which gives a pretty complete overview of what and how you can use the watchdog service.

 

 

 

 

Boot Raspberry Pi 3B with USB SSD

Ensure USB Boot OTP is set

To enable the USB boot bit, the Raspberry Pi 3 needs to be booted from an SD card with a config option to enable USB boot mode. Once this bit has been set, the SD card is no longer required. Note that any change you make to the OTP is permanent and cannot be undone.

You can use any SD card running Raspbian or Raspbian Lite to program the OTP bit. First, prepare the /boot directory with up to date boot files:-

 sudo apt update && sudo apt upgrade && sudo reboot

Then enable USB boot mode with this code:-

echo program_usb_boot_mode=1 | sudo tee -a /boot/config.txt

This adds program_usb_boot_mode=1 to the end of /boot/config.txt. Reboot the Raspberry Pi with:-

sudo reboot

Then check that the OTP has been programmed with:-

 vcgencmd otp_dump | grep 17:

Check that the output 17:3020000a is shown. If it is not, then the OTP bit has not been successfully programmed. In this case, go through the programming procedure again. If the bit is still not set, this may indicate a fault in the Pi hardware itself.

If you wish, you can remove the ‘program_usb_boot_mode’ line from config.txt, so that if you put the SD card in another Raspberry Pi, it won’t program USB boot mode. Make sure there is no blank line at the end of config.txt. You can edit config.txt using the nano editor using the command:-

sudo nano /boot/config.txt              # then scroll all the way to the bottom

Ensure Pi waits for USB to initialise

There are two different things which go by the same name program_usb_boot_timeout (previously called program_usb_timeout): the OTP bit and the corresponding parameter in config.txt. The latter is used to set the former (by booting from SD card), but once the OTP bit is set, there is no need for the SD card anymore. And just in case it’s not clear, OTP is a kind of flash memory, so its content is persistent across reboots.

So the full procedure goes like this:

  • prepare a bootable SD card and boot from it
  • run sudo BRANCH=next rpi-update
  • add program_usb_boot_timeout=1 to your config.txt
  • reboot (this is the moment OTP bit will be programmed)
  • power off, remove the SD card and plug USB device
  • power on.

How to Set Up a Raspberry Pi Web Server

This tutorial aims to host a simple web server on a Raspberry Pi. This produces a very lightweight web server and works well to host a microservice or to test a website without deploying a full web server on the cloud. We will use Docker on Raspbian OS and spin up an Apache 2.4 container from Docker Hub.

Prerequisites

The only prerequisite to following this guide is that you have SSH connection enabled, Raspberry Pi 1, 2, 3, 4 or Pi Zero W with a running Raspbian OS.

Installing Docker to the Raspberry Pi

Step 1: Update and Upgrade

Before installing Docker we need to make sure that the Raspberry Pi is running the latest software.

sudo apt-get update && sudo apt-get upgrade

Step 2: Download the Script to Install Docker on Raspberry Pi

downloading and running the script is very easy just copy and paste the command in the terminal:

curl -fsSL https://get.docker.com -o get-docker.sh

To execute the installation script enter this command:

sudo sh get-docker.sh

Now you have to wait for the script will install all the required packages in Raspberry Pi.

Step 3: Add a Non-Root User to the Docker Group

By default, only root users can run the docker containers. If you are not logged in as the root you will need to use the sudo prefix every time and it’s not recommended. We can easily skip by adding the non-root user to the Docker group here is how to do that:

sudo usermod -aG docker [user_name]

To add the Pi user (the default user in Raspberry Pi OS), use the command:

sudo usermod -aG docker pi

Setting up Apache on Raspberry Pi

One of the best things about the Docker ecosystem is that there are tens of standard docker containers that you can easily download and use.

In this article, we will instantiate an Apache 2.4 container named raspberry-pi-web-server, detached from the current terminal. We will use an image called httpd:2.4 from Docker Hub.

Our plan is to have requests made to raspberry pi’s local IP address on port 8080 be redirected to port 80 on the container. Also, instead of serving content from the container itself, we will serve a simple web page from /home/user/website.

We will do this by mapping /home/user/website/ on the /usr/local/apache2/htdocs/ on the container. Note that you will need to use sudo or login as root to proceed, and do not omit the forward slashes at the end of each directory.

# sudo docker run -dit --name raspberry-pi-web-server -p 8080:80 -v /home/user/website/:/usr/local/apache2/htdocs/ httpd:2.4

At this point, our Apache container should be up and running.

$ sudo docker ps

Now let’s create a simple web page named raspberry-pi-web-server.html inside the /home/user/website directory.

# vi /home/user/website/raspberry-pi-web-server.html

Add the following sample HTML content to the file.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Raspberry Pi Web Server</title>
</head>
<body>
    <h1>Learn Docker</h1>   
</body>
</html>

Next, point your browser to Server-IP:8080/raspberry-pi-web-server.html (where Server-IP is your Raspberry Pi IP address).

If you wish, you can now stop the container.

$ sudo docker stop raspberry-pi-web-server

and remove it:

$ sudo docker rm raspberry-pi-web-server

To finish cleaning up, you may want to delete the image that was used in the container (omit this step if you’re planning on creating other Apache 2.4 containers soon).

$ sudo docker image remove httpd:2.4

Conclusion

In this article, we explained how to Set Up a Raspberry Pi Web Server using docker.

Raspberry Pi as Dashboard Controller

Raspberry Pi is a useful embedded computer that can be used for many things including powering informational dashboards.  There are several ways to achieve this with varying complexity however In this tutorial, we will show how to utilise a Raspberry Pi as a Dashboard Controller in a simple straight forward manner.  We are using a Pi 4 revision B however the below has been tested on Pi 3b revisions.

The Pi needs to be configured properly in order to satisfy the following needs:

  • The screen should be fully filled with the view
  • After booting, the predefined screen should be loaded automatically
  • The screen should not sleep after some period of time
  • The mouse cursor should not be visible in the screen
  • Menus and the taskbar should not be visible
  • After an unclean reboot (i.e. after power outage), there should be no browser warning about the unclean shutdown
  • It should be possible to connect to the device remotely to reload or change the view

What you need

  • RaspberryPi
  • 8GB microSD card (preferably with microSD -> SD adapter)
  • (preferably) RaspberryPi case
  • DC charger with 5V output of 2 Amperes and with USB C jack (very common nowadays, as it is used for charging smartphones and tablets).
  • USB keyboard for configuration. A mouse is not necessary

Step 1 – Update your Raspberry Pi

Once you have setup the Raspberry Pi  and are presented with a desktop screen we need to update the device  The following commands are to be run in a Terminal:

sudo apt-get update && sudo apt-get upgrade -y && sudo reboot

Its also a good idea to update the firmware on your Pi:

sudo rpi-update

Once the firmware is updated reboot the device for the next step.

Step 2 – Disable screen timeout

To prevent the screen going blank you need to disable screen timeout.  In the latest versions of RaspbianOS, this is now an option that can be set in the GUI.

Click Start>Preferences>Raspberry Pi Configuration and select the Display tab:

From here, disable Screen Blanking and click ok.  now reboot your Pi again.

Step 3 – Install Unclutter

Unclutter is a tool to disable the mouse being viable when there is no input.  Simply install with the following command in Terminal:

sudo apt-get install unclutter

Step 4 – Create Autostart for Chromium Browser with LXDE

Create two files in /home/pi/.config/lxsession/LXDE-pi – autostart and desktop.conf this can either be by using nano or creating via a ssh tool like WinSCP.

Add the below to autostart and save the file.  You can place the URL of your dashboard after the –incognito flag:

@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
# @xscreensaver -no-splash
@point-rpi

@xset s off
@xset -dpms
@xset s noblank
@unclutter

@chromium-browser --noerrdialogs --kiosk --disable-infobars --incognito http://URL-GOES-HERE

Add the contents of desktop.conf and save the file:

[Session]
window_manager=openbox-lxde-pi
disable_autostart=no
polkit/command=lxpolkit
clipboard/command=lxclipboard
xsettings_manager/command=build-in
proxy_manager/command=build-in
keyring/command=ssh-agent
quit_manager/command=lxsession-logout
quit_manager/image=/usr/share/lxde/images/logout-banner.png
quit_manager/layout=top
lock_manager/command=lxlock
terminal_manager/command=lxterminal
launcher_manager/command=lxpanelctl

[GTK]
sNet/ThemeName=PiX
sNet/IconThemeName=PiX
sGtk/FontName=Roboto Light 12
iGtk/ToolbarStyle=3
iGtk/ButtonImages=0
iGtk/MenuImages=0
iGtk/CursorThemeSize=18
iXft/Antialias=1
iGtk/AutoMnemonics=1
iGtk/EnableMnemonics=1
sGtk/ColorScheme=selected_bg_color:#4d4d9898f5f5nselected_fg_color:#ffffffffffffnbar_bg_color:#ededececebebnbar_fg_color:#000000000000n
sGtk/CursorThemeName=PiX
iGtk/ToolbarIconSize=1
iNet/EnableEventSounds=1
iNet/EnableInputFeedbackSounds=1
iXft/Hinting=1
sXft/HintStyle=hintfull
sXft/RGBA=rgb

[Mouse]
AccFactor=20
AccThreshold=10
LeftHanded=0

[Keyboard]
Delay=500
Interval=30
Beep=1

[State]
guess_default=true

[Dbus]
lxde=true

[Environment]
menu_prefix=lxde-pi-

Reboot the Pi and after a few moments the display should now show the URL dashboard you enetered in autostart.

To rotate more than one dashboard page

The easiest way to achieve this is by installing Revolver – Tabs from the chrome webstore. this can be done by closing down the dashboard instance of Chromium by pressing CFRL-F4 then opening the Chromium Browser from START>Internet>Chromium Browser and clicking the link above.

You’ll need to change settigns within Revolver Tabs, notably rotation time in seconds, auto start and optionally reload.  If you have Reload enabled, you can prevent tabs reloading by specifying their URL’s.  Remember to click save.

As we loaded Chromium in Incognito, you need to enable Revolver Tabs for incognito mode is Google chromium extensions settings.

Once setup second and subsequent URLs you have entered in autostart will automatically rotate.  subsequent URLs can be added with a space in between them:

@chromium-browser --noerrdialogs --kiosk --disable-infobars --incognito http://URL-1 http://URL-2 http://url-3

 

 

 

 

 

 

 

 

 

Raspberry Pi Disable Bluetooth

The steps below shows how to disable on-board Bluetooth and related services. Those steps also disable loading the related kernel modules such as bluetooth, hci_uart, btbcm, etc at boot.

1 Open /boot/config.txt file.

sudo nano /boot/config.txt

2 Add below, save and close the file.

# Disable Bluetooth
dtoverlay=pi3-disable-bt

3 Disable related services.

sudo systemctl disable hciuart.service
sudo systemctl disable bluealsa.service
sudo systemctl disable bluetooth.service

4 Reboot to apply the changes

sudo reboot

Even after disabling on-board Bluetooth and related services, Bluetooth will be available when a Bluetooth adapter (e.g. Plugable Bluetooth Adapter) is plugged in.

Disable Bluetooth completely

If Bluetooth is not required at all, uninstall Bluetooth stack. It makes Bluetooth unavailable even if external Bluetooth adapter is plugged in.

1 Uninstall BlueZ and related packages:

sudo apt-get purge bluez -y
sudo apt-get autoremove -y

Uninstalling Bluetooth stack also disabling related services, and loading related kernel modules.

Raspberry Pi WinSCP as Root

By default the stfp-server of a Raspberry Pi is located at: /usr/lib/sftp-server, so we need to get WinSCP to execute it with sudo.

  • Go to your WinSCP profile (Session > Sites > Site Manager)
  • Click on Edit > Advanced… > Environment > SFTP
  • Insert sudo su -c /usr/lib/sftp-server at “SFTP Server”
  • Save and connect