Does NOT require www-data to be added to sudoers group
The setgain.sh
script is written by @wiedehopf. This original script is for Piaware SD card image. Necessary modifications in this script were made by @abcd567 to adopt it for dump1090-mutability package install.
.
.
Only Step-1 is different for Jessie and Stretch, rest is same.
STEP-1 (JESSIE): Install necessary php packages and enable module
sudo apt update
sudo apt install php5-cgi
sudo lighty-enable-mod fastcgi-php
sudo /etc/init.d/lighttpd force-reload
STEP-1 (STRETCH): Install necessary php packages and enable module
sudo apt update
sudo apt install php7.0-cgi
sudo lighty-enable-mod fastcgi-php
sudo /etc/init.d/lighttpd force-reload
.
STEP-2: Gain Changing Script
2.1 - Create new directory
sudo mkdir /usr/local/sbin/gain
2.2 - Create a new blank script file setgain.sh inside this new directory
sudo touch /usr/local/sbin/gain/setgain.sh
2.3 Add entry in cron to run script setgain.sh at boot
sudo crontab -e
#Scroll down and ADD following line at the end
@reboot /bin/bash /usr/local/sbin/gain/setgain.sh
Save (Ctrl+o) and Close (Ctrl+x)
.
2.4 - Open file setgain.sh to edit
sudo nano /usr/local/sbin/gain/setgain.sh
.
2.5 - Copy-paste following code in file setgain.sh
#!/bin/bash
# redirect all output and errors of this script to a log file
exec &>/usr/local/sbin/gain/log
# file that anyone can write to in order to set a new gain
fifo=/usr/local/sbin/gain/newgain
# remove $fifo so we are sure we can create our named pipe
rm -f $fifo
# create the named pipe with write access for everyone
mkfifo -m 666 $fifo
# read current gain and store in file currentgain
# script in gain.php will read gain value stored in currentgain and
# will display it on map as "Current Gain"
sed -n 's/\GAIN=//p' /etc/default/dump1090-mutability > /usr/local/sbin/gain/currentgain
while sleep 1
do
if ! [[ -r $fifo ]] || ! [[ -p $fifo ]]
# exit the loop/script if $fifo is not readable or not a named pipe
then break
fi
# read one line from the named pipe, remove all characters but numbers, dot, minus and newline and store it in $line
read line < <(tr -cd '.\-0123456789\n' < $fifo)
#set new gain
sed -i '/GAIN=.*/c\GAIN='$line /etc/default/dump1090-mutability
#restart dump1090-mutability to implement new gain value
systemctl restart dump1090-mutability
# read updated gain and store in file currentgain
sed -n 's/\GAIN=//p' /etc/default/dump1090-mutability > /usr/local/sbin/gain/currentgain
# script in gain.php will read the updated gain and display it on map
done
Save (Ctrl+o) and Close (Ctrl+x) the file.
.
STEP-3: Create a new file gain.php
containing gain button, drop-down list of gains & current gain display. This file will be embedded in dump1090 Map in Step - 4
.
3.1 - Create a new file gain.php
in folder /usr/share/dump1090-mutability/html
sudo nano /usr/share/dump1090-mutability/html/gain.php
3.2 - Copy-paste following code in newly created blank file gain.php
NOTE: Some of code lines are very long. Scroll Right to see these in full
.
<html>
<form id="myform" action="gain.php" method="post" />
<div><font color=#ff0000 face="'Helvetica Neue', Helvetica, Arial, sans-serif">Current Gain: <?php system('cat /usr/local/sbin/gain/currentgain');?> </font></div>
<select name="gain" id="gain">
<option value=-10>-10</option>
<option value=49.6>49.6</option>
<option value=48.0>48.0</option>
<option value=44.5>44.5</option>
<option value=43.9>43.9</option>
<option value=43.4>43.4</option>
<option value=42.1>42.1</option>
<option value=40.2>40.2</option>
<option value=38.6>38.6</option>
<option value=37.2>37.2</option>
<option value=36.4>36.4</option>
<option value=33.8>33.8</option>
<option value=32.8>32.8</option>
<option value=29.7>29.7</option>
<option value=28.0>28.0</option>
<option value=25.4>25.4</option>
<option value=22.9>22.9</option>
<option value=20.7>20.7</option>
<option value=19.7>19.7</option>
<option value=16.6>16.6</option>
</select>
<input type="submit" value="Set Gain" style="color:#ffffff;background-color:#00A0E2;border-color:#00B0F0;" />
</form>
</html>
<?php
function setgain(){
$gain="{$_POST['gain']}";
system("echo $gain > /usr/local/sbin/gain/newgain");
sleep(5);
header("Refresh:0");
}
if ("{$_POST['gain']}"){
setgain();
}
?>
Save (Ctrl+o) and Close (Ctrl+x)
.
STEP-4: Edit file gmap.html
and add code to embed newly created file gain.php (the file gain.php contains “Set Gain” button & drop-down menu).
.
4.1 - BEFORE EDITING, make its backup copy. This will enable you to revert in case something goes wrong.
cd /usr/share/dump1090-mutability/html/
sudo cp gmap.html gmap.html.orig
#Check to ensure back-up copy has been created by giving ls command
ls
#The output should contain both gmap.html and gmap.html.orig
config.js formatter.js markers.js style.css
coolclock gain.php ol3 test
db gmap.html.orig planeObject.js upintheair.json
dbloader.js gmap.html registrations.js
flags.js jquery script.js
flags-tiny layers.js spinny.gif
.
4.2 - Open the file gmap.html
for editing
cd /usr/share/dump1090-mutability/html/
sudo nano gmap.html
.
4.3 - Press Ctrl+w then type sudo_buttons
then press Enter key.
The cursor will jump to line <div id="sudo_buttons">
, as shown below
</div> <!-- timestamps -->
<div id="sudo_buttons">
<table style="width: 100%">
<tr>
<td style="width: 150px; text-align: center;" class="pointer">
[ <span onclick="resetMap();">Reset Map</span> ]
</td>
</tr>
</table>
</div> <!-- sudo_buttons -->
.
5.4 - Just above line <div id="sudo_buttons">
, insert following 3 lines
<div id="GAIN" style="text-align:center;width:175px;height:65px;">
<iframe src=gain.php style="border:0;width:175px;height:65px;"></iframe>
</div> <!----- GAIN --->
.
After insertion of 3 lines, the code will be like shown below:
</div> <!-- timestamps -->
<div id="GAIN" style="text-align:center;width:175px;height:65px;">
<iframe src=gain.php style="border:0;width:175px;height:65px;"></iframe>
</div> <!----- GAIN --->
<div id="sudo_buttons">
<table style="width: 100%">
<tr>
<td style="width: 150px; text-align: center;" class="pointer">
[ <span onclick="resetMap();">Reset Map</span> ]
</td>
</tr>
</table>
</div> <!-- sudo_buttons -->
Save (Ctrl+o) and Close (Ctrl+x)
.
STEP-5: Test and Run
5.1 - Reboot Pi for cron to run the script setgain.sh at startup.
5.2 - After Pi has rebooted, go to page IP-of-PI/dump1090-fa/ and check gain setting add-on appears as shown in screenshot below.
The value show in Red at browser load or re-load is your current gain value.
If you want to change it, click open drop-down menu, select the desired gain and click “Set Gain” button. After about 5 seconds, the Current Gain (red) will be updated.
Check the gain value by following command. The last line of output of this command will show the actual value of gain used.
sudo systemctl status dump1090-mutability -l
.
You can also check current gain by following command
cat /etc/default/dump1090-mutability
.
.
CLICK ON IMAGE TO SEE LARGER SIZE