Raspberry Pi

From Indie IT Wiki

Products

https://www.raspberrypi.org/products

Purchase

Power Supply with On Off Switch

https://www.amazon.co.uk/NorthPada-Raspberry-Tinker-Charger-Adapter/dp/B07MLZQXS7

Starter Kit

VESA Mounting Case

Downloads

Raspbian

DietPi

Installation - Ubuntu 14.04 LTS

NOTE: The following is only applicable to the Raspberry Pi 2.

  • Download the Ubuntu image for Pi here
  • Extract the zip file

Used this as a guide.

Installation

https://www.youtube.com/watch?v=G2M1Ev_ShP0

Install an enhanced version of dd to show progress bars...

sudo aptitude install -y dcfldd

Insert the SD card, and check which disk Linux sees...

cat /proc/partitions 

Extract the downloaded .zip file...

cd /path/to/download/
unzip 2014-06-20-wheezy-raspbian.zip

Now, as root user, run dcfldd instead of the normal dd...

sudo dcfldd bs=4M if=2014-06-20-wheezy-raspbian.img of=/dev/sdb

Customisation With Raspi-Config

Most settings and changes to the system can now be made easily with this new tool called raspi-config.

sudo raspi-config

http://www.raspberrypi.org/documentation/configuration/raspi-config.md

First Boot With Windows Generated SD-Card

The first screen on boot up gives you various options, one of which is to resize the OS to use all of the SD-Card. Do this, then set keyboard, locale etc continue through until you are at a point where you can reboot the system.

HOWTO: MODIFY:

HDMI Output

# Uncomment to force a specific HDMI mode (this will force VGA).
#hdmi_group=2 # (Monitor)
#hdmi_mode=82 # (Monitor - Acer Full HD)
hdmi_group=1 # (TV)
hdmi_mode=31 # (TV - JVC 1080p 50Hz)

https://www.raspberrypi.org/documentation/configuration/config-txt/video.md

https://www.childs.be/blog/post/raspberry-pi-3-hdmi-overscan-settings-and-how-to-correct-them

Tweaks

  • disable swap
  • log to ram

Log2RAM

sudo -i
echo "deb http://packages.azlux.fr/debian/ buster main" | sudo tee /etc/apt/sources.list.d/azlux.list
wget -qO - https://azlux.fr/repo.gpg.key | sudo apt-key add -
apt-get update
apt-get install log2ram
sudo reboot

https://ideaheap.com/2013/07/stopping-sd-card-corruption-on-a-raspberry-pi/

Firmware

A firmware update will allow you to boot from a USB drive instead of a micro SD card for speed improvements...

https://www.tomshardware.com/how-to/boot-raspberry-pi-4-usb

NOTES

Update EEPROM

sudo dietpi-config - advanced - eeprom

https://dietpi.com/phpbb/viewtopic.php?f=15&t=8190

Command Line Aliases

Open a terminal and edit the .bashrc file:

Terminal:~$

nano ~/.bashrc

Edit or add the following lines:

nano

alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias get='get_iplayer/get_iplayer'
alias grep='grep --color=auto'
alias install='sudo apt-get install'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -lah'
alias ls='ls --color=auto'
alias myip='curl ifconfig.me'
alias ping='ping -c3 -n -i 0.2 -W1'
alias pingg='ping www.google.co.uk'
alias pingp='ping www.paully.co.uk'
alias rav='rsync -a -v'
alias remove='sudo apt-get autoremove'
alias rm='rm -iv'
alias search='sudo apt-cache search'
alias update='sudo apt-get update'
alias upgrade='sudo apt-get upgrade'
alias uu='sudo apt-get update && sudo apt-get upgrade'
alias uuf='sudo apt-get update && sudo apt-get dist-upgrade'

CTRL+O then CTRL+X to save and close the file.

Reload the file:

Linux Terminal:~$

source ~/.bashrc

confirm the entries

alias

INFO

Default Username & Password - Debian

Username: pi
Password: raspberry

Default Username & Password - DietPi

Username: root
Password: dietpi

Default Username & Password - Ubuntu

Username: ubuntu
Password: ubuntu

Default Username & Password - Other Distros

Other Distros

FAQ and other resources

http://www.raspbmc.com/wiki/user/frequently-asked-questions/

http://simonthepiman.com/beginners_guide_to_raspberry_pi_unix.php

http://www.raspberrypi-tutorials.co.uk/set-raspberry-pi-wireless-network/

HOWTO: INSTALL

FFMPEG with GPU support for Raspberry Pi

Using the following script will install and configure FFMPEG GPU support on your Pi3 / 4 device ready for transcoding.

#!/bin/bash

# example: ffmpeg -c:v h264_mmal -i http://a.files.bbci.co.uk/media/live/manifesto/audio_video/simulcast/hls/uk/abr_tv/ak/bbc_parliament.m3u8 -c:v h264_omx -c:a copy -b:v 1500k output.mp4

echo "Installing FFMPEG with GPU support for Raspberry Pi"

cd /root

sudo -y apt-get update
sudo -y apt-get install autoconf automake build-essential libass-dev libfreetype6-dev \
libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev \
libxcb-xfixes0-dev pkg-config texinfo zlib1g-dev

cd ~
git clone https://github.com/ffmpeg/FFMpeg --depth 1

cd ~/FFMpeg
./configure --enable-gpl --enable-nonfree --enable-mmal --enable-omx --enable-omx-rpi
make -j4
make install

echo "Install should now be complete. Please check the above output for any error messages."

exit;

https://www.worldofiptv.com/threads/raspberry-pi-gpu-transcoding.8664/

Webmin

https://prdownloads.sourceforge.net/webadmin/webmin_1.900_all.deb

https://pimylifeup.com/raspberry-pi-webmin/

MailX

This will install a very minimal (80Kb!) app for sending emails in conjunction with sSMTP, instead of the 8MB of 'mailutils' or 'mutt'.

sudo aptitude install bsd-mailx

You can then pipe a test message...

echo "message" |mail -s "test" you@email.com

Enable SSH Server Headless

  1. Put the microSD card in the card reader of your computer.
  2. In your file manager explorer software, click to mount and open the boot partition.
  3. File > Create Document > Empty File
  4. Name it 'ssh'
  5. Click your right mouse button on the partition and choose 'Unmount'.
  6. Take out the MicroSD Card from the computer.
  7. Put the MicroSD Card in to the Raspberry Pi and switch on.

When the Raspberry Pi boots, it looks for the ssh file and if it is found, it enables SSH and deletes the file.

https://www.shellhacks.com/raspberry-pi-enable-ssh-headless-without-monitor/

SSH Server

Terminal:~$

sudo raspi-config 

Navigate to:

Option 9 - Advanced Options | Option A4 - Enable/Disable remote command line access of your Pi using SSH

Thanks to RaspberyPi.org

Hardware Lister

Linux Terminal $:

sudo apt-get install lshw

Hardware Lister | USB Connected Devices

Linux Terminal $:

sudo apt-get install usbutils

HOWTO: INFO

Screen Resolution

View current console resolution - probably frame buffer...

fbset

How to set in various methods...

https://pimylifeup.com/raspberry-pi-screen-resolution/

Power Supply Usage

They all need a 5V power supply but the Amp requirements change for each model. This is from personal experience and light non-overclocked usage. I just grabbed one of the many USB power supplies lying around the house and tried them until I didn't get a warning in the error log for 'under voltage detected' or the yellow lightning symbol show on the screen during boot up :-)

  • Raspberry Pi 4 Model B = 3A
  • Raspberry Pi 3 Model B+ = 2.1A
  • Raspberry Pi 3 Model B = 2.1A
  • Raspberry Pi 2 Model B = 2.1A
  • Raspberry Pi 1 Model B = 1.8A
  • Raspberry Pi Zero W = 1.4A
  • Raspberry Pi Zero = 1A

LCD Screen

3.5" 320*480 TFT Touch Screen LCD Display Case For Raspberry Pi A B A+ 2B3B3B PM

Driver Setup Video

SD Card Speeds

  • Class 4 = 4MB/s
  • Class 10 = 10MB/s

https://www.raspberrypi.org/blog/sd-card-speed-test/

sudo apt-get install hdparm 
sudo hdparm -tT /dev/mmcblk0

https://ozzmaker.com/how-to-test-the-sd-card-speed-on-your-raspberry-pi/

sudo apt-get install agnostics
cd /usr/share/agnostics && sh sdtest.sh

https://geektechstuff.com/2020/03/08/raspberry-pi-microsd-check-using-agnostics-via-cli-raspberry-pi/

CPU Stats

https://gist.github.com/ecampidoglio/5009512

Run Script On Boot with DietPi

To run a script on boot, you have plenty possibilities. If you are not too experienced, you can simply put it into /var/lib/dietpi/postboot.d. The DietPi boot scripts will execute it automatically with root permissions then, once the boot process has fully finished, thus network is assured, but BEFORE login/outside the login shell.

Change SSH Server from Dropbear to OpenSSH

dietpi-software > SSH Server

https://dietpi.com/docs/dietpi_tools/

Temperature

sudo vcgencmd measure_temp

Model

MODEL=$(tr -d '\0' </proc/device-tree/model); echo "$MODEL"

Display

Check HDMI Port

 tvservice -n

https://raspberrypi.stackexchange.com/questions/46153/detect-hdmi-and-start-gui

Discovery

How to find a Raspberry Pi in Microsoft Windows or Mac or Linux...

C:\> arp -a | findstr /i "b8-27-eb dc:a6:32"
$ arp -a | grep -i "b8:27:eb\|dc:a6:32"
$ sudo nmap -sP -r -n 192.168.1.0/24 | grep -i "b8:27:eb\|dc:a6:32" -B2

https://www.shellhacks.com/find-raspberry-pi-ip-on-network-windows-macos-linux/

Reboot On Network Failure

root@raspberrypi:~# cat /etc/cron.d/reboot-on-connection-failure
*/20 * * * * root /usr/bin/host google.com > /dev/null 2>1 || (/usr/bin/logger "Rebooting due to connectivity issue"; /sbin/shutdown -r now)

Cloud Management

Balena

Balena Sound - multiroom audio with Spotify and Bluetooth.

Balena Raspberry Pi Cloud Management

Balena OS

Bluetooth Audio Project

Turn your old speakers or Hi-Fi into Bluetooth receivers with a Raspberry Pi

Video Settings

https://www.raspberrypi.org/documentation/configuration/config-txt/video.md

Console Font Size

Method 1

sudo dpkg-reconfigure console-setup

UTF8 > Guess optimal character set > Terminus > 16×32

https://www.raspberrypi-spy.co.uk/2014/04/how-to-change-the-command-line-font-size/

Method 2

This method involves editing a system file. You just need to load it into your preferred text editor and tweak a few lines :

sudo nano /etc/default/console-setup

FONTFACE="Terminus"
FONTSIZE="16x32"

sudo /etc/init.d/console-setup restart

Reboot On Connection Failure

http://wiki.indie-it.com/wiki/BASH#HOWTO:_Reboot_On_Connection_Failure

PIR Motion Sensor

Wiring PIR No Breadboard

Python Software

Backup SD Card

Install software...

sudo apt-get install gddrescue

Check disk assignment...

sudo lsblk

Perform backup...

sudo ddrescue /dev/sdb raspberry_pi.img raspberry_pi_backup.log

Shrink SD Card Backup Image

NEW SCRIPTED METHOD

UPDATE: 2020-01-05 / ok, so someone has created an awesome script to do all the commands below automatically :-)

https://github.com/Drewsif/PiShrink

wget https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh
chmod +x pishrink.sh
sudo mv pishrink.sh /usr/local/bin
sudo pishrink.sh pi_tft_pishrink.img
pishrink.sh v0.1.2
pishrink.sh: Gathering data ...
Creating new /etc/rc.local
pishrink.sh: Checking filesystem ...
rootfs: 114190/467712 files (0.3% non-contiguous), 910213/1873920 blocks
resize2fs 1.45.5 (07-Jan-2020)
pishrink.sh: Shrinking filesystem ...
resize2fs 1.45.5 (07-Jan-2020)
Resizing the filesystem on /dev/loop0 to 935986 (4k) blocks.
Begin pass 2 (max = 37885)
Relocating blocks             XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 58)
Scanning inode table          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 9574)
Updating inode references     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/loop0 is now 935986 (4k) blocks long.
pishrink.sh: Shrinking image ...
pishrink.sh: Shrunk pi_tft_pishrink.img from 7.5G to 3.9G ...

Wow.

OLD MANUAL METHOD

Put the Raspberry Pi SD Card in to your computer using an adapter, then run the following commands to shrink the size of the image file so that you can fit it on to a 4GB or 8GB SD Card :-)

The magic command is 'truncate' but be careful, you have to match that large number to your end sector in the 'fdisk -l' command output...

sudo lsblk
sudo blkid
sudo fdisk -l 
sudo ddrescue -f -n /dev/sda pi_zero.img pi_zero.log
cp -av pi_zero.img pi_zero_shrunk.img 
file pi_zero_shrunk.img 
fdisk -l pi_zero_shrunk.img
sudo modprobe loop
sudo losetup -f
sudo losetup /dev/loop0 pi_zero_shrunk.img
sudo partprobe /dev/loop0
ll /dev/loop0*
sudo apt-get -y install gparted
sudo gparted /dev/loop0
(now shrink your main SD card partition by right-clicking then Resize/Move leaving about 100Mb after the end of the used space for a bit of wiggle room)
sudo sync
sudo losetup -d /dev/loop0
fdisk -l pi_zero_shrunk.img
truncate --size=$[(5789695+1)*512] pi_zero_shrunk.img    (this figure is YOUR sector End number)
ll pi_zero_shrunk.img
file pi_zero_shrunk.img
fdisk -l pi_zero_shrunk.img

https://itectec.com/ubuntu/ubuntu-re-size-the-img-for-smaller-sd-card-how-to-shrink-a-bootable-sd-card-image/

Restore SD Card

Check disk assignment...

sudo lsblk

Perform restore...

sudo ddrescue --force raspberry_pi.img /dev/sdb raspberry_pi_restore.log

Expand Filesystem

sudo raspi-config --expand-rootfs

DDRescue-GUI

http://www.hamishmb.altervista.org/html/downloads.php?program_name=ddrescue-gui

Touch Screen Display

Kiosk

To be done...



https://grafana.com/grafana/plugins/yesoreyeram-boomtheme-panel/installation

https://pimylifeup.com/raspberry-pi-kiosk/

https://www.loganmarchione.com/2020/05/always-on-grafana-dashboard-using-raspberry-pi-touchscreen/

DNS Ad Blocking

Install dietpi first, then change the SSH server from 'dropbear' to 'ssh', because this will enable you to use gravity-sync and the ssh environment variables.

Pi-Hole

The Pi-hole® is a DNS sinkhole that protects your devices from unwanted content, without installing any client-side software. It blocks adverts and tracking across your whole network and all your devices.

It is definitely a good idea to have 2 pi-holes and use 'gravity-sync' between them (see above), then back them up using 'ddrescue' every week (just in case the SD card fails)!

Test using a typical (short) blocked domain which should give you an answer of IP address 0.0.0.0 ;-)

host g.live.com
g.live.com has address 0.0.0.0

dig @pihole2 g.live.com
;; ANSWER SECTION:
g.live.com.		2	IN	A	0.0.0.0
;; Query time: 44 msec
;; SERVER: 192.168.0.10#53(192.168.0.10)

Digital Signage

Screenly

Installation

  • install Raspberry Pi OS Desktop
  • configure console font with sudo dpkg-reconfigure console-setup for Terminus 16x32 - check /etc/default/console-setup
  • run sudo raspi-config and change System Settings > Boot Console + auto login pi user
  • reboot to check font size
  • run command to install Screenly and reboot...
bash <(curl -sL https://www.screenly.io/install-ose.sh)
  1. Do you wish to continue > Y
  2. Press 1 for the Production Branch
  3. Do you want Screenly to manage your network > N
  4. Do you wish to perform a full system upgrade > N
  5. Reboot

Fix WiFi

You have to disable the screenly 'wifi-connect' service, then use Network Manager to setup the wifi, then enable the 'wifi-connect' service again. Madness. This is because the wifi-connect service disables the use of the wireless chip.

sudo systemctl disable wifi-connect.service
sudo reboot
sudo nmcli device wifi rescan
sudo nmcli device wifi list
sudo nmcli device wifi connect SSID-Name password wireless-password hidden yes
sudo iwconfig
sudo ipconfig
sudo reboot
sudo systemctl enable wifi-connect.service
sudo reboot

https://github.com/screenly/screenly-ose

https://www.screenly.io/ose/

https://pimylifeup.com/raspberry-pi-screenly/

https://support.screenly.io/hc/en-us/articles/360042164173-Getting-started-with-Screenly-OSE

Raspberry Slideshow Distribution

http://www.binaryemotions.com/raspberry-slideshow-faq/

Camera

https://projects.raspberrypi.org/en/projects/getting-started-with-picamera

https://www.raspberrypi.org/products/camera-module-v2/

http://www.securipi.co.uk/senior-guardian-project-for-raspberry-pi-with-pir-sensor/

Remote Desktop

Virtual Desktop

:1

This is a second pseudo desktop which is different to the one shown on your connected monitor.

Terminal > raspi-config > Advanced Options > VNC > Enable > Yes

https://www.realvnc.com/en/connect/download/vnc

Actual Desktop

:0

This is the desktop running which is the same one shown on your connected monitor.

This requires an extra add-on to the tiger VNC software called a 'X scraping server'.

x0tigervncserver (hence the :0) is a TigerVNC Server which makes any X display remotely accessible via VNC, TigerVNC or compatible viewers. Unlike Xvnc, it does not create a virtual display. Instead, it just shares an existing X server (typically, that one connected to the physical screen).

sudo apt-get install tigervnc-scraping-server

You will also need the binary called 'vncpasswd' which is part of the 'tigervnc-common' package.

sudo apt-get install tigervnc-common

https://www.howtoforge.com/tutorial/how-to-start-a-vnc-server-for-the-actual-display-scraping-with-tigervnc/

Virtual Desktop

If your Raspberry Pi is headless (that is, not plugged into a monitor) or embedded in a robot, it’s unlikely to be running a graphical desktop.

VNC Server can run in Virtual Mode to create a resource-efficient virtual desktop on demand, giving you graphical remote access even when there is no actual desktop to remote. This virtual desktop exists only in your Raspberry Pi’s memory.

https://www.realvnc.com/en/connect/docs/raspberry-pi.html#raspberry-pi-virtual

Wake Up TV

https://raspberrypi.stackexchange.com/questions/7054/cec-wake-up-command

Kiosk Mode

pi@raspberrypi:~ $ nano .config/lxsession/LXDE-pi/autostart

@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@point-rpi
@xset s off
@xset -dpms
@xset s noblank
@/usr/bin/chromium-browser --noerrdialogs --kiosk www.google.co.uk

Thanks - https://www.danpurdy.co.uk/web-development/raspberry-pi-kiosk-screen-tutorial/

Close Chromium Browser When In Kiosk Mode

Keyboard

ALT+F4

Console

sudo pkill chromium-browser

Automatically Switch Between Browser Tabs Set Interval

sudo apt-get install xdotool unclutter

After the download is finished, open the autostart file (.config/lxsession/LXDE-pi/autostart) and add this line:

@lxterminal --command unclutter & watch -n10 "xdotool search --class --onlyvisible Chromium windowfocus && xdotool key ctrl+Tab F5"

This switches the tabs and refreshes the site every 60 seconds. Save the file and reboot. Now chromium should automatically switch tabs and refresh.

Thanks - https://www.danpurdy.co.uk/web-development/raspberry-pi-kiosk-screen-tutorial/

Autostart Apps On Login

https://raspberrypi.stackexchange.com/questions/8734/execute-script-on-start-up

pi@raspberrypi:~ $ nano .config/lxsession/LXDE-pi/autostart

@lxpanel --profile LXDE-pi
@pcmanfm --desktop --profile LXDE-pi
@point-rpi
@xset s off
@xset -dpms
@xset s noblank
@/usr/bin/chromium-browser --noerrdialogs --kiosk www.google.co.uk

List of Chromium switches

Thanks - https://raspberrypi.stackexchange.com/questions/27572/how-to-auto-start-chromium-after-boot-on-the-raspberry-2-2015-01-31-debian-whee#27575

Looping Video Playlist With Omxplayer

omxplayer - http://elinux.org/Omxplayer

Python Script

The indentations below must be there, and yes that last line is indented twice (that's Python for you!).

You can change the extra output options for omxplayer to hdmi but this example is alsa (headphone jack)...

cd /home/pi
nano omxloop.py
#!/usr/bin/python
import sys
import subprocess
import os
import glob
path ='/home/pi/Videos/'
while(1):
  for infile in glob.glob(os.path.join(path, '*.mp4')):
    a = subprocess.call( [ "omxplayer", "-o", "alsa", infile])
chmod +x omxloop.py
./omxloop.py

Thanks - https://gist.github.com/simmogs/6668652

BASH Script

sudo nano ~/videoplayer.sh
#!/bin/sh
# get rid of the cursor so we don't see it when videos are running
setterm -cursor off
# set here the path to the directory containing your videos
VIDEOPATH="/mnt/storage/videos" 
# you can normally leave this alone
SERVICE="omxplayer"
# now for our infinite loop!
while true; do
       if ps ax | grep -v grep | grep $SERVICE > /dev/null
       then
       sleep 1;
else
       for entry in $VIDEOPATH/*
       do
               clear
               omxplayer --blank -o hdmi "$entry" > /dev/null
       done
fi
done
chmod +x videoplayer.sh
./videoplayer.sh

Force HDMI Sound Output

sudo nano /boot/config.txt

Either add or uncomment the line hdmi_drive=2 then ctrl-o to write the changes and ctrl-x to exit the nano text editor.

Reboot and the HDMI sound will work.

Turn Off Screensaver Screen Blanking

sudo nano /etc/kbd/config
BLANK_TIME=0
POWERDOWN_TIME=0

sudo nano /etc/xdg/lxsession/LXDE/autostart /etc/xdg/lxsession/LXDE-pi/autostart /home/pi/.config/lxsession/LXDE-pi/autostart
#@xscreensaver
@xset s noblank
@xset s off
@xset -dpms

sudo reboot

Find Distribution Version

sudo apt-get install lsb-release

Usage:

lsb_release -a

Switching To Root

sudo -i

Wireless (Built In) Raspberry Pi3

sudo ifconfig wlan0 up
sudo iwconfig
sudo iwlist wlan0 scan | grep 'SSID'
sudo -i
sudo wpa_passphrase "SSID" "Password" >> /etc/wpa_supplicant/wpa_supplicant.conf
sudo nano /etc/network/interfaces
  allow-hotplug eth0
  iface eth0 inet dhcp
  allow-hotplug wlan0
  iface wlan0 inet dhcp
  wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
sudo reboot

nmcli Network Config Tool

Check wireless radios...

nmcli radio

List network devices...

nmcli device

Scan wireless networks...

nmcli device wifi rescan

List wireless networks...

nmcli device wifi list

Connect to wireless network...

nmcli device wifi connect SSID-Name password wireless-password

Connect to a hidden wireless network...

nmcli device wifi connect SSID-Name password wireless-password hidden yes

Reboot...

reboot

Check network interfaces...

ifconfig

nmcli Network Config Tool

Connect to a wireless network using command line nmcli

New Method

OLD Wizard

OLD (no longer used)

sudo nano /boot/network.ini
  [wlan0]
  ssid=SSID
  passphrase=hkws8348wf
  mode=dhcp
sudo reboot
sudo reboot (yes twice)

https://www.screenly.io/ose

https://github.com/screenly/screenly-ose/releases

Similar To Screenly

nmtui

Wireless Dongle

NEW

sudo iwconfig
sudo iwlist wlan0 scan | grep 'SSID'
sudo -i
sudo wpa_passphrase "SSID" "Password" >> /etc/wpa_supplicant/wpa_supplicant.conf
sudo nano /etc/network/interfaces
  allow-hotplug eth0
  iface eth0 inet dhcp
  allow-hotplug wlan0
  iface wlan0 inet dhcp
  wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
sudo reboot


OLD

Bus 001 Device 005: ID 148f:5370 Ralink Technology Corp. RT5370 Wireless Adaptor
sudo cp /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf.bak
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
network={
       ssid="<SSID of your wifi network>"
       psk="<the password for this network>"
}
sudo wpa_action wlan0 stop
sudo ifup wlan0
sudo wpa_cli status
sudo ifconfig 

https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md

https://www.modmypi.com/wireless-usb-1n-nano-adaptor-802.11N-wifi-dongle?filter_name=Wireless

https://www.modmypi.com/blog/how-to-set-up-the-ralink-rt5370-wifi-dongle-on-raspian

...

TP-Link TL-WN725N v.1 - Realtek 8188CUS chipset

HOWTO: ALTER:

Disable Quiet Boot

This will allow you to see the kernel loading on boot (which might help with any problems of display, etc.)...

Edit the /boot/cmdline.txt file and remove the entry quiet from the boot line.

Get Proper Flashing Cursor Prompt In Terminal

Edit the /boot/cmdline.txt file and remove the entry vt.global_cursor_default=0 from the boot line.

Disable Bluetooth

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

https://scribles.net/disabling-bluetooth-on-raspberry-pi/

Disable Audio

Add or edit the following line in /boot/config.txt

dtparam=audio=off

Disable IPv6

https://cwesystems.com/?p=231

Delete Secondary IP Address

For some reason, you might end up with 2 IP addresses for your Pi like this...

link/ether b8:27:eb:50:ec:f4 brd ff:ff:ff:ff:ff:ff
inet 10.0.55.5/24 brd 10.0.55.255 scope global eth0
   valid_lft forever preferred_lft forever
inet 10.0.55.55/24 brd 10.0.55.255 scope global secondary eth0
   valid_lft forever preferred_lft forever

To remove the secondary IP, you need to stop and disable the 'dhcpd' service and then delete the IP. On reboot, you will be left with one.

NOTE - You might need to do this with a keyboard and monitor attached!

sudo update-rc.d dhcpcd disable
sudo service dhcpcd stop
sudo ip addr del %YOURS-SECOND-IP% dev ethX
sudo reboot

Turn Off LEDs

Add the following lines to /boot/config.txt and reboot...

# Disable Ethernet LEDs
dtparam=eth_led0=14
dtparam=eth_led1=14

# Disable the PWR LED
dtparam=pwr_led_trigger=none
dtparam=pwr_led_activelow=off

# Disable the Activity LED
dtparam=act_led_trigger=none
dtparam=act_led_activelow=off

https://www.raspberrypi.org/forums/viewtopic.php?t=149126

Delete User pi

sudo -i
passwd root
useradd -c "Pi User" -d /home/piuser -m -s /bin/bash -U piuser
passwd piuser
gpasswd -a piuser sudo
gpasswd -a piuser adm
delgroup pi sudo
rm -iv /etc/sudoers.d/010_pi-nopasswd
userdel -f -r pi
exit
logout

Harden SSH Server

sudo nano /etc/ssh/sshd_config
  LoginGraceTime 30s
  PermitRootLogin no               
  AllowUsers piuser
sudo service sshd restart

Firewall

sudo apt-get update
sudo apt-get install ufw
sudo ufw allow from 192.168.0.0/24 to any port 22 proto tcp
sudo ufw enable
sudo ufw status numbered verbose

SD Card Partition Size

http://elinux.org/RPi_Resize_Flash_Partitions

How To Find Out The Actual SD Card Size

dmesg |grep 'SD'
cd /sys/class/mmc_host/mmc?/mmc?:*
echo "man:$(cat manfid) oem:$(cat oemid) name:$(cat name) hwrev:$(cat hwrev) fwrev:$(cat fwrev)"

Thanks - http://elinux.org/RPi_SD_cards

Font Size In Terminal

sudo dpkg-reconfigure console-setup
  • Select text encoding | OK
  • Select "Guess optimal character set | OK
  • Select "Terminus" | OK
  • Select font size | OK

HOWTO: FIX:

wifi wlan0 unavailable

Use wpa_cli to scan and connect to a wireless network, then setup a standard wpa_supplicant.conf file.

https://unix.stackexchange.com/questions/458406/network-manager-works-but-wlan-is-unavailable-for-nmcli

pi@raspberrypi:~ $ sudo wpa_cli -i wlan0
wpa_cli v2.8-devel
Copyright (c) 2004-2019, Jouni Malinen <j@w1.fi> and contributors
This software may be distributed under the terms of the BSD license.
See README for more details.

Interactive mode

> ADD_NETWORK
0
> SET_NETWORK 0 ssid "MYWIFI"
OK
> SET_NETWORK 0 psk "mYpAsshrase"
OK
> ENABLE_NETWORK 0
OK
<3>CTRL-EVENT-SCAN-STARTED 
<3>CTRL-EVENT-SCAN-RESULTS 
<3>Trying to associate with SSID 'SMITH3'
> quit

iwconfig
ifconfig
sudo wpa_cli -i wlan0 LIST_NETWORKS

To make this permanent, edit the /etc/wpa_supplicant/wpa_supplicant.conf file and add the lines with your wireless network settings to match.

country=gb
update_config=1
ctrl_interface=/var/run/wpa_supplicant
network={
 scan_ssid=1
 ssid="MyNetworkSSID"
 psk="Pa55w0rd1234"
}

If a wpa_supplicant.conf file is placed into the /boot/ directory, this will be moved to the /etc/wpa_supplicant/ directory the next time the system is booted, overwriting the network settings; this allows a Wifi configuration to be preloaded onto a card from a Windows or other machine that can only see the boot partition.

OMX Player ERROR: Raspberry Pi COMXAudio::Decode Timeout

sudo nano /boot/config
  gpu_mem=128
sudo reboot

Missing Sound On HDMI

https://www.raspberrypi.org/documentation/configuration/audio-config.md

Check DOS VFAT Boot Partition

sudo aptitude install -y dosfstools
sudo fsck.vfat -v -a -t -V -w /dev/mmcblk0p1
sudo reboot

Missing Characters On Either Side Of The Screen

Terminal:~$

sudo nano /boot/config.txt

#disable_overscan=1
overscan_left=30
overscan_right=30

30 is an arbitrary figure, experiment for your own setup.

Hardware Addons

HiFiBerry - The HiFiBerry Digi+ is a high-quality S/PDIF output board for the Raspberry Pi. It comes in three different versions, compatible with different Raspberry Pis. The dedicated S/PDIF interface chip supports up to 192kHz/24bit resolution. This will enable you to have DTS passthrough on Plex or Kodi or OpenElec.

Strawberry 4 Pi - The product you were waiting for. App and baseboard integrated to control any electrical device. Easier than ever. Use its base functionality and create any DIY project you want with a Raspberry Pi Zero W and your Strawberry4Pi.