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