Tag: Command Line

  • Using the Raspberry Pi to Feed to FlightRadar24, FlightAware, and ADS-B Exchange

    Using the Raspberry Pi to Feed to FlightRadar24, FlightAware, and ADS-B Exchange

    In this post, I will be showing you how to start feeding flight data to three services: Flightradar24, ADS-B Exchange, and FlightAware. This post may be helpful to some of you who want to run your own flight feeder, and can’t tell which is a better service to feed to.

    The main benefit of running your own Raspberry Pi flight tracker is that you will get paid accounts for free. For example, you will get a free FlightAware enterprise account, a subscription valued at around $89.95 a month. FlightRadar24 will also give you a free business plan, which costs $49.99 a month. If you also want to support non-proprietary websites, you can also give flight data to ADS-B Exchange.

    What you will need (hardware)

    Below are the parts you will need:

    Raspberry Pi 3B (x1, required)

    The Raspberry Pi will be our microcontroller (This also works with other models, just not the Zero or the Pico; you can see FlightAware’s compatibility list here)

    ADS-B Dongle (x1, required)

    This will pick up ADS-B signals from nearby aircraft.

    MicroSD Card (at least 8GB, x1, required)

    The Raspberry Pi will be our microcontroller.

    Flashing our PiAware image

    To begin the installation, we will have to first start feeding to FlightAware. To begin, first, create an account at their website, or log in at their website.

    Now download the PiAware image (direct download for 7.2), and download Etcher. Then flash Etcher to your device using the PiAware ISO.

    Note that you must select the correct drive, as this will erase your drive.

    Configuring the ISO

    If you want to enable SSH on your PiAware, or you have a wireless network configuration that you want to set (this will be typically everyone, unless you are using an ethernet cable on your Raspberry Pi), you must follow the below steps to configure the new operating system to use your configurations. You can refer to the configurations at FlightAware’s Website, or you could not set a default configuration, and once the PiAware has booted up, configure it using Bluetooth.

    Booting it up

    Now, you can put it all together! Connect your ADS-B antenna to your Raspberry Pi via USB, and then put the SD card through the back. Then, plug in the HDMI cable (and ethernet if you are going to be using it), and power it on.

    Now, once the Raspberry Pi has booted up, you should see a screen showing the PiAware Status. If you did this correctly, it should be connected. You will also need to connect a keyboard if you do not know your PiAware’s IP address. If it asks you for credentials, the default is pi for username, and raspberry for password.

    Setting up the FlightAware feeder

    Now we get to the fun part! Now, we set up the feeders. Let’s start off with the FlightAware feeder. Since we flashed the custom ISO file, FlightAware is going to be installed, just not set linked to an account. Create a basic plan FlightAware account at their website if you don’t already have one, and claim your PiAware. Once that is set up, make sure you are connected to the same network as your PiAware. It will come in handy for later. Once you do that, make sure you are still on the status page on your PiAware, click Alt+F2 (or whatever key it says to press to open the terminal and run commands). If it asks you for credentials, the default is pi for username, and raspberry for the password (unless it is set otherwise, of course). Now run the following command:

    BASH
    
    hostname -I

    This should return your Pi’s IP address. Now, on another device, navigate to your IP address on the SkyAware page. For example, if my Pi’s IP address is 192.168.1.1, I will navigate to the following website:

    URL
    
    http://192.168.1.1/skyaware

    After that, you should see a map with all the aircraft you are tracking. You have successfully set up FlightAware! After some time, your basic account will be upgraded, and you can view your ADS-B statistics.

    Setting up FlightRadar24

    Now, open the terminal and run the following command:

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

    You will then be asked some questions about antenna position, fr24 sharing key, and other things.

    Now, we need to configure FlightRadar24. To begin, sign up for an account at their official website. Note that all you need to do is sign up for a free account and do not select any paid plans. This is because your account will automatically be upgraded at the end of this tutorial.

    Run the following command to enter configuration:

    BASH
    
    sudo fr24feed --signup

    You will be asked questions about you and the antenna that you are using. Answer the questions similar to the ones below:

    • Email Address: Enter the same email address you used to sign up for FlightRadar24. This is the same email address that your sharing key will be sent to, and the same email address that your account on will be upgraded.
    • FR24 Sharing key: If you have never set up a feeder or have never got a sharing key from FlightRadar24, leave this blank. If not, enter your FlightRadar24 sharing key.
    • Participating in MLAT Calculations: Answer yes, unless you know you don’t want it or need it.
    • Autoconfiguration for dump1090 (if asked): Yes
    • Latitude & Longitude: Use a website like latlong.net to find your latitude and longitude. It is best to be as accurate as possible. Enter this question in the form of XX.XXXX and XX.XXXX (leave out any extra numbers).
    • Altitude: This is your altitude from sea level. You can use whatismyelevation.com to find your altitude.
    • Receiver Selection: If you are using a DVB-T (the type I put in the parts list) stick then I strongly recommend option 1. If you encounter an error regarding dump1090 in this tutorial, restart the tutorial and click option 4. If you do not have a DVB-T stick, check out your other options.
    • Dump1090 Arguments (if asked): Leave this blank and hit enter.
    • Raw Data Feed: No, unless you know what you are doing.
    • Basestation Data feed: No unless you know what you are doing.
    • Logfile Mode: 48-hour, 24 rotation.
    • Logfile Path: This will be the path that the log file is saved to. If you want to use a custom path for logs, put it here. If not, stick with the default and hit enter.

    FlightRadar24’s configuration should return that everything is correctly set up. The program should also give you a sharing key. Save this key as you may need it later in the future.

    To begin feeding ADS-B data to FlightRadar24, enter the command below. Note that MLAT or general feeding might take some time to show up. For me, it took 30 minutes before the feeder was actively sending data to FlightRadar24:

    BASH
    
    sudo systemctl restart fr24feed

    You can go to the data page and view your feeder statistics. If you want to access the web UI for FlightRadar24, then go to your Raspberry Pi’s IP address (remember, you can access it with sudo hostname -I), and access it via a web browser on port 8754, unless set otherwise. For example, my Raspberry Pi’s IP address is 192.168.1.252, so I access it by using http://192.168.1.252:8754.

    Also, it is important to note that it may take some time for the receiver to start working and sending data. For me, it took 30 minutes before flight data was sent to the services I was feeding to.

    Setting up MLAT for FlightAware

    If you want to set up MLAT configurations on FlightAware (we highly recommend doing so, it can increase the amount of positions seen), then follow our steps.

    First, go to your FlightAware data sharing page and clcik the gear icon next to the nearest airport, labeled in orange.

    Then, enable MLAT and Mode S Alliteration. Put in the same details as you did for FlightRadar24, or new details if you have to.

    Setting up ADS-B Exchange

    First, we need to download ADS-B Exchange. You can do that with the following command:

    BASH
    
    sudo bash -c "$(wget -nv -O - https://raw.githubusercontent.com/adsbxchange/adsb-exchange/master/install.sh)"
    

    You will be asked a couple questions. For the first one, type in a random username, but note that this username will be public. Next, enter the details it asks for, and it will begin configuring. Note that this may take a while.

    Next, run the following command:

    BASH
    
    sudo bash /usr/local/share/adsbexchange/git/install-or-update-interface.sh

    The script should output a sharing key. You can use this to view your feeder statistics at the official website of ADS-B Exchange. You should also be able to access your web interface on the adsbx page. This will be your Raspberry Pi’s IP address, with /adsbx at the end. For me, the URL was http://192.168.1.252/adsbx.

    Aftermath

    PiAware status (FlightAware)
    SkyAware Map (FlightAware)
    Data sharing Page (FlightAware)
    Flight map (tar1090) (ADS-B Exchange)
    Status Page (FlightRadar24)
    Data sharing page (FlightRadar24)
  • How to make permanent bash aliases and bash functions

    In the last post, I covered how to make bash aliases. However, creating bash aliases with the alias command only lets you create bash aliases for the current session. For example, if I were to use alias hi="echo hi" to make a bash alias that connects hi with the command echo hi, and then exited the terminal session, all the bash aliases would reset. However, there is a way to make them permanent.

    Creating Permanent Bash aliases

    To make Bash aliases permanent, you will need to add lines to the ~/.bash_profile or ~/.bashrc file. Once you find out that file, open it with the text editor of your choice. I prefer nano.

    Make sure to run the below command after you are done modifying those files:

    BASH SHELL
    source ~/.bash_profile

    The below commands are how you get into the file.

    BASH SHELL
    cd ~
    nano .bashrc

    Then add your aliases.

    BASH CONFIGURATION
    # Aliases
    # alias alias_name="command_to_run"
    
    
    # If you are new to the shell, note that the Linux system ignores lines that start with '#' so this line does not mean anything to Linux
    
    # Long format list
    alias ll="ls -la"
    
    # Print my public IP
    alias myip="curl ipinfo.io/ip"
    
    # That 'hi' example from earlier
    alias hi="echo hi"

    Now when you reboot your Linux system, the Bash aliases should still work.

    Bash aliases with command arguments (Bash functions)

    Sometimes you may need to create a Bash alias that will change depending on certain values or will accept arguments. The syntax for Bash functions is relatively easy. They can be declared in two separate formats. It is preferred to declare functions using the ~/.bashrc file.

    TIP: If you want your .bashrc file to be more modular, you can store your aliases in a separate folder. Some distributions of Linux like Ubuntu or Debian include a separate .bash_aliases file.

    The syntax is below. Way 1 is the preferred way and the most used one.

    Way 1 (Multi-Line):

    BASH CONFIGURATION
    function_name () {
      commandsToRun
    }

    Way 1 (Single-Line):

    BASH CONFIGURATION
    function_name () { commandsToRun; }

    Way 2 uses the keyword of function, and then the function name, and after that the commands to run. The code below demonstrates way 2 (multi-line):

    BASH CONFIGURATION
    function function_name {
      commandsToRun
    }
    

    Way 2 (Single-Line):

    BASH CONFIGURATION
    function function_name { commandsToRun; }

    A few things that are nice to know:

    • The commands that the function will run are between the curly braces ({}). This is called the body of the function. The curly braces must be separated from the body by newlines or spaces. In this case, function A {commandsToRun;} or A () {commandsToRun;} will not work, but something like function A { commandsToRun; } or A () { commandsToRun; } which has spaces separating the body of the function from the function data will.
    • Simply defining a function will not execute it. If you want to invoke or execute a bash function simply use the name of the function. The body of the function is executed when you invoke it in the shell script.
    • You must define the function before calling or executing it.

    You can pass any number of arguments in a function. If you want to call a Bash function right after the function’s name, separated by a space. The passed parameters can be referenced with $1, $2, $3, $4, etc., corresponding to the position of the argument after the name of the function when it is executed. Below is a simple bash function that will create a directory and then navigate into it:

    BASH/SH
    mkcd () {
      mkdir -p -- "$1" && cd -p -- "$1"
    }

    Same as aliases, make sure to add the Bash functions in the ~/.bashrc file and run source ~/.bash_profile to make the changes take effect.

    Now instead of having to make a directory using mkdir and then move into that directory using cd, you can simply use our mkcd function:

    BASH SHELL
    mkcd testDirectory

    A few things that you need to know:

    • The -- makes sure that Linux does not get confused and parse the folder name as an argument. If you have a folder that starts with -, Linux might parse it as an argument.
    • The && ensures that the second command runs only if the first one is successful.

    Final Note

    By now you should have a good understanding of how Bash aliases and functions work. This should help you be more productive on the command line.

    If you have any questions or feedback, feel free to leave a comment on this post.

  • How to Create Bash Aliases in Linux, and How They Work

    If you are like me, you will often find yourself typing long, bulky, and hard-to-remember commands in the Linux terminal, and if not, I will almost always find myself searching the bash history for a long command I typed earlier. If you are also like me, this is where bash aliases come in handy. Bash aliases are like shortcuts, short, quick replacements for long, bulky commands. For example, you can use rmopwrt instead of opkg remove --force-remove --force-removal-of-dependent-packages ppp ppp-mod-pppoe odhcpd-ipv6only dnsmasq hostapd-common luci luci-ssl-openssl luci-base lua luci-app-firewall luci-lib-ip luci-lib-jsonc luci-lib-nixio luci-proto-ipv6 luci-proto-ppp luci-theme-bootstrap uhttpd uhttpd-mod-ubus. In this post, I will show you how to create bash aliases in Linux, so you can save time on the command line, and be more productive.

    Creating Bash Aliases

    Creating bash aliases is very easy and straightforward. The basic command is as follows:

    BASH SHELL
    
    alias whatever_you_want_your_alias_to_be_called="command_to_run"

    However, like always, make sure not to use spaces in the name, else Linux will think it is a command argument, and the alias command does not take any. When you create an alias, you type “alias”, followed by your alias name, an equal sign without spaces, and then, without spaces, in quotes, what command the alias should run. In the case above, running whatever_you_want_your_alias_to_be_called will do the same thing as running command_to_run.

    Let us try another example.

    BASH SHELL
    
    alias myip="hostname -I"

    When you run myip, you will get the same output as running hostname -I.

    Done!