カテゴリー
お知らせ

備忘録 Flightradar on RaspberryPI

 これは自分のためのメモです。
 この備忘録を見られて真似されても結構ですが、動作の保証は出来かねます。
 また、真似られたことで不測の不具合が発生しましても、私は一切の責任を負いません。


OSインストール

※1行づつ作業した方が良い
sudo apt update
sudo apt -y full-upgrade
sudo apt dist-upgrade -y
sudo rpi-update
sudo apt autoremove -y
sudo apt autoclean
sudo reboot

UARTシリアルコンソール

shutdonボタン

pi@raspberrypi:~ $ cat /boot/config.txt
#
#
[all]
enable_uart=1
dtoverlay=gpio-shutdown,gpio_pin=6,debounce=1000

SSD1306ディスプレイ

DHT22温度計

[I2Cを使用できるようにconfigを変更する]
$ sudo raspi-config nonint do_i2c 0

[OSにi2c関連toolをインストールする]
$ sudo apt-get install i2c-tools
$ i2cdetect -y 1

[python3用のSSD1306ライブラリーをpip3でインストール]
sudo apt-get install pip
sudo pip3 install adafruit-circuitpython-ssd1306

[gitからDHT温度センサーのライブラリーをダウンロードする]
sudo apt-get install git
sudo git clone https://github.com/adafruit/Adafruit_Python_DHT.git

[ライブラリーのドライバーをインストールする]
cd Adafruit_Python_DHT
sudo python setup.py install

[その他のライブラリーをインストール]
sudo pip3 install ipget

[RuntimeError: No access to /dev/memの対処]
sudo chown root.gpio /dev/gpiomem
sudo chmod g+rw /dev/gpiomem

pi@raspberrypi:~ $ cat SSD1306output.py

import board
import digitalio
from PIL import Image, ImageDraw, ImageFont
import adafruit_ssd1306
from time import sleep
import ipget
import Adafruit_DHT as DHT
SENSOR_TYPE = DHT.DHT22
DHT_GPIO = 26

DEVICE_ADR = 0x3C
DISP_WIDTH = 128
DISP_HEIGHT = 64

tempfile='/sys/class/thermal/thermal_zone0/temp'
loadfile='/proc/loadavg'


def getTemp():
    with open(tempfile, 'r') as f:
        rdata = f.readline()
        t = float(rdata)/ 1000.0
    return t

def getCpuload():
    with open(loadfile, 'r') as la:
        rdata = la.readline()
    return rdata



RESET_PIN = digitalio.DigitalInOut(board.D4)
i2c = board.I2C()
oled = adafruit_ssd1306.SSD1306_I2C(DISP_WIDTH, DISP_HEIGHT, i2c, addr=DEVICE_ADR, reset=RESET_PIN)
# Clear display.
oled.fill(0)
oled.show()


# Load a font in 2 different sizes.
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 28)
font2 = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 14)
font3 = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 12)

def main():
    image = Image.new("1", (oled.width, oled.height))
    draw = ImageDraw.Draw(image)

    target_ip = ipget.ipget()
#    print(target_ip.ipaddr("wlan0"))
    wlan_ip = target_ip.ipaddr("wlan0")

    la = getCpuload()
    la_list = la.split()
    cpuload = 'loadave=' + la_list[0] + ' ' + la_list[1]
    #cpuload = 'loadave=' + la_list[0] + ' ' + la_list[1] + ' ' + la_list[2]

    t = getTemp()
    cputemp = 'cputemp = %.2f c' % (t)

    h,t = DHT.read_retry(SENSOR_TYPE, DHT_GPIO)
    Temp = "{0:0.1f}c" .format(t)
    #Temp = "Temp = {0:0.1f} deg C" .format(t)
    Humidity = "{0:0.1f}%" .format(h)
    #Humidity = "Humidity = {0:0.1f} %" .format(h)
    message = "DHT22=" + Temp + " " + Humidity
    #message = Temp + "\n" + Humidity

    draw.text((0, 0), wlan_ip, font=font3, fill=255)
    draw.text((0, 15), cputemp, font=font3, fill=255)
    draw.text((0, 30), cpuload, font=font3, fill=255)
    draw.text((0, 45), message, font=font3, fill=255)

    # Display image
    oled.image(image)
    oled.show()

    sleep(30)

    return


sleep(2)
h,t = DHT.read_retry(SENSOR_TYPE, DHT_GPIO)
sleep(2)
if __name__ == "__main__":
    while True:
        main()



pi@raspberrypi:~ $ cat displayoutput.py
from time import sleep
import ipget
import Adafruit_DHT as DHT
SENSOR_TYPE = DHT.DHT22
DHT_GPIO = 26


tempfile='/sys/class/thermal/thermal_zone0/temp'
loadfile='/proc/loadavg'


def getTemp():
    with open(tempfile, 'r') as f:
        rdata = f.readline()
        t = float(rdata)/ 1000.0
    return t

def getCpuload():
    with open(loadfile, 'r') as la:
        rdata = la.readline()
    return rdata


def main():

    target_ip = ipget.ipget()
    wlan_ip = target_ip.ipaddr("wlan0")

    la = getCpuload()
    la_list = la.split()
    cpuload = 'loadave=' + la_list[0] + ' ' + la_list[1]

    t = getTemp()
    cputemp = 'cputemp = %.2f c' % (t)

    h,t = DHT.read_retry(SENSOR_TYPE, DHT_GPIO)
    Temp = "{0:0.1f}c" .format(t)
    Humidity = "{0:0.1f}%" .format(h)
    message = "DHT22=" + Temp + " " + Humidity


    print (wlan_ip)
    print (cputemp)
    print (cpuload)
    print (message)
    print ("\r")

    sleep(10)

    return


sleep(2)
h,t = DHT.read_retry(SENSOR_TYPE, DHT_GPIO)
sleep(2)
if __name__ == "__main__":
    while True:
        main()

[cronで自動起動させる]
pi@raspberrypi:~ $ crontab -e
@reboot sleep 30 ; cd /home/pi ; /usr/bin/sudo /usr/bin/python3 SSD1306output.py



FlightAware

本家サイトに従ってインストールする

[piAwareのインストール]
pi@raspberrypi:~ $ wget https://ja.flightaware.com/adsb/piaware/files/packages/pool/piaware/f/flightaware-apt-repository/flightaware-apt-repository_1.1_all.deb
pi@raspberrypi:~ $ sudo dpkg -i flightaware-apt-repository_1.1_all.deb

pi@raspberrypi:~ $ sudo apt-get update
pi@raspberrypi:~ $ sudo apt-get install piaware

pi@raspberrypi:~ $ sudo piaware-config allow-auto-updates yes
pi@raspberrypi:~ $ sudo piaware-config allow-manual-updates yes

pi@raspberrypi:~ $ sudo apt-get install dump1090-fa

pi@raspberrypi:~ $ sudo reboot



[feederIDを調べる]
pi@raspberrypi:~ $ sudo piaware-status
PiAware master process (piaware) is running with pid 668.
PiAware ADS-B client (faup1090) is running with pid 701.
PiAware ADS-B UAT client (faup978) is not running (disabled by configuration settings)
PiAware mlat client (fa-mlat-client) is not running.
Local ADS-B receiver (dump1090-fa) is running with pid 403.

dump1090-fa (pid 403) is listening for ES connections on port 30005.
faup1090 is connected to the ADS-B receiver.
piaware is connected to FlightAware.

dump1090 is producing data on localhost:30005.

Your feeder ID is nnnnn-nnnn-nnnn-nnnn-nnnn (from /var/cache/piaware/feeder_id)

[パソコンのブラウザから紐付ける]
https://flightaware.com/adsb/piaware/claim/nnnnn-nnnn-nnnn-nnnn-nnnn

flightradar24

pi@raspberrypi:~ $ sudo bash -c "$(wget -O - https://repo-feed.flightradar24.com/install_fr24_rpi.sh)"
--2023-11-01 21:33:23--  https://repo-feed.flightradar24.com/install_fr24_rpi.sh
Resolving repo-feed.flightradar24.com (repo-feed.flightradar24.com)... nnnn:nnnn::nnnn:3nnnn, nnnn:nnnn::nnnn:nnnn, nnnn:nnnn::nnnn:nnnn, ...
Connecting to repo-feed.flightradar24.com (repo-feed.flightradar24.com)|nnnn:nnnn::nnnn:nnnn|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1349 (1.3K) [application/x-sh]
Saving to: ‘STDOUT’

-                   100%[===================>]   1.32K  --.-KB/s    in 0.001s

2023-11-01 21:33:25 (1.85 MB/s) - written to stdout [1349/1349]

Hit:2 http://archive.raspberrypi.org/debian bullseye InRelease
Hit:1 http://www.flightaware.com/adsb/piaware/files/packages bullseye InRelease
Get:3 http://raspbian.raspberrypi.org/raspbian bullseye InRelease [15.0 kB]
Get:4 http://raspbian.raspberrypi.org/raspbian bullseye/main armhf Packages [13.2 MB]
Fetched 13.2 MB in 1min 2s (212 kB/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
dirmngr is already the newest version (2.2.27-2+deb11u2).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
Executing: /tmp/apt-key-gpghome.TvNy1AKa4F/gpg.1.sh --recv-key --keyserver keyserver.ubuntu.com nnnn
gpg: key nnnn: public key "Flightradar24 <support@fr24.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1
Get:2 http://repo.feed.flightradar24.com flightradar24 InRelease [17.0 kB]
Hit:3 http://archive.raspberrypi.org/debian bullseye InRelease
Hit:1 http://www.flightaware.com/adsb/piaware/files/packages bullseye InRelease
Hit:4 http://raspbian.raspberrypi.org/raspbian bullseye InRelease
Get:5 http://repo.feed.flightradar24.com flightradar24/raspberrypi-stable armhf Packages [482 B]
Fetched 17.5 kB in 10s (1,672 B/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  fr24feed
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 3,785 kB of archives.
After this operation, 5,120 kB of additional disk space will be used.
Get:1 http://repo.feed.flightradar24.com flightradar24/raspberrypi-stable armhf fr24feed armhf 1.0.41-0 [3,785 kB]
Fetched 3,785 kB in 5s (766 kB/s)
Selecting previously unselected package fr24feed.
(Reading database ... 50183 files and directories currently installed.)
Preparing to unpack .../fr24feed_1.0.41-0_armhf.deb ...
Unpacking fr24feed (1.0.41-0) ...
Setting up fr24feed (1.0.41-0) ...
You don't seem to have any dump1090 installed. On the fr24feed start it will automatically install dump1090-mutability.
Created symlink /etc/systemd/system/multi-user.target.wants/fr24feed.service → /etc/systemd/system/fr24feed.service.
error | Local time: 2023-11-01 21:37:29 +0900
error | GMT+0 time: 2023-11-01 12:37:29 +0900
______  _  _         _      _                    _              _____    ___
|  ___|| |(_)       | |    | |                  | |            / __  \  /   |
| |_   | | _   __ _ | |__  | |_  _ __  __ _   __| |  __ _  _ __`' / /' / /| |
|  _|  | || | / _` || '_ \ | __|| '__|/ _` | / _` | / _` || '__| / /  / /_| |
| |    | || || (_| || | | || |_ | |  | (_| || (_| || (_| || |  ./ /___\___  |
\_|    |_||_| \__, ||_| |_| \__||_|   \__,_| \__,_| \__,_||_|  \_____/    |_/
               __/ |
              |___/
error | Your machine should be set as GMT+0 time zone!
warning | Time zone is not set to GMT+0
[main][i]FR24 Feeder/Decoder
[main][i]Version: 1.0.41-0/generic
[main][i]Built on Oct  9 2023 12:17:06 (T202310091212/Linux/static_armel)
[main][i]Running on: raspbian="11"
[main][i]Local IP(s): 192.168.11.7,nnnn
[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)
$:nnnn@gmail.com

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 sharing".
https://www.flightradar24.com/account/data-sharing

Otherwise leave this field empty and continue.
$:[エンター]

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)
$:dd.dddd

Step 3.B - Enter antenna's longitude (DDD.DDDD)
$:ddd.dddd

Step 3.C - Enter antenna's altitude above the sea level (in feet)
$:700

Using latitude: 34.6596, longitude: 136.1306, altitude: 700ft above sea level

Validating email/location information...OK

The closest airport found is ICAO:RJOO IATA:ITM near Osaka.

Latitude: dd.dddd
Longitude: ddd.dddd
Country: Japan

Flightradar24 may, if needed, use your email address to contact you regarding your data feed.

Would you like to continue using these settings?

Enter your choice (yes/no)$:yes

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

Submitting form data...OK

Congratulations! You are now registered and ready to share ADS-B data with Flightradar24.
+ Your sharing key (nnnnnnn) has been configured and emailed to you for backup purposes.
+ Your radar id is nnnn, please include it in all email communication with us.
+ Please make sure to start sharing data within one month from now as otherwise your ID/KEY will be deleted.

Thank you for supporting Flightradar24! We hope that you will enjoy our Premium services that will be available to you when you become an active feeder.

To start sending data now please execute:
sudo systemctl start fr24feed

Saving settings to /etc/fr24feed.ini...OK
Installation and configuration completed!
pi@raspberrypi:~ $ sudo systemctl start fr24feed
pi@raspberrypi:~ $

ROM化

[ROM化を有効にする]
sudo raspi-config nonint enable_overlayfs
sudo raspi-config nonint enable_bootro
sudo reboot

[ROM化を無効にする]
sudo raspi-config nonint disable_overlayfs
sudo reboot
sudo raspi-config nonint disable_bootro
sudo reboot

不要なサービス停止

$ sudo systemctl stop alsa-restore.service
$ sudo systemctl stop bluetooth.service
$ sudo systemctl stop bthelper@hci0.service
$ sudo systemctl stop ModemManager.service
$ sudo systemctl stop triggerhappy.service
Warning: Stopping triggerhappy.service, but it can still be activated by:
  triggerhappy.socket
$ sudo systemctl stop triggerhappy.socket


$ sudo systemctl disable alsa-restore.service
$ sudo systemctl disable bluetooth.service
$ sudo systemctl disable bthelper@hci0.service
$ sudo systemctl disable ModemManager.service
$ sudo systemctl disable triggerhappy.service

負荷の観測

while true
do
  uptime
  sleep 300
done


while true; do   uptime ; cat /sys/class/thermal/thermal_zone0/temp;    sleep 300; done

googleスプレッドシートへのデータアップ

pi@raspberrypi:~ $ cat sendgoogle.py
from time import sleep
import ipget
import Adafruit_DHT as DHT
import requests
SENSOR_TYPE = DHT.DHT22
DHT_GPIO = 26


tempfile='/sys/class/thermal/thermal_zone0/temp'
loadfile='/proc/loadavg'


def getTemp():
    with open(tempfile, 'r') as f:
        rdata = f.readline()
        t = float(rdata)/ 1000.0
    return t

def getCpuload():
    with open(loadfile, 'r') as la:
        rdata = la.readline()
    return rdata


def main():

    target_ip = ipget.ipget()
    wlan_ip = target_ip.ipaddr("wlan0")

    la = getCpuload()
    la_list = la.split()
    cpuload = 'loadave=' + la_list[0] + ' ' + la_list[1]

    t = getTemp()
    cputemp = 'cputemp = %.2f c' % (t)
    cputemp_str = '%.2f' % (t)

    h,t = DHT.read_retry(SENSOR_TYPE, DHT_GPIO)
    Temp = "{0:0.1f}c" .format(t)
    outtemp = "{0:0.1f}" .format(t)
    Humidity = "{0:0.1f}%" .format(h)
    outhumi = "{0:0.1f}" .format(h)
#    message = "DHT22=" + Temp + " " + Humidity


    ipaddr = wlan_ip.strip("/24")
    print (ipaddr)
    print (cputemp)
    print (cpuload)
#    print (message)
    print ("\r")

    url = 'https://script.google.com/macros/s/nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn/exec?data1=' + ipaddr + '&data2=' + cputemp_str + '&data3=' + la_list[0] + '&data4=' + outtemp + '&data5=' + outhumi
    requests.get(url)
#    sleep(600)

    return


sleep(2)
h,t = DHT.read_retry(SENSOR_TYPE, DHT_GPIO)

if __name__ == "__main__":
#    while True:
    main()

[crontab編集]
*/10 * * * * cd /home/pi ; /usr/bin/sudo /usr/bin/python3 sendgoogle.py

参考文献

b.urpn.net/2020/05/31/625

bitstar.jp/blog/2021/06/02/34570/

www.momobro.com/rasbro/tips-rp-raspberry-pi-stop-service/

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です