Saturday, 17 April 2021

MTU issue with Zerotier

Just for the record, I had some issues using Zerotier between UK and US. For some reason, I could ping through with default packet size but ssh did not work. Once I changed MTU on UK side as follows it was working stable.

pi@pi0w:~ $ sudo nano /etc/dhcpcd.conf
interface wlan0
static interface_mtu=1200

Thursday, 1 April 2021

Exploring software defined radios

When last season Premier League restarted behind closed gates some games were broadcasted on Pick (a free to air Sky channel) paralell to paid streaming so I built a DVB-T hat on a Raspberry Pi Zero W. This was great fun running a small TV headend able to stream BBC One, BBC Two, iTV, Channel 4 and Channel 5 simultaneously, all in HD quality to Kodi installed on any device. But with the cease of free to air games I realised that watching TV on the corresponding apps (BBC iPlayer, iTV Hub, etc.) is actually even more convenient and does not disturb my daugther as reception was only adequate from her window upstairs.
Already back then I read about software defined radios (SDR) but unfortunately the DVB-T hat I got has a Sony CXD2880 tuner that only supports DVB-T/T2.
One of my friends told me he had a lot of fun with SDR during lockdown so I decided to buy a Realtek RTL2832U based USB dongle and plugged it to an unused Raspberry Pi 4B from the drawer.

pi@pi4b2:~ $ lsusb
Bus 001 Device 035: ID 0bda:2838 Realtek Semiconductor Corp. RTL2838 DVB-T

While DVB-T/T2 driver is loaded as default, there are plenty of other bands that can be demodulated as the underlying chip supports a test mode giving direct access to IQ stream output from the tuner. To get access to the other bands, first we need to blacklist the DVB driver:

pi@pi4b2:~ $ sudo nano /etc/modprobe.d/blacklist-dvb.conf
blacklist dvb_usb_rtl28xxu

After reboot we can install rtl-sdr package that is supported in Raspberry Pi OS:

pi@pi4b2:~ $ sudo apt install rtl-sdr
pi@pi4b2:~ $ rtl_test -t
Found 1 device(s):
  0:  Realtek, RTL2838UHIDIR, SN: 00000001

Using device 0: Generic RTL2832U OEM
Found Rafael Micro R820T tuner
Supported gain values (29): 0.0 0.9 1.4 2.7 3.7 7.7 8.7 12.5 14.4 15.7 16.6 19.7 20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4 37.2 38.6 40.2 42.1 43.4 43.9 44.5 48.0 49.6 
[R82XX] PLL not locked!
Sampling at 2048000 S/s.
No E4000 tuner found, aborting.

Now I was ready to join to an ADS-B community and start sharing. I picked flightradar24 and installed their service with:

pi@pi4b2:~ $ sudo bash -c "$(wget -O - https://repo-feed.flightradar24.com/install_fr24_rpi.sh)"
pi@pi4b2:~ $ fr24feed-status 
[ ok ] FR24 Feeder/Decoder Process: running.
[ ok ] FR24 Stats Timestamp: 2021-04-01 10:46:26.
[ ok ] FR24 Link: connected [UDP].
[ ok ] FR24 Radar: T-EGMD67.
[ ok ] FR24 Tracked AC: 19.
[ ok ] Receiver: connected (16814 MSGS/0 SYNC).
[ ok ] FR24 MLAT: ok [UDP].
[ ok ] FR24 MLAT AC seen: 19.

It runs quite nicely now with 500-900 aircrafts seen in a day. This gives me access to the business plan of flightradar24.com (for all its worth) and my contribution can be viewed online on flightradar24.com as some nice aggregated statistics graphs or more details on actual aircrafts seen locally on port 8754.

UPDATE

I kept having disconnected USB dongle issues. Some error messages in /etc/dmesg suggested powering issues although I was using the official Raspberry Pi power supply. I gave this USB-C hub with power charging input a try:
https://smile.amazon.co.uk/gp/product/B08KW2MCK2/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1

In order to use the USB power input of the Raspberry Pi in OTG mode I had to add this line to the boot config file:
pi@pi4b2:~ $ sudo nano /boot/config.txt
otg_mode=1

Friday, 27 November 2020

Connecting with my parents

I have installed a Raspberry Pi Zero at my parents' house in the summer to connect our LAN networks better. One particular use case is streaming at my parents' house via my broadband access. For this reason, I have dynamic DNS and PiVPN with WireGuard on the Raspberry Pi 1 at our house. This enables the use case for hosts that can install a WireGuard client. For hosts that can not install WireGuard client like Chromecast, the need emerges to build a small island at my parents' house with complete DHCP/WiFi infrastructure connected to the Internet via my broadband access. I used a small USB WiFi stick plugged into the USB hub with Ethernet that is connected to the Raspberry Pi Zero at my parents' house. Using this USB WiFi stick as an access point with hostapd and running dnsmasq for DHCP, I could build the basic infrastructure.

pi@pi0:~ $ sudo apt install hostapd
pi@pi0:~ $ sudo systemctl unmask hostapd
pi@pi0:~ $ sudo systemctl enable hostapd
pi@pi0:~ $ sudo nano /etc/hostapd/hostapd.conf
country_code=HU
interface=wlan0
ssid=ralink
hw_mode=g
channel=1
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=*****************
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
pi@pi0:~ $ sudo rfkill unblock wlan
pi@pi0:~ $ sudo nano /etc/dhcpcd.conf
interface wlan0
static ip_address=192.168.3.1/24
nohook wpa_supplicant
pi@pi0:~ $ sudo apt install dnsmasq
pi@pi0:~ $ sudo nano /etc/dnsmasq.conf
interface=wlan0
dhcp-range=192.168.3.2,192.168.3.20,255.255.255.0,24h
dhcp-option=6,8.8.8.8

As PiVPN on both sides were using conflicting IP addresses and WireGuard client can only be installed on Raspberry Pi OS based on Debian Buster with the hassle of backporting it from Debian Bullseye, I installed ZeroTier. For some reason, ZeroTier 1.6.1 does not install flawlessly on Raspberry Pi Zero so I had to make them from the git repository.

UPDATE

ZeroTier 1.6.2-2 now installs flawlessly on both Raspberry Pi Zero.

UPDATE 2

It turned out that Raspberry Pi 1 700 MHz CPU could not cope hairpin streaming with ZeroTier. Please note that hairpin streaming with WireGuard might be a working option even on Raspberry Pi 1 but it seems to be a hassle to backport WireGuard client from Debian Bullseye. Fortunately, I had an unused Raspberry Pi Zero W lying around as the only aerial position that provides good enough signal to its DVB-T hat is from my daughters' window upstairs and she refused to keep the window slightly open all day long for permanent installation. So instead of trying to move the setup over to WireGuard on Raspberry Pi 1 that has a lot of other duties anyway in my home, I gave this Raspberry Pi Zero W a try. It turned out that 1 GHz CPU clock speed is just enough for hairpin streaming with zerotier.

The resulting and relevant IP configuration with ASCII diagram is as follows:

pi@pi0w:~ $ ip a
wlan0: inet 192.168.1.10/24
zt5u4vfg76: inet 192.168.193.236/24

pi@pi0:~ $ ip a
eth0: inet 192.168.8.151/24
zt5u4vfg76: inet 192.168.193.79/24
wlan0: 192.168.3.1/24

wlan0 zt5u4vfg76 zt5u4vfg76 eth0
  |  ----------------------  |
  | |                      | |
 ------                   -----
| pi0w |                 | pi0 |
 ------                   -----
                           |
                           |/|
                             |
                          wlan0

The trickiest part of the routing is to direct the traffic from the small island DHCP/WiFi infrastructure into the ZeroTier link instead of the default route. I use a source-based rule with a separate routing table for this as follows, starting with enabling routing on both sides:

pi@pi0w:~ $ sudo nano /etc/sysctl.d/routed-ap.conf
net.ipv4.ip_forward=1

pi@pi0:~ $ sudo nano /etc/sysctl.d/routed-ap.conf
net.ipv4.ip_forward=1

pi@pi0:~ $ sudo nano /lib/dhcpcd/dhcpcd-hooks/40-route
/sbin/ip rule add from 192.168.3.0/24 table 1
/sbin/ip route add 192.168.3.0/24 via 192.168.3.1 table 1 
/sbin/ip route add default via 192.168.193.236 table 1

On my side of the ZeroTier link, I used NAT as follows:

pi@pi0w:~ $ sudo iptables -t nat -I POSTROUTING -j MASQUERADE
pi@pi0w:~ $ sudo iptables-save -f /etc/iptables.rules
pi@pi0w:~ $ sudo nano /etc/rc.local
iptables-restore /etc/iptables.rules

For static route for reverse traffic I used advanced manage route function on zero tier as follows:




To make this configuration persistent, I saved iptables rules and added ip commands to dhcpcd hooks.
The connection can be tested with tcpdump as follows:

pi@pi0w:~ $ sudo tcpdump -i zt5u4vfg76 net 192.168.3.0/24

UPDATE after 4 years

jordana@pi4g:~ $ sudo nano /etc/rc.local
#!/bin/bash
iptables-restore /etc/iptables.rules
jordana@pi4g:~ $ sudo chmod +x /etc/rc.local
jordana@pi4g:~ $ sudo reboot
jordana@pi4g:~ $ journalctl -b | grep rc.local
Dec 23 09:23:29 pi4g systemd[1]: Starting rc-local.service - /etc/rc.local Compatibility...
Dec 23 09:23:29 pi4g systemd[1]: Started rc-local.service - /etc/rc.local Compatibility.

Saturday, 31 October 2020

Building a Raspberry Pi 4 laptop

I was watching a lot of YouTube videos where people gave Raspberry Pi 4 a try as their primary PC. I got tempted myself but lacking a desk I had to explore the options of building a laptop based on Raspberry Pi 4. I have done a similar test with my Samsung 10-inch tablet in a Bluetooth keyboard case but as it still runs Android Nougat and has 1G of memory only the experience is really slow. The most important match to find was a Bluetooth keyboard case with a monitor. As a pointing device with a computer, the touchpad was a necessity on the keyboard too. In terms of size I was aiming at 10-inch again and found a reasonable match on Amazon:

10-inch monitor

Bluetooth keyboard and touchpad case

I managed to tie my Raspberry Pi and a big 20,000 mAh power bank to the case and used short USB power and HDMI cables to connect it all. 


The overall experience is pretty reasonable on Raspberry Pi OS. Unfortunately Bluetooth is not stable on Ubuntu desktop yet. YouTube in Chromium browser is playing without a noticable drop of frames up to 720p but even 1080p60 is watchable. Email and chat are widely supported with the exception of the Outlook desktop experience and WhatsApp Web. Lack of built in microphone makes it more difficult to test voice calls but even with a USB sound card the result is dubious. Telegram desktop does not recognise the USB sound card and Messenger from Chromium does not provide stable voice calls either. With some hacking even Netflix and Amazon Prime are running fine in Chromium. As the monitor has a second HDMI input the other use case that I am trying is Samsung Dex from my Galaxy S10. First try with a USB-C to HDMI adapter was quite reasonable also however not all apps are working fine. Netflix and BBC iPlayer are notable examples of apps that are not functioning correctly. To minimise the cableing I have a Miracast dongle shipping that I plan to test soon.

Saturday, 10 October 2020

[Updated] Removing quiet and splash options from command line of Debian RPD live USB with persistence

The excuse to remove quiet and splash options from the kernel command line of my Debian RPD live USB with persistence was the tty consoles did not reliably setup increased font size with dpkg-reconfigure console-setup on bootup. I have found xorriso and its alter ego osirrox to extract grub.cfg, remove the quiet and splash options and write it over back in the ISO image.

pi@raspberrypi:~ $ osirrox -dev Downloads/2020-02-12-rpd-x86-buster.iso
-extract boot/grub/grub.cfg grub.cfg
xorriso 1.5.0 : RockRidge filesystem manipulator, libburnia project.
xorriso : NOTE : Loading ISO image tree from LBA 0
xorriso : UPDATE : 5398 nodes read in 1 seconds
xorriso : NOTE : Detected El-Torito boot information which currently is set to be discarded
Drive current: -dev 'Downloads/2020-02-12-rpd-x86-buster.iso'
Media current: stdio file, overwriteable
Media status : is written , is appendable
Boot record : El Torito , MBR isohybrid cyl-align-on GPT APM
Media summary: 1 session, 1527416 data blocks, 2983m data, 521m free
Volume id : 'Debian RPD M-A 1'
xorriso : UPDATE : 1 files restored ( 1828b) in 1 seconds = 0.0xD
Extracted from ISO image: file '/boot/grub/grub.cfg'='/home/pi/grub.cfg'
pi@raspberrypi:~ $ chmod +w grub.cfg
pi@raspberrypi:~ $ nano grub.cfg
pi@raspberrypi:~ $ chmod -w grub.cfg
pi@raspberrypi:~ $ xorriso -indev 2020-02-12-rpd-x86-buster.iso /
-outdev 2020-02-12-rpd-x86-buster-mod.iso /
-map '/home/pi/grub.cfg' '/boot/grub/grub.cfg' /
-overwrite nondir /
-boot_image any keep /
-close off /
-write_type auto /
-stream_recording data /
-commit
xorriso : UPDATE : 5398 nodes read in 1 seconds
xorriso : NOTE : Loading ISO image tree from LBA 0
Drive current: -indev '/mnt/2020-02-12-rpd-x86-buster.iso'
xorriso : NOTE : Detected El-Torito boot information which currently
is set to be discarded
Media current: stdio file, overwriteable
Media summary: 1 session, 1527416 data blocks, 2983m data, 754g free
Media status : is written , is appendable
Boot record : El Torito , MBR isohybrid cyl-align-on GPT APM
Volume id : 'Debian RPD M-A 1'
Media summary: 0 sessions, 0 data blocks, 0 data, 754g free
Drive current: -outdev '/mnt/2020-02-12-rpd-x86-buster-mod.iso'
Media current: stdio file, overwriteable
Media status : is blank
xorriso : UPDATE : 1 files added in 1 seconds
xorriso : UPDATE : Writing: 4512s 0.3% fifo 0% buf 50%
Added to ISO image: file '/boot/grub/grub.cfg'='/home/pi/grub.cfg'
xorriso : NOTE : Keeping boot image unchanged
xorriso : UPDATE : Writing: 2048s 0.1% fifo 2% buf 50%
Writing to '/mnt/2020-02-12-rpd-x86-buster-mod.iso' completed successfully.
xorriso : UPDATE : Writing: 16384s 1.1% fifo 81% buf 50% 17.5xD
...
xorriso : UPDATE : Writing: 1523712s 99.9% fifo 75% buf 50% 18.7xD
ISO image produced: 1525788 sectors
Written to medium : 1525952 sectors at LBA 32
xorriso : UPDATE : 5398 nodes read in 1 seconds
xorriso : NOTE : Re-assessing -outdev '/mnt/2020-02-12-rpd-x86-buster-mod.iso'
xorriso : NOTE : Loading ISO image tree from LBA 0
libburn : SORRY : Read start address 1527415s larger than number of readable blocks 1525984
xorriso : NOTE : Detected El-Torito boot information which currently is set to be kept
unchanged
xorriso : NOTE : Tolerated problem event of severity 'SORRY'
Drive current: -dev '/mnt/2020-02-12-rpd-x86-buster-mod.iso'
Media current: stdio file, overwriteable
Media status : is written , is appendable
Boot record : El Torito , MBR cyl-align-on GPT APM
Media summary: 1 session, 1525788 data blocks, 2980m data, 751g free
Volume id : 'Debian RPD M-A 1'
xorriso : NOTE : -return_with SORRY 32 triggered by problem severity SORRY

xorriso : UPDATE : 5398 nodes read in 1 seconds
xorriso : UPDATE : 5398 nodes read in 1 seconds

This made increased font size reliably setup during boot of Debian RPD live USB with persistence.

[Update]

As my cheap USB SATA SSD frequently stopped working with kernel messages that suggested uas
driver is the culprit. So in order to fall back on legacy storage driver, I have looked up the idVendor and
idProduct in dmesg of my cheap USB SATA SSD and added this to the kernel command line:

usb_storage.quirks=2109:0715:u

Wednesday, 7 October 2020

Appearance fine tuning

As my eyes are getting weaker, I do not feel comfortable with the default font size on my 14" laptop screen using 1920x1080 resolution. I had to add this file to make fonts bigger:

pi@raspberrypi:~ $ nano .Xresources 
Xft.dpi: 140

This made the taskbar icons look smaller, so I increased them in Appearance Settings.

For tty, that I very rarely use I have set up the maximal 16x32 characters using:

pi@raspberrypi:~ $ sudo dpkg-reconfigure console-setup

Monday, 5 October 2020

Boosting Raspberry Pi Desktop experience with SSD

While my sleek SanDisk Cruzer Fit was great to give me the initial insight into Debian with Raspberry Pi Desktop, it is so sluggish that seriously deteriorates user experience. As a matter of fact, this SanDisk Cruzer Fit USB 2.0 flash drive is so slow that it even fails Raspberry Pi Diagnostics badly. At the same time, Raspberry Pi OS has recently made booting from USB officially supported on Raspberry Pi 4b.

As both of my laptop and the Raspberry Pi 4b supports USB 3, it made me look into investing a bootable USB 3 solution. In these investment investigations, I usually try to find the cheapest solution on Amazon. I have found for £10 a 64 GB M2 2242 SATA SSD that fits into a £20 USB 3 enclosure. While it sticks out of my laptop much more than the SanDisk Cruzer Fit did, the responsiveness it offers made me stick with it.

Just for the records, I have run Raspberry Pi Diagnostics on this new SSD drive both in my laptop and in the Raspberry Pi 4b.

Here are the results in my laptop:

Raspberry Pi Diagnostics - version 0.5
Sun Oct  4 18:13:59 2020
Test : SD Card Speed Test
Run 1
prepare-file;0;0;156410;305
seq-write;0;0;163024;318
rand-4k-write;0;0;16137;4034
rand-4k-read;16773;4193;0;0
Sequential write speed 163024 KB/sec (target 10000) - PASS
Random write speed 4034 IOPS (target 500) - PASS
Random read speed 4193 IOPS (target 1500) - PASS
Test PASS

Here are the results in the Raspberry Pi 4b:

Raspberry Pi Diagnostics - version 0.5
Sun Oct  4 16:11:35 2020
Test : SD Card Speed Test
Run 1
prepare-file;0;0;157538;307
seq-write;0;0;161418;315
rand-4k-write;0;0;49461;12365
rand-4k-read;48259;12064;0;0
Sequential write speed 161418 KB/sec (target 10000) - PASS
Random write speed 12365 IOPS (target 500) - PASS
Random read speed 12064 IOPS (target 1500) - PASS
Test PASS