Daily Archives: 08/22/2020

Raspberry Pi – 继续折腾FlightAirMap

PiAware最大的问题是没办法记录曾经检测过的飞机,于是我又开始折腾起了功能更强大的FlightAirMap

安装过程

Install git, mariadb, apache and PHP with needed modules:

sudo apt-get install git mariadb-server apache2 php5 php5-curl php5-mysql php5-gd php-pclzip

Or this on Stretch:

sudo apt-get install git mariadb-server apache2 php7.0-common php7.0-cgi php7.0-mysql php7.0-curl php7.0 php7.0-xml php7.0-zip php7.0-gd php7.0-json

Get FlightAirMap from git:

cd /var/www
sudo git clone --recursive --depth=1 http://github.com/ysurac/flightairmap

Edit Apache conf /etc/apache2/site-available/000-default.conf, add this in VirtualHost section:

<VirtualHost *:8088>
        ServerName 192.168.68.128/flightairmap
        DocumentRoot "/var/www/flightairmap"
        <Directory /var/www/flightairmap>
                Options Indexes FollowSymLinks
                AllowOverride All
                Require all granted
        </Directory>
</VirtualHost>

Enable mod rewrite:

sudo a2enmod rewrite

Restart apache2:

sudo service apache2 restart

Fix permissions:

cd /var/www/flightairmap
sudo chmod 666 require/settings.php
sudo chmod 777 install/tmp
sudo chmod 777 data

Create database and user, may skip if already created:

mysql -u root -p
update mysql.user set password=password('YOUR_DB_PASSWORD') where user='root';

Then:

CREATE DATABASE `flightairmap`;
GRANT ALL ON `flightairmap`.* TO 'youruser'@'localhost' IDENTIFIED BY 'yourpass';
FLUSH PRIVILEGES;

Now use your browser to go to http://127.0.0.1/install/ (or ip of your server) Run scripts/update_db.php in a shell.

cd /var/www/flightairmap/
php scripts/update_db.php

Add FlightAirMap service:

sudo cp /var/www/flightairmap/install/init/flightairmap.service.systemd /etc/systemd/system/flightairmap.service

Alter paths to match your path, may skip i no change to the installation folder:

sudo nano /etc/systemd/system/flightairmap.service
sudo chmod 644 /etc/systemd/system/flightairmap.service

Then you can run flightairmap daemon:

sudo systemctl enable flightairmap.service

Add update_db.php in /etc/crontab:

sudo 5 * * * * root php /var/www/flightairmap/scripts/update_db.php >/dev/null 2>&1

运行效果:

折腾Raspberry Pi:安装PiAware

PiAware是什么鬼?

官方解释:

您的地面站可以运行 FlightAware 的 PiAware 软件,用于跟踪在 100-300 miles (视线内,取决于天线的安装范围) 内的飞行,并自动将数据传送给 FlightAware。 您可以直接从您的 PiAware 设备或通过 FlightAware.com 跟踪航班。为了表达FlightAware的谢意,发送ADS-B数据的用户将享受以下优待:

  • flightaware.com上的实时数据(存在最多两分钟的标准数据处理延迟)
  • 访问本地设备最近一秒接收的最新实时数据(可通过本地网络连接在统计信息页面访问)
  • 来自本地设备的数据在FlightAware航迹上突出显示
  • 站点性能详细统计
  • 一个免费Enterprise Account (价值每月89.95美刀)

安装过程:

硬件:

将amazon购买的ADS-B接收器连上天线,并插入RasPi的USB口。

软件:

wget https://flightaware.com/adsb/piaware/files/packages/pool/piaware/p/piaware-support/piaware-repository_3.8.1_all.deb
sudo dpkg -i piaware-repository_3.8.1_all.deb

sudo apt-get update
sudo apt-get install piaware

sudo piaware-config allow-auto-updates yes
sudo piaware-config allow-manual-updates yes

sudo apt-get install dump1090-fa

sudo reboot

安装完毕后,登录flighwaware网站激活刚安装完毕的客户端

https://flightaware.com/adsb/piaware/claim

激活以后,就能在本地局域网看到本地地图以及正在追踪的飞机了。

还有一个问题,由于我这个RasPi,之前已经安装了Apache运行wordpress和piwigo相册,而PiAware默认使用的是lighttpd服务器,两者(Apache和lighttpd)同时运行,会造成端口监听冲突,同时也会加重主机的负荷,所以我又多做了几个步骤,把dump1090-fa的服务迁移到了Apache上。

具体步骤很简答,只需要改动两个文件:

第一个是在/etc/apache2/ports.conf中加入对8080端口的监听 :

Listen 8080

其次,将8080端口的服务加入到/etc/apache2/sites-available/000-default.conf:

<VirtualHost *:8080>
        ServerAdmin webmaster@localhost
       DocumentRoot /usr/share/dump1090-fa/html/
       Alias  "/dump1090-fa/data/" "/run/dump1090-fa/"
       Alias  "/data/" "/run/dump1090-fa/"
       Alias  "/dump1090-fa/" "/usr/share/dump1090-fa/html/"
       Alias  "^/dump1090-fa$" "/dump1090-fa/"
        #SetEnvIf Request_URI "/dump1090-fa/data/.*\.json$" Header set "Access-Control-Allow-Origin" "*"
        <Directory "/usr/share/dump1090-fa/html/">
        Require all granted
        Options All
        AllowOverride All
        SetEnvIf Request_URI "/dump1090-fa/data/.*\.json$" Header set "Access-Control-Allow-Origin" "*"
        </Directory>
        <Directory "/run/dump1090-fa/">
        Require all granted
        Options All
        AllowOverride All
        SetEnvIf Request_URI "/dump1090-fa/data/.*\.json$" Header set "Access-Control-Allow-Origin" "*"
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>


重启Apache服务

sudo service apache2 restart

禁用lighttpd

sudo systemctl disable lighttpd

sudo update-rc.d -f lighttpd remove

将Apache服务设为自动启动

sudo systemctl enable --now apache2

实际运行效果:

下一步:

Amazon买的ADS-B自带的天线信号有点弱,只能接收到周围25NM左右的范围,接下来可能另外买一个信号强一点的天线,同时需要调整一下摆放位置。

参考资料:

https://flightaware.com/adsb/piaware/install
https://discussions.flightaware.com/t/migrate-dump1090-fa-to-apache/34053/11