Rotating gain

hi all

I was observing a slight increase in aircraft / messages early morning hours
(when all noise die down, traffic, cellphones etc) if i increased the gain from 38.6/40.2
to 48.0/49.6 and was wondering is there a way to have sort of ‘rotating’ gain ?
that is, pre-program gains to be used by the software ( I use dump1090-mutability)
to decrease gain at peak times, say 08:00-23:00 and increase it between 23:01-07:59 ?
or at other set intervals. can it be done through a script ?

thanks in adv

evangel

of course you can do this time-based with a script. if your own coding skills aren’t enough you could use e.g. one of those scripts as a basis and modify it to your needs. autorun of the script e.g. via cronjob: Tweaks - #4 by abcd567

but to be honest i do not really think that all this will see huge improvements to your site …

hi Tom

i found and modified this code with ‘google assistance’ cause i know very little about programming and that in Visual Basic. so took 7-8 hrs to shape it to my need (only for use with dump1090-mutability).
i used some other code but kept erasing /etc/default/dump1090-mutablitity file.
other than that, i do need a ‘ready-made’ script to change the gain at preset times, and that cause i do not know how to program in python. being 63 is a little late to start learning python.
due to my position and antenna (i use abcd567 cantenna and/or spider) i try to scavenge every acft position available.

the code i modified

#!/usr/bin/python2

20.Oct.2017 ----------------------------> OK --------------------

import argparse, os, socket, threading
from subprocess import Popen, PIPE
from datetime import datetime
from select import select
import time, fileinput, os

try:
import queue
except:
import Queue as queue # For Python 2.x

os.system(‘clear’)

def date(): # Returns UTC date and time in the format DD MM YY HH:MM:SS
return datetime.strftime(datetime.utcnow(), ‘%a %d %b %Y %H:%M:%S UTC’)

==== CHANGE PARAMETERS AS REQUIRED =================================================================

measure_duration = 60 # duration of each pass seconds
ntests = 3 # number of tests
gainstr = “20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4 37.2 38.6 40.2 42.1 43.4 43.9 44.5 48.0 49.6 -10”

gains = gainstr.split()
gains.reverse()
results = {}

s_port = 30003
s_format = “Basestation”

====================================================================================================

print " "
print “--------------------------------------------------------------”
print " DUMP1090-MUTABILITY * GAIN OPTIMIZATION TESTER "
print " "
print " ", "will run ", ntests, " test(s) for ", measure_duration, " seconds per gain setting, "
print " “, “using data received on port”, s_port, " format”, s_format # AVR, Beast, SBS etc.
print " ", "for the following gains : "
print " ", gainstr
print " "
print " ", date()
print “--------------------------------------------------------------”

orig_gain = “”

for i in range(ntests):
print " "
print " test", i+1, “of”, ntests
print " gain mesgs posns acft"
for g in gains:
if g not in results:
results[g] = [0,0,{}] # msgs, positions, aircraft

for line in fileinput.input(‘/etc/default/dump1090-mutability’, inplace=1):
if line.startswith(‘GAIN’):
if len(orig_gain) < 1:
orig_gain = line # remember AND preserve !
print(orig_gain),
os.system(“sudo systemctl restart dump1090-mutability”)
else:
print(line),
os.system(“sudo systemctl restart dump1090-mutability”)
else:
print(line),
os.system(“sudo systemctl restart dump1090-mutability”)
time.sleep(2)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((‘localhost’,s_port))
t = time.time()
d = ‘’
while 1:
d += s.recv(32)
if time.time() - t > measure_duration:
break
s.close()
messages = 0
positions = 0
planes = {}
for l in d.split(‘\n’):
a = l.split(‘,’)
messages += 1
if len(a) > 4:
if a[1] == ‘3’:
positions += 1
planes[a[4]] = 1
print " ",g, " ", messages, " ", positions, " ", len(planes.keys())

results[g][0] += messages
results[g][1] += positions
for hex in planes.keys():
results[g][2][hex] = 1

print(" “)
print(” === Totals ============“)
print(” Gain, Mesgs, Posns, Acft")
for g in gains:
(messages,positions,planes) = results[g]
print " ", g, " ", messages, " ", positions, " ",len(planes.keys())

#--------------------------------------------------------------------------

os.system(“sudo service dump1090-mutability restart”)

print(‘\n’)
print " ", date(), " - orig ", orig_gain
print “--------------------------------------------------------------”
print(‘\n’)

END

and the balcony antenas

IMG0052A

:))) and does it work now?

it works measuring gains, but not at preset times as i need (eg 37.2 at 08:00Z then 48.0 at 23:00Z).
even better will be to check gains every hour and select / set the best for that time.

for your needs 95% of the code isn’t needed. you just have to use the lines that open the settings-file, search and replace the gain setting and restart dump1090. but again - believe me this is the wrong idea to really improve your site :slight_smile:

@evangelyul
You have removed indent of all python code, making all lines flush with left margin. This will make Python code fail as it is very sensetive to relative indenting of lines.

If the indent is gone due to posting code as normal text message instead of code, there is a very easy and simple method. Put three (3) grave accents ``` above and below the chunk of code, and it will post as code. The grave-accent key is the top-left key left of digit 1 on US keyboard.

Grave-Accent Key, US Keyboard

.
.
How to make whole chunk of lines post as code
CLICK ON IMAGE TO ENLARGE

1 Like

Optimize-Gain-dump-mut-on-Raspbian .py

#!/usr/bin/python2
import time, socket, subprocess, fileinput, os

measure_duration = 62  #duration of each pass, seconds
ntests = 5   #number of tests
gains = "20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4 37.2 38.6 40.2 42.1 43.4 43.9 44.5 48.0 49.6".split()
#gains = "36.4 38.6 40.2 42.1 44.5 48.0 49.6".split()
#gains = "22.9 25.4 28.0 29.7 32.8 33.8 36.4".split()
gains.reverse()
results = {}

for i in range(ntests):
  print "test", i+1, "of", ntests 
  for g in gains:
   if g not in results:
      results[g] = [0,0,{}] #msgs, positions, aircraft

   for line in fileinput.input('/etc/default/dump1090-mutability', inplace=1):
      if line.startswith('GAIN'):
         print 'GAIN='+g
      else:
         print line,
   os.system("sudo systemctl restart dump1090-mutability")
   time.sleep(2)
   s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   s.connect(('localhost',30003))
   t = time.time()
   d = ''
   while 1:
      d += s.recv(32)
      if time.time() - t > measure_duration:
         break
   s.close()
   messages = 0
   positions = 0
   planes = {}
   for l in d.split('\n'):
      a = l.split(',')
      messages += 1
      if len(a) > 4:
         if a[1] == '3':
            positions += 1
         planes[a[4]] = 1
   print "gain=",g, "messages=", messages, "positions=", positions, "planes=", len(planes.keys())
   results[g][0] += messages
   results[g][1] += positions
   for hex in planes.keys():
      results[g][2][hex] = 1

print "\n===Totals==="
print "Gain, Messages, Positions, Aircraft"
for g in gains:
   (messages,positions,planes) = results[g]
   print g, messages, positions, len(planes.keys())

thanks Tom and abcd567

you are right about ident, i noticed while playing with this code for 7-8 hours.
i downloaded the code from pi to MS-Word saved it as text and uploaded it.
i could not find the code tags.

#!/usr/bin/python2
# 20.Oct.2017 ----------------------------> OK --------------------
import argparse, os, socket, threading
from subprocess import Popen, PIPE
from datetime import datetime
from select import select
import time, fileinput, os

try:
    import queue
except:
    import Queue as queue # For Python 2.x

os.system('clear')

def date(): # Returns UTC date and time in the format DD MM YY  HH:MM:SS
    return datetime.strftime(datetime.utcnow(), '%a %d %b %Y %H:%M:%S UTC')

# ==== CHANGE PARAMETERS AS REQUIRED =================================================================

measure_duration = 60   # duration of each pass seconds
ntests = 3              # number of tests
gainstr = "20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4 37.2 38.6 40.2 42.1 43.4 43.9 44.5 48.0 49.6 -10"

gains = gainstr.split()
gains.reverse()
results = {}

s_port = 30003
s_format = "Basestation"

# ====================================================================================================

print " "
print "--------------------------------------------------------------"
print "    DUMP1090-MUTABILITY * GAIN OPTIMIZATION TESTER "
print " "
print "   ", "will run ", ntests, " test(s) for ", measure_duration, " seconds per gain setting, "
print "   ", "using data received on port", s_port, " format", s_format         # AVR, Beast, SBS etc.
#      port 30002 format AVR "
#      port 30005 format Beast "
print "   ", "for the following gains : "
print "   ", gainstr
print " "
print "   ", date()
print "--------------------------------------------------------------"

orig_gain = ""

for i in range(ntests):
  print " "
  print "    test", i+1, "of", ntests
  print "    gain   mesgs   posns   acft"
  for g in gains:
   if g not in results:
      results[g] = [0,0,{}]     # msgs, positions, aircraft

   for line in fileinput.input('/etc/default/dump1090-mutability', inplace=1):
      if line.startswith('GAIN'):
         if len(orig_gain) < 1:
            orig_gain = line     # remember AND preserve !
            print(orig_gain),
            os.system("sudo systemctl restart dump1090-mutability")
         else:
            print(line),
            os.system("sudo systemctl restart dump1090-mutability")
      else:
         print(line),
   os.system("sudo systemctl restart dump1090-mutability")
   time.sleep(2)
   s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   s.connect(('localhost',s_port))
   t = time.time()
   d = ''
   while 1:
      d += s.recv(32)
      if time.time() - t > measure_duration:
         break
   s.close()
   messages = 0
   positions = 0
   planes = {}
   for l in d.split('\n'):
      a = l.split(',')
      messages += 1
      if len(a) > 4:
         if a[1] == '3':
            positions += 1
         planes[a[4]] = 1
   print "   ",g, "   ", messages, "   ",  positions, "   ",  len(planes.keys())

   results[g][0] += messages
   results[g][1] += positions
   for hex in planes.keys():
        results[g][2][hex] = 1


print(" ")
print("    ===  Totals ============")
print("    Gain, Mesgs, Posns, Acft")
for g in gains:
   (messages,positions,planes) = results[g]
   print "   ", g, " ", messages, "  ", positions, "   ",len(planes.keys())

#--------------------------------------------------------------------------

os.system("sudo service dump1090-mutability restart")

print('\n')
print "   ", date(), " - orig ", orig_gain
print "--------------------------------------------------------------"
print('\n')

# END

so i believe now is ok.

as for improving the site.
this is temporary when i visit my son for few months, and there are restrictions.
I made the pole out of broom stick, imagine.
and, luck of funds for better gear. i am happy though with RPi3, Prostick Plus, cantenna.

2 Likes

cmon - before you die over the curiosity what huge improvement this could add to your site - this should do the trick :slight_smile:

cheers
tom

sudo crontab -e

throw the below lines in the crontab (make sure that an empty line is at the end):

58 22 * * * sed -i -e 's/GAIN=".*"/GAIN="48.0"/g' /etc/default/dump1090-mutability
0 23 * * * /etc/init.d/dump1090-mutability force-reload
58 7 * * * sed -i -e 's/GAIN=".*"/GAIN="37.2"/g' /etc/default/dump1090-mutability
0 8 * * * /etc/init.d/dump1090-mutability force-reload
1 Like

thank you Tom, appreciate your time.
I did not know of ‘crontab’ . I guess is timer / action related.will give it a try see what happens.
for automation i use the /etc/rc.local.
see ideal would have been top of the building (or the nearby hill even better :wink: , proper filter, antenna etc.
so the rest are just patches.

2 Likes

no big deal! looked into your site stats - and saw that they are already very good. you are within the top-performers in nearby sites with your broomstick-cantenna construction :slight_smile:

greetings from munich/germany
tom

thanks Tom
so you reckon that’s the top for this configuration ?

I named it Cantenna because this defination suits me and other Canadians like evanglyul :smile:
Cantena = Canadian antenna

The other reason I named it Cantenna is
Cantenna = Can antenna

1 Like

no - not for your configuration - but maybe for the actual location of antenna. we’ll see what your gain-rotation will bring … que sera sera the future’s not ours to see :slight_smile:

@ abcd567
very apprppriate - mind you I tried different cans from tuna-can, coffee-can large diameter, beer-can
it seems coke-can stuffed with some aluminum foil inside performs better than the rest.

another combo that works for me is the 13cm spider you made, mounted on top of the coke-can
but is hard to protect from elements. for the other i use as radome the large Tim Horton’s cups :grin:

@ Tom
yes you are right :grinning: