This is an experiment, mainly of academic interest.
.
.
It started when forum member @evangelyul added a Gains drop-down menu to the table at right of SkyView map. He then contacted me to find out what code will be required to change the gain setting in Pi. At first it looked simple, as in the < select > dropdown, the selected values can be passed by javascript command <select onChange="function();" />
.
However when I tried, it did not work. After some Google Search I discovered that javascript works on the same computer on which the browser is located. Here the situation is different. The browser is located on Client (Windows/Mac) whereas the command is required to be executed on Server (RPi). This is possible with PHP or AJAX, but not with javascript.
As I have very little knowledge of PHP, and Zero knowledge of Ajax, I apologized to @evangelyul that I cannot help him.
This weekend I had some spare time, and after lot of Googling could workout a solution.
The solution comprises of:
-
PHP code snippets to pass the commands from Client (Win/Mac computer) to Server (RPi).
-
Adding required packages and modules to enable Pi to handle PHP pages.
-
Commands sent from Client (Win/Mac) to Server (RPI), failed to execute with âNot Permittedâ response . I found that the commands from Client browser are treated as from user
www-data
which for security reasons does not havesudo
powers. I then assigned a strong password to userwww-data
, and then added it tosudoers
group. Now the commands started executing.
.
Here is the step-bystep method
This post is for Piaware SD Card image.
For Raspbian Jessie/Stretch + dump1090-mutability package install, click here
For Raspbian Jessie/Stretch + dump1090-fa package install, click here
.
STEP-1: Install necessary php packages and enable module
sudo apt-get update
sudo apt-get install php5-cgi
sudo lighty-enable-mod fastcgi-php
sudo /etc/init.d/lighttpd force-reload
.
STEP-2: Assign strong password to user www-data, and add it to sudoerâs group
sudo passwd www-data
sudo adduser www-data sudo
groups www-data
.
REBOOT for sudo permission of user www-data to be implemented.
sudo reboot
STEP-3: Create new directory and files
(a) Create new directory
sudo mkdir /var/www/html/setgain
(b) Move inside the new directory
cd /var/www/html/setgain/
(c ) Inside directory /var/www/html/setgain, create a new blank file setgain.sh, make it executable
sudo touch setgain.sh
sudo chmod +x setgain.sh
(d) Open newly created file in nano editor
sudo nano setgain.sh
(e) Add code to the new file
(In code below, replace xxxxxxxxx by the actual password you have set for user www-data)
#!/bin/bash
echo 'xxxxxxxxxxx' | sudo -S piaware-config rtlsdr-gain "$1"
echo 'xxxxxxxxxxx' | sudo -S systemctl restart dump1090-fa
Save (Ctrl+o) and Close (Ctrl+x) the file.
.
(f) Inside directory /var/www/html/setgain, create a new blank file findgain.sh, make it executable
sudo touch findgain.sh
sudo chmod +x findgain.sh
(g) Open newly created file in nano editor
sudo nano findgain.sh
(h) Add code to the new file
(In code below, replace xxxxxxxxx by the actual password you have set for user www-data)
#!/bin/bash
echo 'xxxxxxxxxxx' | sudo -S piaware-config -show rtlsdr-gain
Save (Ctrl+o) and Close (Ctrl+x) the file.
.
(i) Inside directory /var/www/html/setgain, create new php file
sudo nano index.php
(j) Copy-paste following code in it
<?php
echo <<<HTML
<form id="myform" name="myform" action="{$_SERVER['PHP_SELF']}" method="post" />
ENTER GAIN VALUE: <input type="text" id="gain" name="gain" value="-10" />
<input type="submit" name="submit" value="Click to Set Gain" />
</form>
HTML;
echo "Your gain was = ";
system("/var/www/html/setgain/findgain.sh");
?>
<BR>
<?php
function setgain(){
$_SERVER['PHP_SELF'];
$gain="{$_POST['gain']}";
echo "You changed gain to = $gain";
system("/var/www/html/setgain/setgain.sh $gain >> /tmp/gain.log 2>&1");
}
if ("{$_POST['gain']}"){
setgain();
}
?>
.
Save (Ctrl+o) and close (Ctrl+x)
.
STEP-4: Load the gain setting file in browser of Win/Mac computer, and set gain.
IP-OF-PI/setgain/
STEP-5: Check if the gain change has actually taken place
piaware-config -show rtlsdr-gain
sudo systemctl status dump1090-fa -l
#Check log for any error messages
cat /tmp/gain.log