2023年12月30日土曜日

Raspberry Pi 4 + DVB-T + Ubuntu 22.04.3 server で ADS-B 受信機を作成 ( Flightradar24、FlightAware、RadarBox )

ADS-B 受信機を Ubuntu 22.04.3 に更新です。
最近、この RasPi を Radiko ダウンロードサーバと兼用しているので、microSD の容量大きめ (256GB) です。

■ 環境

HardwareRaspberry Pi 4 Model B / 4 GB
OSUbuntu Server 22.04.3 64-bit
SDSanDisk microSDXC Ultra Class10 UHS-I A1 128GB
DVB-TR820T2 & SDR+SMD X-tal 10PPM [DVB-T+FM+DAB/RTL-SDR][RTL2832U+R820T2][High quality USB-CN][広帯域受信用]Blue

1. Ubuntu Server 22.04.3 イメージを micro SD に書き込む

Ubuntu のサイト から Ubuntu Server のイメージを取得。micro SD に書き込む。

$ sudo apt install gddrescue xz-utils
$ unxz ubuntu-22.04.3-preinstalled-server-arm64+raspi.img.xz
$ sudo ddrescue -D --force ubuntu-22.04.3-preinstalled-server-arm64+raspi.img /dev/mmcblk0

GNU ddrescue 1.23
Press Ctrl-C to interrupt
     ipos:    4539 MB, non-trimmed:        0 B,  current rate:  14417 kB/s
     opos:    4539 MB, non-scraped:        0 B,  average rate:  14834 kB/s
non-tried:  460714 kB,  bad-sector:        0 B,    error rate:       0 B/s
  rescued:    4539 MB,   bad areas:        0,        run time:      5m  6s
pct rescued:   90.78%, read errors:        0,  remaining time:         32s
                              time since last successful read:          0s
Copying non-tried blocks... Pass 1 (forwards)

2. Ubuntu Server 22.04.3 諸設定

デフォルトユーザのログインは、User: ubuntu, Password ubuntu で。
最初のログインは、起動してからちょっと待ったほうが良い。
パスワード変えるのと、adduser でユーザを作成。
SSHd は、最初から入ってました。あと、GNU screen も入ってた!
あとはお好みで。

$ sudo apt update
$ sudo apt upgrade -y

キーボードレイアウトを日本語キーボードに変更。
$ sudo dpkg-reconfigure keyboard-configuration
  ・Generic 105-key PC を選択
  ・keyboard: Japanese を選択
  ・Keyboard Layout: Japanese を選択
  ・AltGr 設定: The default for the keyboard layout を選択
  ・Compose key: No compose key を選択

NTP クライアントとして、Chrony をインストールする。
$ sudo systemctl stop systemd-timesyncd.service
$ sudo systemctl disable systemd-timesyncd.service
$ sudo apt purge systemd-timesyncd
$ sudo apt install chrony

timezone を Asia/Tokyo に変更
$ sudo timedatectl set-timezone Asia/Tokyo

$ sudo apt install -y language-pack-ja

ifconfig は欲しい
$ sudo apt install -y net-tools

dash を bash に切り替える (No を選択)
$ sudo dpkg-reconfigure dash

/lib/systemd/system/systemd-networkd-wait-online.service を編集
$ sudo vi /lib/systemd/system/systemd-networkd-wait-online.service
(下記の行を編集 --any -i eth0 -i wlan0 を追記)
ExecStart=/lib/systemd/systemd-networkd-wait-online --any -i eth0 -i wlan0
  

3. FlightAware

(参考)
https://discussions.flightaware.com/t/flightaware-on-ubuntu-22-04-arm64/82668
https://github.com/abcd567a/ubuntu22/blob/master/README.md

$ sudo wget -O /etc/apt/sources.list.d/abcd567a.list https://abcd567a.github.io/ubuntu22/abcd567a.list
$ sudo wget -O /etc/apt/trusted.gpg.d/abcd567a-key.gpg https://abcd567a.github.io/ubuntu22/KEY2.gpg
$ sudo apt update
$ sudo apt install -y piaware 
$ sudo apt install -y dump1090-fa
$ sudo apt install -y piaware-web
$ sudo piaware-config feeder-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
$ sudo init 6

しばらくしたら、下記リンクで Piaware と FlightAware のアカウントを関連付ける。
同じルータ配下の別 PC からブラウザでアクセスすれば OK。 https://flightaware.com/adsb/piaware/claim
更に、MY ADS-B のリンクから、アンテナ設置場所の緯度、経度、高度を設定すれば OK。

4. Flightradar24

$ sudo apt install -y libssl-dev tcl-dev chrpath

$ sudo dpkg --add-architecture armhf
$ sudo dpkg --print-foreign-architectures
armhf

$ sudo bash -c "$(wget -O - https://repo-feed.flightradar24.com/install_fr24_rpi.sh)"

______  _  _         _      _                    _              _____    ___
|  ___|| |(_)       | |    | |                  | |            / __  \  /   |
| |_   | | _   __ _ | |__  | |_  _ __  __ _   __| |  __ _  _ __`' / /' / /| |
|  _|  | || | / _` || '_ \ | __|| '__|/ _` | / _` | / _` || '__| / /  / /_| |
| |    | || || (_| || | | || |_ | |  | (_| || (_| || (_| || |  ./ /___\___  |
\_|    |_||_| \__, ||_| |_| \__||_|   \__,_| \__,_| \__,_||_|  \_____/    |_/
               __/ |
              |___/
[main][i]FR24 Feeder/Decoder
[main][i]Version: 1.0.44-0/generic
[main][i]Built on Oct 31 2023 11:09:57 (T202310311106/Linux/static_arm64)
[main][i]Running on: ubuntu="22.04"
[main][i]Local IP(s): XXX.XXX.XXX.XXX,XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX,fe80::xxxx:xxxx:xxxx:xxxx
[main][i]Copyright 2012-2023 Flightradar24 AB
[main][i]https://www.flightradar24.com
[main][i]DNS mode: PING

Welcome to the FR24 Decoder/Feeder sign up wizard!

Before you continue please make sure that:

 1 - Your ADS-B receiver is connected to this computer or is accessible over network
 2 - You know your antenna's latitude/longitude up to 4 decimal points and the altitude in feet
 3 - You have a working email address that will be used to contact you
 4 - fr24feed service is stopped. If not, please run: sudo systemctl stop fr24feed

To terminate - press Ctrl+C at any point


Step 1.1 - Enter your email address (username@domain.tld)
$:●Flightradar24 に登録しているメールアドレスを入力

Step 1.2 - If you used to feed FR24 with ADS-B data before, enter your sharing key.
If you don't remember your sharing key, you can find it in your account on the website under "My data sh
aring".
https://www.flightradar24.com/account/data-sharing

Otherwise leave this field empty and continue.
$:●新規登録であれば、メールで送られてきた sharing key を入力。または既存のものを入力

Verifying sharing key...OK



Step 1.3 - Would you like to participate in MLAT calculations? (yes/no)$:yes

IMPORTANT: For MLAT calculations the antenna's location should be entered very precise!

Step 3.A - Enter antenna's latitude (DD.DDDD)
$:●設置場所の緯度を入力

Step 3.B - Enter antenna's longitude (DDD.DDDD)
$:●設置場所の経度を入力

Step 3.C - Enter antenna's altitude above the sea level (in feet)
$:●設置場所の高度を入力

Using latitude: XX.XXXX, longitude: XXX.XXXX, altitude: XXft above sea level

We have detected that you already have a dump1090 instance running. We can therefore automatically configure the FR24 feeder to use existing receiver configuration, or you can manually configure all the parameters.

Would you like to use autoconfig (*yes*/no)$:● yes を入力

Saving settings to /etc/fr24feed.ini...OK
Settings saved, please run "sudo systemctl restart fr24feed" to use new configuration.

Starting the fr24feed service, it may take a while if dump1090 needs to be installed...
Installation and configuration completed!

fr24feed を再起動。

$ sudo systemctl restart fr24feed

5. RadarBox

続いて RadarBox。
RadarBox のアカウントに紐付ける方法は、忘れてしまいました。
通常は、下記を実行するだけなのですが、スクリプト内の lsb_release -c コマンドで、コードネームが bionic となってしまい、
スクリプトが停止してしまいます。
ちょっと修正して、buster と同じ流れにすれば OK。

$ sudo bash -c "$(wget -O - http://apt.rb24.com/inst_rbfeeder.sh)"
Don't know how to install for a distribution named で止まってしまう、、、。

inst_rbfeeder.sh を取得して、スクリプトを修正、実行します。

$ wget http://apt.rb24.com/inst_rbfeeder.sh
$ vi inst_rbfeeder.sh
case 文の bullseye) となっている部分に jammy を追記。
(変更前)
    bullseye)
(変更後)
    bullseye|jammy)

$ sudo sh inst_rbfeeder.sh

mlat-client をソースからビルドしてインストール。
ビルドの前に python3.pm を作成しておきます (ビルドエラーになるため)。

$ sudo vi /usr/share/perl5/Debian/Debhelper/Sequence/python3.pm
(下記を記述)
#! /usr/bin/perl
# debhelper sequence file for dh_python3

use warnings;
use strict;
use Debian::Debhelper::Dh_Lib;

insert_before("dh_installinit", "dh_python3");

1

ここからビルド。

$ sudo apt install -y dh-python python2 python3-dev debhelper
$ wget https://github.com/mutability/mlat-client/archive/refs/tags/v0.2.13.tar.gz
$ tar zxvf v0.2.13.tar.gz
$ cd mlat-client-0.2.13/
$ sudo dpkg-buildpackage -b --no-sign
$ sudo dpkg -i ../mlat-client_0.2.13_arm64.deb
$ sudo ./setup.py install
$ sudo init 6

設定ファイルのメモを残しておきます。

$ cat /etc/rbfeeder.ini
[client]
network_mode=true
log_file=/var/log/rbfeeder.log

key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

sn=XXXXXXXXXXXX

[network]
mode=raw
external_port=30005
external_host=127.0.0.1

[mlat]

/etc/default/mlat-client ファイルを編集 LAT, LON, ALT を設定

6. graphs1090

dump1090-fa の受信状況をグラフで表示。
http://192.168.x.x/graphs1090/ にアクセス。

$ sudo apt install -y librrd8
$ sudo apt --fix-broken install -y
$ wget http://old-releases.ubuntu.com/ubuntu/pool/universe/c/collectd/collectd_5.12.0-11_arm64.deb
$ wget http://old-releases.ubuntu.com/ubuntu/pool/universe/c/collectd/collectd-core_5.12.0-11_arm64.deb
$ sudo dpkg -i collectd_5.12.0-11_arm64.deb collectd-core_5.12.0-11_arm64.deb
$ 
$ sudo bash -c "$(wget -q -O - https://raw.githubusercontent.com/wiedehopf/graphs1090/master/install.sh)"

7. logrotate を設定する

fr24feeder.log, rbfeeder.log, mlat-client.log については、logrotate の設定をしておく。

$ sudo vi /etc/logrotate.d/fr24feed
(下記を記述)
/var/log/fr24feed/fr24feed.log {
  daily
  rotate 7
  copytruncate
}
$ sudo vi /etc/logrotate.d/rbfeeder
(下記を記述)
/var/log/rbfeeder.log {
  daily
  rotate 7
  copytruncate
}

■ 備考

ADS-B feeder を設置すると、下記プランが無料で利用可能になります。
年間、$ 1 = 130 円 換算で、$ 499.99 + ($ 89.95 × 12) + $399.50 = $ 1,978.89 = 257,255 円 お得です♪

ServicePlan$ / month$ / year
Flightradar24Business$ 49.99$ 499.99
FlightAwareEnterprise$ 89.95$ -
RadarBoxBUSINESS$ 39.95$ 399.50

dump1090 の受信状況は下記コマンドで確認できます。

$ nc 127.0.0.1 30003

● Raspberry Pi 4, raspi4, raspi, DVB-T, Ubuntu Server 22.04, ADS-B, Flightradar24, FlightAware RadarBox, dump1090-fa, ddrescue

2022年2月17日木曜日

HTTP サーバ OPTIONS メソッド確認方法 (curl)

curl コマンドで、HTTP サーバの OPTIONS メソッドを確認する方法。

$ curl -X OPTIONS http://localhost/ -i
HTTP/1.1 200 OK
Date: Thu, 17 Feb 2022 08:00:55 GMT
Server: Apache/2.4.41 (Ubuntu)
Allow: GET,POST,OPTIONS,HEAD
Content-Length: 0
Content-Type: text/html

● curl, HTTP, http, OPTIONS, options, メソッド, method, 確認, check

2022年1月29日土曜日

Raspberry Pi 4 の Ubuntu Server バックアップ、リストア (dd, PiShrink)

Raspberry Pi 4 にインストールしている Ubuntu Server をバックアップして、別の microSD カードにリストアする手順。
Ubuntu PC 上で、dd コマンドでバックアップ、PiShrink でイメージの縮小化、dd コマンドでリストア します。

1. バックアップ

まず、Raspberry Pi 4 から microSD カードを抜いて、Ubuntu PC に挿入して、dd コマンドでバックアップ。
自動マウントされる場合は、unmount してから作業。

# dd if=/dev/mmcblk0 of=/home/raspi.img status=progress

2. イメージサイズの縮小化

PiShrink を使用。
https://github.com/Drewsif/PiShrink

# wget wget https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh
# chmod 755 pishrink.sh
# ./pishrink.sh /home/raspi.img
pishrink.sh v0.1.2
pishrink.sh: Gathering data ...
pishrink.sh: Checking filesystem ...
writable: Inode 2809 extent tree (at level 1) could be shorter.  IGNORED.
writable: Inode 28025 extent tree (at level 1) could be shorter.  IGNORED.
writable: Inode 40963 extent tree (at level 1) could be shorter.  IGNORED.
writable: 203145/926640 files (0.2% non-contiguous), 2164496/3823739 blocks
resize2fs 1.45.5 (07-Jan-2020)
pishrink.sh: Shrinking filesystem ...
resize2fs 1.45.5 (07-Jan-2020)
Resizing the filesystem on /dev/loop16 to 2346988 (4k) blocks.
Begin pass 2 (max = 909346)
Relocating blocks             XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 117)
Scanning inode table          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 26342)
Updating inode references     XXXXXXXXXXXXXXXXXXXXXXXX^HXXXXXXXXXXXXXXXX
The filesystem on /dev/loop16 is now 2346988 (4k) blocks long.

pishrink.sh: Shrinking image ...
pishrink.sh: Shrunk raspi.img from 15G to 9.3G ...

3. リストア

microSD カードを入れ替えて、リストア。

# dd if=/home/raspi.img of=/dev/mmcblk0 status=progress

● raspberry pi, ubuntu server, バックアップ, backup, リストア, restore, PiShrink, pishrink.sh, 縮小化, shrink

2022年1月4日火曜日

Ubuntu 20.04 Server で、timezone を日本時間に変更する

Raspberry pi に Ubuntu 20.04 Server をインストールした場合、timezone の設定が UTC になっています。
日本時間に変更する方法。

現在の設定を確認。

$ timedatectl
               Local time: 火 2022-01-04 01:04:39 UTC
           Universal time: 火 2022-01-04 01:04:39 UTC
                 RTC time: n/a
                Time zone: Etc/UTC (UTC, +0000)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

日本時間に変更 (即時反映)。

$ sudo timedatectl  set-timezone Asia/Tokyo

設定の確認。

$ timedatectl
               Local time: 火 2022-01-04 10:05:14 JST
           Universal time: 火 2022-01-04 01:05:14 UTC
                 RTC time: n/a
                Time zone: Asia/Tokyo (JST, +0900)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

● Ubuntu, 20.04, server, timezone, タイムゾーン, 日本, 変更, JST, JST-9, Tokyo, Asia, date, timedatectl

2022年1月3日月曜日

raspberry pi 4 で radiko を録音してローカル RSS でスマホに Podcast として同期する

JUNK 爆笑問題カーボーイ の Podcast 配信サービスが終わったので、代替手段のメモ。
raspberry pi 4 で、radiko (タイムフリー、2022/01/03 現在無償) を録音して、ローカル RSS でスマホに配信するようにしました。

1. radiko を録音するために rec_radiko_ts をインストール

rec_radiko_ts に必要なパッケージをインストール

# apt install curl ffmpeg libxml2

rec_radiko_ts を git clone

$ git clone https://github.com/uru2/rec_radiko_ts
$ cd rec_radiko_ts
$ sudo cp rec_radiko_ts.sh /usr/local/bin/
$ sudo chmod 755 /usr/local/bin/rec_radiko_ts.sh

2. rec_radiko_ts.sh の動作確認

2021/12/29 01:00-03:00 の放送をタイムフリーで録音する場合の例。
radiko プレミアムに入っている場合は、-m "mail address" -p "password" オプションを追加すると良い。
-s オプションで放送局 ID を指定。うちは福岡なので、RKB です。
放送局 ID は、下記サイトを参照。
https://www.norikistudio.com/station-id-list

$ /usr/local/bin/rec_radiko_ts.sh -s RKB -f 202112290100 -d 120 -o 20211229-JUNK_bakusho.m4a

3. HTTP サーバは、lighttpd をインストール

HTTP サーバは何でもいいんですが、とりあえず、lighttpd を選択。

# apt install lighttpd

4. RSS の設定

RSS は、下記サイトから、makepodcast.rb を使わせてもらいました。
指定ディレクトリ内のmp3ファイルから必要最低限のPodcast用RSSを生成する
lighttpd の document root である /var/www/html/radiko/ に保存。
あと、ruby をインストール。

# apt install ruby

5. 自動ダウンロード設定、RSS フィード更新 (cron)

JUNK 爆笑問題カーボーイ は、毎週火曜日 25:00-27:00 (水曜日 1:00-3:00) の放送なので、
毎週水曜日の 4:00 に録音。5:00 に RSS フィードを更新するように cron を設定。
ちなみに、raspberry pi 4 の IP は、192.168.10.100 固定になってます。
将来的には、古いファイルを自動で消すようにするかな。

# crontab -e
(下記を追加)
00 04 * * 3 /usr/local/bin/rec_radiko_ts.sh -s RKB -f "`date +\%Y\%m\%d`0100" -d 120 -o "/var/www/html/radiko/`date +\%Y\%m\%d`-JUNK_bakusho.m4a"
30 05 * * 3 (cd /var/www/html/radiko/ ; ./makepodcast.rb JUNK_bakusho http://192.168.10.100/radiko/ ./ >| ./JUNK_bakusho.rss)

6. スマホの Podcast アプリに RSS を登録する。

スマホの Podcast アプリに RSS を登録すれば、あとは自動で同期できます (アプリの方は適当に設定してください)。

http://192.168.10.100/radiko/JUNK_bakusho.rss

■ 注意

録音したデータをインターネットで配信とかしたら著作権法違反になるので、個人利用の範囲で楽しみましょう。

● raspberry pi 4, radiko, 録音, タイムフリー, RSS, Podcast, ポッドキャスト, ローカル

2021年12月20日月曜日

Ubuntu コマンドで ISO ファイルを DVD に書き込む

growisofs コマンドを使う。
= (イコール) を忘れないように注意。

$ sudo apt install growisofs

$ growisofs -dvd-compat -Z /dev/dvd=./ubuntu-ja-20.04.1-desktop-amd64.iso

● growisofs, linux, command, iso, file, dvd, DVD, ISO, コマンド

2021年12月15日水曜日

SVN チェックアウト時の mtime をコミットされた時刻にする

SVN でリポジトリをチェックアウトしたとき、mtime は、チェックアウトした時刻になります。
コミットした時刻にする方法。

$ vi ~/.subversion/config
(miscellany セクションに use-commit-times = yes を記述。コメントアウトでいける場合もあり)
[miscellany]
use-commit-times = yes

● SVN, チェックアウト, checkout, コミット, commit, mtime, 更新時刻, 時刻, タイムスタンプ, timestamp

2021年12月11日土曜日

tcpdump オプションメモ

よく忘れるので、メモしておく。

# tcpdump -s0 -n -nn -tttt -i eth0

● tcpdump, オプション, option

2021年9月9日木曜日

ディレクトリ以下の zip ファイルをすべて解凍する

必要があったので、メモ。

$ find . -name "*.zip" | while read filename; do unzip -o -d "`basename -s .zip "$filename"`" "$filename"; done;

● zip, 解凍, unzip, ディレクトリ, directory, 全て

2021年7月14日水曜日

rpm ファイルの中身を展開する

rpm2cpio がインストールされていない場合は、インストールする。

# apt install rpm2cpio

展開。

$ rpm2cpio hogehoge.rpm | cpio -id

● rpm, 中身, 展開, rpm2cpio