B1N9's ADSB Scripts & Tools (GAIN_CHECK_v3.py) (STATSV2 not released)

POST LAST UPDATE: 2023-01-24

Hello all, this topic is my main location to share my scripts and tools I create and use to help setup my ADSB Receiver.

I have 2 custom built tools currently only one is ready for release to users however the other is “coming soon” ™

  • GAIN_CHECK_v3.py
    • script should help you choose a STATIC GAIN setting that maximizes reception using more categories and distance calculations
  • STATSV2 (NOT RELEASED YET)
    • updated graphs1090 with updated graphs and statistics
    • portal with multi-tabbed interface to hold all your web pages in one portal.
    • portal help and links for command notes and examples

GAIN_CHECK_v3.py

NOTES GOAL

  • script should help you choose a STATIC GAIN setting that maximizes reception using more categories
    • ALL MESSAGE TYPES 1-8
      • you also want to maximize type 2 and type 3 messages
  • DISTANCE of RECEPTION including CLOSE, NORMAL, FAR
    • you want to be able to receive (CLOSE) DISTANCES & FAR DISTANCES at the same time

NOTES GENERAL

  • my (b1n9) take and maybe/hopefully an improvement of the optimize_gain.py script by (abcd567)
  • REQUIRES PYTHON 3 for better table display
  • DISTANCES are in MILES
  • DISTANCES are only calculated for TYPE 2 and TYPE 3 MESSAGES with lat/lon positions
  • TYPE 2 SURFACE MESSAGES are counted in 2 categories if they include lat/lon and all TYPE 2
  • TYPE 3 AIRBORN MESSAGES are counted in 2 categories if they include lat/lon and all TYPE 3

NOTES RUNNING EXAMPLE

  • I personally run at 5dB steps using short intervals (10s) and do a final verify with a long interval (62s)
    • RUN 1: passes 5, duration 10, gain gain_setp_5
    • RUN 2: passes 5, duration 62, gain gain_setp_5
  • I then run using all gains in the 10-20 dB span around what the first 2 runs tell me to find the best gain
    • RUN 3: passes 5, duration 10, gain gain_all_20
    • RUN 4: passes 5, duration 62, gain gain_all_20

CHANGE LOG (MOST RECENT VERSION ONLY)

# 3.3
# 	add in 2 columns for types 2 and 3 with lat/lon
# 	add in pos_ll or positions with LATLON ranking
# 	updated install instructions thanks to (abcd567)
# 	fix issue with categories if set contains no values (issue found by (gavin323))
# 	categories naming updated to be more clear
# 	update script header display
# 	update script final header display to include script_name, script_version, and script_author
# 	remove distance change from miles for now because of all hardcoded categories and columns
# 	update script documentation to be more clear
# 	update formatting to use variables instead of hardcodes
# 	add additional formatting
# 	cleanup config line variable naming
# 	fix config_setting and config_setting_after to make it actually work for other than PIAWARE SD
# 	update color display to work with all colors
# 	update to display table with values within color_top_percentage of best value

USER SETTINGS IN SCRIPT DESCRIPTIONS

# REQUIRED GAIN_CHECK SETTINGS DESCRIPTIONS
# 	antenna_lat				location of your antenna for distance calcs in xxx.xxx form) (use at least 3 decimal places for accuracy)
#	antenna_lon				location of your antenna for distance calcs in xxx.xxx form) (use at least 3 decimal places for accuracy)
# 	pass_duration			seconds for each gain (default 62)
# 	pass_number				number of passes to aggregate for totals (default 5)
# 	gain_choice				variable of gains to use (gains_step_5) or list of gains separated by space
# ----------------------------------------------------------------------------------------------------------------------
# REQUIRED DUMP1090 SETTINGS DESCRIPTIONS
# 	host 					url of dump1090 (default PIAWARE SD)
# 	port 					30003 = SBS port (default PIAWARE SD)
# 	config_file				path and filename of where gain settings are stored (default PIAWARE SD)
# 	config_setting			gain setting before the gain number
# 								(ex. "rtlsdr-gain 49.6" the config_setting is "rtlsdr-gain" no space after)
# 	config_setting_after	gain setting after the gain number
# 								(ex. "rtlsdr-gain 49.6 something" the config_setting_after is "something" no space before)
# 								(ex. "rtlsdr-gain 49.6" the config_setting_after is "")
# 	service_restart_cmd		command to restart service to apply changed gain (default PIAWARE SD)
# ----------------------------------------------------------------------------------------------------------------------
# OPTIONAL SETTINGS DESCRIPTIONS
#	distance_unit			mile or km (don't change off miles as it doesn't update categories and columns)
#	color_top_percent		5 values in same column within this percentage of the best value will also be highlighted in a different color

INSTALL PREREQUISITS

sudo apt install python3
sudo apt install python3-pip
sudo python3 --version 

if you have python3.7 or higher

sudo pip3 install beautifultable

if you have python3.6 or lower

sudo pip3 install beautifultable==1.0.1

DOWNLOAD SCRIPT

sudo wget https://github.com/sxb1n9/ADSB/raw/main/GAIN_CHECK/gain_check_v3.py

CONFIGURATION (SETTINGS)

sudo nano gain_check_v3.py

RUN

sudo python3 ./gain_check_v3.py

ISSUES, QUESTIONS

  • Please submit issues, questions on this post thread or on the GitHub repos issues

COMMENTS

  • Please leave a post if this script helps you and how you use it on this post thread to help others
4 Likes

 

pi@raspberrypi:~ $ sudo apt install python3.10
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package python3.10
E: Couldn't find any package by glob 'python3.10'

 

pi@raspberrypi:~ $ apt-cache policy python3
python3:
  Installed: 3.9.2-3
  Candidate: 3.9.2-3
  Version table:
 *** 3.9.2-3 500
        500 http://deb.debian.org/debian bullseye/main arm64 Packages
        100 /var/lib/dpkg/status

 

pi@raspberrypi:~ $ sudo apt install python3-venv python3-pip
... ... ...
... ... ...
Setting up python3-setuptools (52.0.0-4) ...
Setting up python3-wheel (0.34.2-1) ...
Setting up python3-pip (20.3.4-4+rpt1+deb11u1) ...
Processing triggers for man-db (2.9.4-2) ...

 

pi@raspberrypi:~ $ sudo pip3 install beautifultables
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
ERROR: Could not find a version that satisfies the requirement beautifultables
ERROR: No matching distribution found for beautifultables

1 Like

whoops i put a s at the end when i should not have.
looks like i didn’t do a great job with the install instructions on that or python. I technically have python 3.7 installed on my test piaware so any python 3 should work.

BTW this is based on your script I put your username and original post in the notes. If you want me to update anything or a different call out let me know.

sudo apt install python3
sudo apt-get install python3-pip
sudo pip3 install beautifultable

below is my install

pi@piaware:~ $ apt-cache policy python3
python3:
  Installed: 3.7.3-1
  Candidate: 3.7.3-1
  Version table:
 *** 3.7.3-1 500
        500 http://flightaware.com/mirror/raspbian/raspbian buster/main armhf Packages
        100 /var/lib/dpkg/status
pi@piaware:~ $ sudo apt-get install python3-pip
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-pip is already the newest version (18.1-5+rpt1).
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
pi@piaware:~ $ sudo pip3 install beautifultable
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: beautifultable in /usr/local/lib/python3.7/dist-packages (1.1.0)
Requirement already satisfied: wcwidth in /usr/local/lib/python3.7/dist-packages (from beautifultable) (0.2.6)
pi@piaware:~ $ sudo apt install python3-venv python3-pip

pi@piaware:~ $ sudo pip3 install beautifultable

pi@piaware:~ $ wget https://github.com/sxb1n9/ADSB/raw/main/GAIN_CHECK/gain_check_v3.py    

pi@piaware:~ $ sudo nano gain_check_v3.py

pi@piaware:~ $ sudo python3 gain_check_v3.py 

 

 

CLICK ON SCREENSHOT TO SEE LARGER SIZE

 

 

1 Like

Heads up on the display being crunched down the table needs a lot of width and will fix itself if you maximize the terminal.

My results

let me take a look and see if i need some error checking on those lines for exception cases. Will try to fix and put a new version up.

Hi
is there anyway i can alter to inc readsb as i use both
many thanks

gain_check_v3.py UPDATE to VERSION 3.3

NOTES

script_name			= "gain_check_v3.py"
script_version		= "3.3"
script_release		= "RELEASED"
script_author		= "sxb1n9 or b1n9"
print(line_break) #-----------------------------------------------------------------------------------------------------
print("SCRIPT: ", white + script_name + nocolor)
print("VERSION:", white + script_version + space + script_release + nocolor)
print("AUTHOR: ", white + script_author  + nocolor)
print(line_break + white) #---------------------------------------------------------------------------------------------
print("GOAL:" + nocolor)
print("    * script should help you chooose a STATIC GAIN setting that maximizes receiption using more categories")
print("        * ALL MESSAGE TYPES 1-8")
print("            * you also want to maximize type 2 and type 3 messages")
print("        * DISTNACE of RECEPTION including CLOSE, NORMAL, FAR")
print("            * you want to be able to receive (CLS or CLOSE) DISTANCES & FAR_1 or FAR_2 DISTANCES at the same time")
print(line_break + white) #---------------------------------------------------------------------------------------------
print("NOTES:" + nocolor)
print("    * my (b1n9) take and maybe/hopefully an improvement of the optimize_gain.py script by (abcd567)")
print("        * https://discussions.flightaware.com/t/tweaks/20339/36")
print("    * REQUIRES PYTHON 3 for better table display")
print("    * DISTANCES are in MILES")
print("    * DISTANCES are only calculated for TYPE 2 and TYPE 3 MESSAGES with lat/lon positions")
print("    * TYPE 2 GND or SURFACE MESSAGES are counted in 2 categories if they include lat/lon and all TYPE 2")
print("    * TYPE 3 AIR or AIRBORN MESSAGES are counted in 2 categories if they include lat/lon and all TYPE 3")
print(line_break + white) #---------------------------------------------------------------------------------------------
print("RUNNING:" + nocolor)
print("    * I personally run at 5dB steps using short intervals (10s) and do a final verify with a long interval (62s)")
print("        * RUN 1: passes 5, duration 10, gain gain_setp_5")
print("        * RUN 2: passes 5, duration 62, gain gain_setp_5")
print("    * I then run using all gains in the 10-20 dB span around what the first 2 runs tell me to find the best gain")
print("        * RUN 3: passes 5, duration 10, gain gain_all_20")
print("        * RUN 4: passes 5, duration 62, gain gain_all_20")
print(line_break + red) #------------------------------------------------------------------------------------------------
print("WARNING: " + nocolor)
print("    * if script exits before the end it does not reset the original gain and you must do it manually")
print(line_break) #-----------------------------------------------------------------------------------------------------

INSTRUCTIONS

# ----------------------------------------------------------------------------------------------------------------------
# PREREQUISITE INSTALLS 
# 	PYTHON 3				sudo apt install python3
# 	PYTHON 3 PIP			sudo apt install python3-pip
# 	BEAUTIFULTABLE			sudo pip3 install beautifultable
# ----------------------------------------------------------------------------------------------------------------------
# INSTALL / UPDATE SCRIPT 
# 	WGET SCRIPT				sudo wget https://github.com/sxb1n9/ADSB/raw/main/GAIN_CHECK/gain_check_v3.py
# ----------------------------------------------------------------------------------------------------------------------
# MODIFY SETTINGS			sudo nano gain_check_v3.py 
# ----------------------------------------------------------------------------------------------------------------------
# REQUIRED GAIN_CHECK SETTINGS DESCRIPTIONS
# 	antenna_lat				location of your antenna for distance calcs in xxx.xxx form) (use at least 3 decimal places for accuracy)
#	antenna_lon				location of your antenna for distance calcs in xxx.xxx form) (use at least 3 decimal places for accuracy)
# 	pass_duration			seconds for each gain (default 62)
# 	pass_number				number of passes to aggregrate for totals (default 5)
# 	gain_choice				variable of gains to use (gains_step_5) or list of gains seperated by space
# ----------------------------------------------------------------------------------------------------------------------
# REQUIRED DUMP1090 SETTINGS DESCRIPTIONS
# 	host 					url of dump1090 (default PIAWARE SD)
# 	port 					30003 = SBS port (default PIAWARE SD)
# 	config_file				path and filename of where gain settings are stored (default PIAWARE SD)
# 	config_setting			gain setting before the gain number
# 								(ex. "rtlsdr-gain 49.6" the config_setting is "rtlsdr-gain" no space after)
# 	config_setting_after	gain setting after the gain number
# 								(ex. "rtlsdr-gain 49.6 something" the config_setting_after is "something" no space before)
# 								(ex. "rtlsdr-gain 49.6" the config_setting_after is "")
# 	service_restart_cmd		command to restart service to apply changed gain (default PIAWARE SD)
# ----------------------------------------------------------------------------------------------------------------------
# OPTIONAL SETTINGS DESCRIPTIONS
#	distance_unit			mile or km (don't change off miles as it doesn't update categories and columns)
#	color_top_percent		5 values in same column within this percentage of the best value will also be highlighted in a different color
# ----------------------------------------------------------------------------------------------------------------------
# RUN 						sudo python3 gain_check_v3.py
# ----------------------------------------------------------------------------------------------------------------------

CHANGE LOG

# ----------------------------------------------------------------------------------------------------------------------
# CHANGELOG
# 3.0
# 	initial
# 3.1
# 	fix distance min
# 	save original value or gain and restore
#	additional starting notes for users
# 	show all 8 types msg count
#		second count for ground and air with lat/lon
# 	added other configs for other setups so that it can be used anywhere
# 	choose distance unit (mile, km)
# 	cleanup and document for release to others
# 	GAIN DESCION MAKING
# 		add top gain per category
# 		add color highlight at end for each column best on the table
# 	keep aircraft distance between all passes
# 	add seconds while receiving gain info
# 3.2
# 	not detecting minimums correctly
# 	not counting distance msgs correctly
# 	updated version and screenshots
# 3.3
# 	add in 2 columns for types 2 and 3 with lat lon
# 	add in pos_ll or positions with LATLON ranking
# 	updated install instructions thanks to (abcd567)
# 	fix issue with categories if set contains no values (issue found by (gavin323))
# 	categories naming updated to be more clear
# 	update script header display
# 	update script final header display to include script_name, script_version, and script_author
# 	remove distance change from miles for now because of all hardcoded categories and columns
# 	update script documentation to be more clear
# 	update formatting to use variables instead of hardcodes
# 	add additional formating
# 	cleanup config line variable naming
# 	fix config_setting and config_setting_after to make it actually work for other than PIAWARE SD
# 	update color display to work with all colors
# 	update to display table with values within color_top_percentage of best value
# ----------------------------------------------------------------------------------------------------------------------

edit the file

sudo nano gain_check_v3.py

edit the following lines

# PIAWARE SD SETTINGS (comment out and uncomment other settings to switch)
host					= 'localhost'
port 					= 30003
config_file				= '/boot/piaware-config.txt'
config_setting			= 'rtlsdr-gain'
config_setting_after	= ''
service_restart_cmd		= 'sudo systemctl restart dump1090-fa'

# DUMP1090-FA on RASPBIAN
# host					= 'localhost'
# port 					= 30003
# config_file			= '/etc/default/dump1090-fa'
# config_setting		= 'RECEIVER_OPTIONS="--device-index 0 --ppm 0 --gain'
# config_setting_after	= '--net-bo-port 30005 --net-sbs-port 30003'
# service_restart_cmd	= 'sudo systemctl restart dump1090-fa'

# DUMP1090-MUTABILITY on RASPBIAN
# host					= 'localhost'
# port 					= 30003
# config_file			= '/etc/default/dump1090-mutability'
# config_setting		= 'GAIN='
# config_setting_after	= ''
# service_restart_cmd	= 'sudo systemctl restart dump1090-mutability'

I am unsure how to control readsb so you would need to fill out the config with the proper values as in the instructions

# ----------------------------------------------------------------------------------------------------------------------
# REQUIRED DUMP1090 SETTINGS DESCRIPTIONS
# 	host 					url of dump1090 (default PIAWARE SD)
# 	port 					30003 = SBS port (default PIAWARE SD)
# 	config_file				path and filename of where gain settings are stored (default PIAWARE SD)
# 	config_setting			gain setting before the gain number
# 								(ex. "rtlsdr-gain 49.6" the config_setting is "rtlsdr-gain" no space after)
# 	config_setting_after	gain setting after the gain number
# 								(ex. "rtlsdr-gain 49.6 something" the config_setting_after is "something" no space before)
# 								(ex. "rtlsdr-gain 49.6" the config_setting_after is "")
# 	service_restart_cmd		command to restart service to apply changed gain (default PIAWARE SD)
# ----------------------------------------------------------------------------------------------------------------------
1 Like

fixed in newly released version 3.3

Assuming you run sudo wget https://github.com/sxb1n9/ADSB/raw/main/GAIN_CHECK/gain_check_v3.py to update 3.3 is throwing the same value error as before when it finishes

1 Like

I had to delete the original gain_check_v3.py file and then wget it again. Worked fine for me after that.

1 Like

I have just re downloaded the update and all is good. 49.6 is my best gain on almost all the tests

1 Like

Glad to hear it worked out well for you. Hope it helps give some more clarity into gain settings.

It does matter when you run this tool as to how many planes are in the sky you should try to run it at peak time if possible as you will get the best results.

Example I live in downtown Phoenix, Arizona, and my antenna is 200 ft above the ground facing west with the building in between myself and the east direction, however i am about 3-4 miles from Phoenix Sky Harbor Airport to the east, so I get a lot of super close planes as they fly by my highrise about 1 mile away and if my gain is too high it will overload. So I used the tool to find the best compromise between distance and close.

I can pick up planes about 275-300 miles away on full gain, however i lose tons of close planes if i do that. With my settings now I can get the close ones and the ones at the ground at the airport while still getting a 225-275 distance max range.

hope this helps.
b1n9

here are 3 screenshots right now at 8:38 local AZ time of range and ground planes at the same time.



here are some stats. I started optimizing with this tool on 01.05.2023 edited put wrong date

here is a link to my feeds stats https://flightaware.com/adsb/stats/user/b1n9#stats-117494

This is my current range since running the script. I’m about 4.5 miles from my airport so can’t get ground coverage but get them right to the end of the runway


1 Like

did the script help you improve your coverage or at least know more about it?

From early results I’m definitely seeing improvements both locally and further across the UK

1 Like

Thats great sounds like we have very similar situations with ability to get long range and being right next to an airport.

I have found some of my biggest improvements was a good filter stack and antenna.

I have the following:

  • Antenna:
    • Signal Plus 1090/978 MHz (9 dB gain) (N Type)
  • Coaxial:
    • 6ft Times Microwave LMR400 (< 0.5 dB loss) (N Type to SMA)
  • Cavity Filter (not really it is actually ladder circuit or LC filter):
    • Light Blue Flightaware 1090/978 (SMA to SMA)
  • T splitter
    • (SMA male to 2x SMA male)
  • Saw Filter
    • adsbexchange saw filter (SMA)
  • 1090 SDR
    • adsbexchange blue (aka better packaged flightaware blue w/ LNA and filter) (SMA)
  • 978 SDR
    • adsbexchange orange (aka better packaged flightware orange) (SMA)



Previous Equipment:

  • Antenna:
    • Flightaware 1090/978 Antenna
  • Splitter
    • coaxial splitter
  • 1090 SDR
    • flightaware blue w/ LNA and filter
    • RTL-SDRv3
  • 978 SDR
    • flightware orange
    • RTL-SDRv3

Wanted Upgrades:

  • jetvision cavity filter 1090
  • airspy mini (for more dynamic range)

From what I gather, the airspy mini gives more messages but in terms of ac numbers it’s pretty much the same as FA blue