Showing posts with label radio. Show all posts
Showing posts with label radio. Show all posts

Sunday, May 17, 2020

HackRF and ADS-B and COVID-19 in pictures

Given the current COVID-19 situation, I thought I'd take a look at what else was in the air. With not much to do these days, it was a good reason to pull out my ADS-B aerial and see about getting my HackRF One device to play with VirtualRadar.

Some pictures from VirtualRadar are in the second half of this post, the first half talks about setting things up.

In my blog post from 2016 I described my experience getting ADS-B going with an rtl device. If you're reading this, you probably already know what ADS-B is, but if for some reason you don't, you probably want to check my earlier post.


Setting Things Up


HackRF isn't supported by the dump1090 or the rlt_adsb applications for Linux, so I spent quite a bit of time trying to work out how to get some "1090" software to work with VirtualRadar. I tried gr-air-modes but it was a total disaster trying to "make" even under Debian 10 (Buster) due to a pyqt4 dependency and I almost gave up the whole idea.

In the end I found a fork of dump1090 that installed and worked with little drama. The configuration of VirtualRadar is slightly different from that in my rtl post.

Here's the dump1090 fork install steps - it wasn't quite as straightforward as the doc suggested.

This bit went fine:

$ sudo apt-get install librtlsdr0 librtlsdr-dev libhackrf-dev libairspy-dev libsoxr-dev
$ chmod 755 Downloads/SDRplay_RSP_API-Linux-2.13.1.run
$ ./Downloads/SDRplay_RSP_API-Linux-2.13.1.run

$ sudo ldconfig
$ cd personal/git/
$ git clone https://github.com/itemir/dump1090_sdrplus.git

This bit did not go so fine:

$ cd dump1090_sdrplus/
$ make
.../usr/bin/ld: dump1090.o: in function `readerThreadEntryPoint':
/home/xxx/personal/git/dump1090_sdrplus/dump1090.c:852: undefined reference to `rtlsdr_read_async'
/usr/bin/ld: dump1090.o: in function `main':
/home/xxx/personal/git/dump1090_sdrplus/dump1090.c:3172: undefined reference to `rtlsdr_close'
collect2: error: ld returned 1 exit status
make: *** [Makefile:12: dump1090] Fehler 1


This turns out to be a known issue requiring (on Debian) an edit of /usr/lib/x86_64-linux-gnu/pkgconfig/librtlsdr.pc :

prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include


Then I could build:

$ make
cc -g -o dump1090 dump1090.o anet.o  -lrtlsdr -lhackrf -lairspy -lsoxr -lpthread -lm -lmirsdrapi-rsp


Starting dump1090, it first looked for rtlsdr and then for a HackRF:

$ ./dump1090
No supported RTLSDR devices found.
Unable to initialize RSP
HackRF successfully initialized (AMP Enable: 0, LNA Gain: 32, VGA Gain: 48).


Interactive mode fairly quickly showed promising results:


$ ./dump1090 --interactive

...

Hex    Flight   Altitude  Speed   Lat       Lon       Track  Messages Seen  .
--------------------------------------------------------------------------------
3e6bd1 DKGAJ    3900      0       0.000     0.000     0     8         0 sec




Here I tell the application that I have a HackRF and that I want it to stream the results over the network, binding to port 8081 instead of the default 8080 for the web display because VirtualRadar will fail to start when it also tries to bind to port 8080.

$ ./dump1090 --dev-hackrf --net --net-http-port 8081
HackRF successfully initialized (AMP Enable: 0, LNA Gain: 32, VGA Gain: 48).
*8d471f59ea3e9858011c08f4aa9d;
CRC: f4aa9d (ok)
Single bit error fixed, bit 82
DF 17: ADS-B message.
  Capability     : 5 (Level 2+3+4 (DF0,4,5,11,20,21,24,code7 - is on airborne))
  ICAO Address   : 471f59
  Extended Squitter  Type: 29
  Extended Squitter  Sub : 2
  Extended Squitter  Name: Unknown
    Unrecognized ME type: 29 subtype: 2


This dump1090 version seems to have VirtualRadar directly in mind because the default ports it uses to stream data was what VirtualRadar expects by default.

$ netstat -pano | grep dump
tcp        0      0 0.0.0.0:8081            0.0.0.0:*               LISTEN      17413/./dump1090     aus (0.00/0/0)
tcp        0      0 0.0.0.0:30001           0.0.0.0:*               LISTEN      17413/./dump1090     aus (0.00/0/0)
tcp        0      0 0.0.0.0:30002           0.0.0.0:*               LISTEN      17413/./dump1090     aus (0.00/0/0)
tcp        0      0 0.0.0.0:30003           0.0.0.0:*               LISTEN      17413/./dump1090     aus (0.00/0/0)


VirtualRadar is configured according to the following screenshot, most of this is defaults:




Note that if you use google as the map provider then you need to setup API access and you probably don't want to do that, so use Leaflet.

And we're away.


There Must Be Something in the Air

Over a few hours I did see activity but the sky wasn't exactly alive wih commercial traffic. I should also add that I face west and it's quite possible that my position captures very little of the Munich airport traffic.



Overwhelmingly most of the planes I saw today were private. Obviously registered around near where I live (Munich, Germany) with the curious exception of this fellow out of the US:





Tel-Aviv.



It's hard to say how many airlines were running cargo, but this Egyptian one obviously was:


Someone in Munich was having a bad day, here's a rescue helicopter:



Qatar




Saudi



China



Libya - Not sure if the flight path is accurately recorded:






Sunday, October 23, 2016

Software Defined Radio and ADS-B with RTL-SDR

I recently participated in an introduction to Software Defined Radio (SDR). The point of the introduction was to get an RTL-SDR device running and then check out ADS-B. This was a load of fun and I've pulled together here a few notes to document my experience as a newbie.

The notes here focus on the software that worked for me, with particular focus on getting meaningful ADS-B data.

What is SDR?

Software Defined Radio (SDR) has advantages over traditional radio concepts by farming aspects of signal processing to software, rather than requiring expensive hardware. Additionally, SDR provides a practical solution to handling tracts of frequencies at the same time.

What is RTL?

RTL is shorthand for the affordable and apparently versatile Realtek 2832U chipset found in the SDR dongles referenced in this blog. See more information on the rtlsdr.org website.

What is ADS-B?

The introduction I attended was to demonstrate the RTL-SDR as a radio receiver and then move to listening in on ADS-B data from aircraft. This data includes flight information like where the aircraft is in the air, how fast it's moving, flight number, an ICAO 24-bit transponder code and so on.

Is Listening to ADS-B legal?  

Apparently so and commonly done, since services like FlightRadar24 openly track the same data. It is probably safe to say that it is not illegal to listen to anything on the radio spectrum since it is in the public domain

What RTL-SDR Should I Buy?

NooElec NESDR Mini USB RTL-SDR
Two weeks before the SDR introduction was scheduled, I purchased a NooElec NESDR SMArt - Premium RTL-SDR via Amazon but the thing never showed up. At the last minute I purchased instead the NooElec NESDR Mini USB RTL-SDR (pictured right), which arrived the next day (thanks Amazon Prime). The RTL appears to be the same in both, the difference is that the former device had three aerials and an SMA input. The SMA is supposedly more versatile, but adapters are available. The aerial on the latter and cheaper unit isn't fabulous, but for my initial purpose it worked well.

Software - Windows

First off, if you bought a NooElec device, you'll need to follow the instructions for installing the correct drivers under Windows. There's another nice quick-start guide here.

SDRSharp | SDR#

Under Windows I was easily able to use the SDR Sharp (SDR#) software to tune into FM radio stations and amateur frequencies. It seems to be the general-purpose Windows radio software.


The important config points are that you select RTL-SDR from the Source and then select the cog icon at top to bring up the Device settings (right).

There is also HDSDR and CubicSDR that appear to do the same job as SDR#. I did play around with them, but SDR# is the one I primarily use under Windows.

The moment that you need to do anything interesting, however, it seems that you need to switch to Linux. I can confirm that on Windows 10, dump1090 works very nicely with VirtualRadar and with almost no configuration required. This post isn't going to discuss setting all that up, it's well enough documented on the rtlsdr.org website.

Software - Linux

For a Windows-only person, this isn't as daunting as it sounds. You can run Linux as a Virtual Machine on your Windows system. A number of steps need to be undertaken to get that going. This starts with installing VirtualBox or VMware Player, both are free downloads. VirtualBox seems like less hassle but I find VMware Player more flexible and useful. For this situation, VirtualBox is fine.

Also remember to connect the RTL device to the Virtual Machine (VMware screenshot):


Once you have a Linux system running, either as a Virtual Machine or natively installed you might find the following packages useful to install (these are debian / ubuntu packages):
$ sudo apt-get install git cmake libqt5core5 libqt5core5a libqt5dbus5 libqt5gui5 libqt5network5 libqt5svg5 libqt5widgets5 qt5-default gnuradio-audio gnuradio gnuradio-dev gnuradio-dev libgnuradio-audio3.7.10 open-vm-tools rtl-sdr gqrx-sdr

gqrx

gqrx appears to be the Linux standard for Windows' SDR#. Naturally there's nothing new I can add to the existing config docs, but here is how I configured it for RTL-SDR:


rtl_adsb

This application should automatically pick up the RTL-SDR device and tune into the ADS-B frequency, streaming the data to a network port that another application can connect to. I recommend something like this, which keeps the application alive and connects to a port (this example 10000) that you define:
$ while :; do rtl_adsb | netcat -lp 10000 127.0.0.1; done
We will use VirtualRadar to read the data.

dump1090 is an alternative to rtl_adsb, but as it is not part of the default Debian package sources I had trouble getting it compiled (in fact I got it running well after the workshop).

Note also that ADSBSpy, which comes with SDRSharp did not not seem to be RTL-SDR compatible.

VirtualRadar

VirtualRadar will take the ADS-B data and render it against a Google Map. VirtualRadar doesn't care what the data source is, just so long as the source provides data that VirtualRadar can parse.

VirtualRadar runs well under Linux although requires 'mono' to run:
$ sudo apt-get install mono-complete
$ mkdir VirtualRadar
$ cd VirtualRadar/
$ wget http://www.virtualradarserver.co.uk/Files/VirtualRadar.tar.gz
$ tar xvf VirtualRadar.tar.gz
$ mono VirtualRadar.exe
Pay attention to the VirtualRadar.exe.config edit that you may need to make described here.

The main panel looks something like the screenshot below. One clicks on the http link to see the Google Map with the detected planes mapped against it, but remember that your PC/laptop requires a web connection to render the Google Map:


Setting up the right "receiver" information is critical. Below is a configuration screenshot when using rtl_adsb as the data source. Notice that the Port 10000 is that which is used in the rtl_adsb example above.



What to Expect

If you live near an airport, even with an imperfect antenna you should receive 1090MHz signals easily. However, as you get further from an airport your chances of picking it up lessen. The ADS-B data is almost impossible to pick up indoors, it really favours an antenna located outside and line-of-site.

If you want to build a perfect antenna for ADS-B, check this site out:

You Gotta Keep 'em Calibrated

Listening to a signal from a known precise station will tell you how far off your SDR is. My father, an amateur radio operator who was visiting me at the time, used an APRS channel to ascertained a -10,000Hz offset on my RTL-SDR. This will vary from device to device. He recommended amateur radio stations as reliable sources because they have a somewhat self-regulated standard of precision. I guess you could also calibrate off a known FM radio station if you were sure of its exact frequency.

What Next?

Good question. I have more to investigate. Stay tuned ;-)