Tweaks

Glad to know it is now working for you.

I tried to run the script after following the instructions, but keep getting the following error:

sudo: unable to execute ./optimize-gain.py: No such file or directory

I checked the directory and the file is indeed in there, so I am unsure why that error is popping up.

I must be missing something simple, but after deleting and recreating the file several times I still canā€™t get it to run.

I am using the Piaware SD card image

# first check if file optimize-gain.py is present in the current folder
dir
#if file is not there, cd to the folder where file optimize-gai.py is located
sudo chmod +x optimize-gain.py
sudo ./optimize-gain.py
1 Like

I was able to get to the site where I have the unit set up and run both those commands. I did verify the file was present (it popped up when I ran dir) before I ran the chmod and executable command, but still had the same error.

I tried creating a blank file, making it executable and running it, and didnā€™t have any issues, so it must be something with the gain optimization code within the file. I thought I could be missing a package the code needed to run, but the error wouldnā€™t make any sense if that were the case.

Would it help to re-image the SD card? According to everything I have read, the file should run, but for whatever reason the file system canā€™t detect the file and keeps displaying the error.

Delete optimize-gain.py file you have already created. Now do this:

#Create a new blank file optimize-gain.py and make it executable
sudo nano optimize-gain.py
sudo chmod +x optimize-gain.py

#now test blank file by running it
sudo ./optimize-gain.py

#if no error message appears, then next step is to add code to blank file and run again.

sudo nano optimize-gain.py

#copy-paste the code in blank file
#save file (Ctrl+o) and close it (Ctrl+x)

#now run the file
sudo ./optimize-gain.py

Looks like its the code that is affecting the file, because the blank file will run without errors. As soon as I add the code Iā€™ll get the same error as before. I tried deleting the everything after the for loop in the code, and the error was still present.

I experimented with removing certain sections of the code and the closest I could get is removing the first line. When I deleted #!/usr/bin/python2 the program will run with a different set of errors, but since these errors reference lines in the code I think the program is actually being run instead of not being read as is the case when the entire code is present

@ki6fro
I replicated your situation by formatting microSD card and writing Piaware SD card image.
Found solution: Install python.
Please see below for details

pi@piaware:~$ sudo nano optimize-gain.py

#Copy-pasted code from downloaded file "Optimize-Gain-Piaware-SD-Card-Image.docx"
#Saved file (Ctrl+o) and closed it (Ctrl+x)
#Made file "optimize-gain.py" executeable
pi@piaware:~$ sudo chmod +x optimize-gain.py

#Ran "optimize-gain.py", FAILURE
pi@piaware:~$ sudo ./optimize-gain.py
sudo: unable to execute ./optimize-gain.py: No such file or directory

#SOLUTION
pi@piaware:~$ sudo apt-get update

pi@piaware:~$ sudo apt-get install python
........
........
pi@piaware:~$ sudo ./optimize-gain.py
test 1 of 5
gain= 49.6 messages= 14817 positions= 1243 planes= 71
gain= 48.0 messages= 17085 positions= 1423 planes= 78
gain= 44.5 messages= 15815 positions= 1394 planes= 85
2 Likes

Thanks abcd567, that fixed it. That call to python at the beginning of the program should have tipped me off. Running the program now and itā€™s working.

Thanks for the help!

In my Piaware SD Card, I have installed Web Portal / Performance graphs, which installs python also during its installation. That is the reason I did not face any problem when I tried the script.

Only when I erased the existing Piaware SD card image and wrote fresh image, and tried to run optimize-gain.py, I got exactly your problem. I then realized that it is missing python, and when installed python, it started working normally.

Can it display FAā€™s MLAT calculations after doing this?

BOTH the dump1090-mutability AND dump1090-fa are capable to display FAā€™s MLAT.
Changing GUI/Skin does NOT prevent, or affect in any way, the display of FAā€™s MLAT.

1 Like

So seems just because not MLAT data available in my location :frowning:

It may be because

  1. You have not set your receiver location
    AND/OR
  2. Have not enabled MLAT

Please see following thread and set Receiver Location.
On configure page having ā€œConfigure Locationā€ button, there is also an option to Enable/Disable MLAT. Choose the Enable option

For Beginners - How To Set Receiver Location

.

Just local MLAT aircraft very few :sweat_smile:

I think thereā€™s something wrong in the docx file.
Character encoding can mess up things. Iā€™m getting the following error:

pi@raspberrypi:~ $ sudo ./optimize-gain.py
File "./optimize-gain.py", line 13
SyntaxError: Non-ASCII character '\xc2' in file ./optimize-gain.py on line 13, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Iā€™m on mutability & Stretch. I was using Optimize-Gain-dump-mut-on-Raspbian-Jessie.docx

@loplo
The character encoding is ok if opened by Microsoft Word on Windows.

It is bad when opened with LibreOffice on Linux Ubuntu.

I am not sure of Mac, but vaguely remember someone reporting similar problem as yours.

Which computer/OS you use?

Iā€™m using Windows 10, but I donā€™t have MS Office. Iā€™ve opened the doc with Microsoft Word pad and tried to fix it with notepad++.
In the end Iā€™ve found some of your code on the fr24 forums, and that worked.

At the time I made the thread ā€œTWEAKSā€, it was old format of forum which did not allow posting of scripts. As a result I had to copy scripts to Microsoft Word files (.docx) and uploaded to Dropbox, and gave links to these files.

Later, I came to know .docx format gives problem if opened by any software other than Microsoft Word. I prepared these files in plain text and wanted to change links of dropbox from .docx files to .txt files, but by that time forum formate was changed to new ā€œDiscourseā€, which did not allow editing of old posts.

Since the new forum format allows posting of code, I am posting below codes from all the .docx files here:

.

There are 4 Scripts below.
Their names describe the installation they will work with.
Select the one which applies to your installation, and copy paste that script to newly created blank file optimize-gain.py

(1) Optimize Gain Script for: Piaware SD Card-Image

#!/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 = "20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4".split()
#gains = "36.4 38.6 40.2 42.1 44.5 48.0 49.6".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('/boot/piaware-config.txt', inplace=1):
      if line.startswith('rtlsdr-gain'):
         print 'rtlsdr-gain '+g
      else:
         print line,

   os.system("sudo systemctl restart dump1090-fa")
   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())

.

(2) Optimize Gain Script for: dump1090-fa on Raspbian

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

measure_duration = 62  #duration of one 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 = "20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4".split()
#gains = "36.4 38.6 40.2 42.1 44.5 48.0 49.6".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-fa', inplace=1):
      if line.startswith('RECEIVER_OPTIONS'):
         print 'RECEIVER_OPTIONS="--device-index 0  --ppm 0 --gain  ' + g + ' --net-bo-port 30005 --net-sbs-port 30003"'
      else:
         print line,
   os.system("sudo systemctl restart dump1090-fa")
   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())


.

(3) Optimize Gain Script for: dump1090-mutability on Raspbian

#!/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())


.

(4) Optimize Gain Script for: dump1090 (Malcolm-Robb) on Raspbian

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

measure_duration = 15 #seconds
ntests = 10  #Number of tests
mutability = False    #set to True if you use dump1090-mutability
#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
   if mutability:
       p = subprocess.Popen(('/usr/bin/dump1090-mutability --net --gain '+g+' --oversample --fix --phase-enhance --quiet').split(),shell=False,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
   else:
       p = subprocess.Popen(('/usr/bin/dump1090 --net --gain '+g+' --quiet').split(),shell=False,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
   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()
   p.terminate()
   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())

3 Likes

Awesome, as always!
Thank you!

Ok, just to tie up TWEAK-2: REPLACING TWO-CLOCK MAP (DUMP1090-MUTABILITY) BY SKYVIEW MAP (DUMP1090-FA),

how does one revert back to the two clock map? I can sort of think of how to do it, but if I need to, I donā€™t want to break anything. I am thinking, it wonā€™t be too hard.