|
#!/bin/sh |
|
# I'm not the author ! -> |
|
# SCRIPT FROM http://www.phantompilots.com/threads/phantom-3-standard-range-mod-lets-do-it-together.80721/page-25#post-855473 |
|
#Auto scan and set unused Wifi channel for Phantom 3 Standard / 4K |
|
#Author : Gary Kan |
|
#Date : 20/06/2016 |
|
#Version 1.1 |
|
# 1) Add new user argument option |
|
# -ch for set channel number, eg. -ch 13 |
|
# -booster will limit RC tx power to 20DBM, to protect your external booster |
|
# 2) Add Restart udhcp and apsvr |
|
# 3) Some Minor tweak |
|
# |
|
#Date : 21/06/2016 |
|
#Version 1.2 |
|
# 1) Remove user argument option -booster |
|
# 2) Remove apsvr due to my RC video link sometime get disconnected |
|
# 4) Change Default DBM from 27dbm to 24 dbm on RC and drone, due to user report his RC is bricked despite of successful application of 27dbm setting, after fifth flight. |
|
# 3) Add new user argument option |
|
# -rc will limit RC tx power to your target mbm, eg -rc 2000 = 20DBm, Max = 2700 |
|
# -d will limit DRONE tx power to your target mbm, eg -d 2000 = 20DBm, Max = 2700 |
|
# |
|
#Version 1.21 |
|
#Date : 21/06/2016 |
|
# 1) Add User changable default dbm |
|
|
|
clear |
|
DRONE="192.168.1.2" |
|
SCRIPT=`basename "$0"` |
|
RCDBM="2400" |
|
DDBM="2700" |
|
|
|
|
|
###For check User argument |
|
while [ "$1" != "" ]; do |
|
case $1 in |
|
-ch) |
|
shift |
|
SCAN="OFF" |
|
CHANNEL=$1 |
|
;; |
|
-rc) |
|
shift |
|
RCDBM=$1 |
|
echo "Info : User Limit RC TX Power to $1" |
|
;; |
|
-d) |
|
shift |
|
DDBM=$1 |
|
echo "Info : User Limit Drone TX Power to $1" |
|
;; |
|
-h) |
|
echo "-ch for set channel number, eg. -ch 13" |
|
echo "-rc will limit RC tx power to your target mbm, eg -rc 2000 = 20DBm, Option = 1700 2000 2400 2700" |
|
echo "-d will limit DRONE tx power to your target mbm, eg -d 2000 = 20DBm, Option = 1700 2000 2400 2700" |
|
echo "-h for show this page" |
|
exit |
|
;; |
|
* ) |
|
echo "Incorrect user argument !!" |
|
echo "-ch for set channel number, eg. -ch 13" |
|
echo "-rc will limit RC tx power to your target mbm, eg -rc 2000 = 20DBm, Option = 1700 2000 2400 2700" |
|
echo "-d will limit DRONE tx power to your target mbm, eg -d 2000 = 20DBm, Option = 1700 2000 2400 2700" |
|
echo "-h for show this page" |
|
exit 1 |
|
;; |
|
esac |
|
shift |
|
done |
|
|
|
###Make Sure network is ready and Drone side is online |
|
echo "Checking Connection with Phantom 3 Standard / 4K . . ." |
|
ping -c 1 -w 60 $DRONE &> /dev/null |
|
if [ $? -ne 0 ] |
|
then |
|
echo "ERROR : Phantom 3 Standard / 4K at $DRONE is unreachable" |
|
exit 1 |
|
else |
|
echo "Connection - OK." |
|
fi |
|
|
|
|
|
###Check unused channel or user argument |
|
if [ "$SCAN" != "OFF" ] |
|
then |
|
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
do |
|
iw dev wlan0 scan | grep "DS Parameter set:" | awk '{FS=" "} {print $5}' | sort -n | grep -x $i &>/dev/null |
|
if [ $? -ne 0 ] |
|
then |
|
echo "Channel $i - Not In Use" |
|
echo "Set CH to $i" |
|
CH=$i |
|
break |
|
else |
|
echo "Channel $i - In Use" |
|
if [ $i = 13 ] |
|
then |
|
CH=$i |
|
fi |
|
fi |
|
done |
|
else |
|
echo "User Input Channel = $CHANNEL" |
|
case $CHANNEL in |
|
1|2|3|4|5|6|7|8|9|10|11|12|13) |
|
CH=$CHANNEL |
|
;; |
|
*) |
|
echo "Input Error : Channel must be 1 to 13 !!" |
|
exit 1 |
|
;; |
|
esac |
|
fi |
|
|
|
|
|
###Setup hostapd-phy0.conf with target channel number |
|
echo "Trying To Set Channel = $CH . . ." |
|
sed -i "/channel=/c\channel=$CH" /tmp/run/hostapd-phy0.conf |
|
echo "Patched `grep "channel" /tmp/run/hostapd-phy0.conf`" |
|
echo " " |
|
|
|
|
|
###patch drone side to BO, make sure ready for CH12,13, telnet.d must be on in rcS, scan be remove is user set country = BO in rcS at drone side |
|
echo "Checking Connection with Phantom 3 Standard / 4K . . ." |
|
ping -c 1 -w 30 $DRONE &> /dev/null |
|
if [ $? -ne 0 ] |
|
then |
|
echo "ERROR : Phantom 3 Standard / 4K at $DRONE is unreachable" |
|
exit 1 |
|
else |
|
echo "Connected . . ." |
|
echo "Patching Phantom 3 Standard / 4K at $DRONE . . ." |
|
{ sleep 1;echo "iw reg get";echo "iw reg set BO";echo "iw reg get";echo "iw dev wlan0 set txpower limit $DDBM";sleep 1;} | telnet $DRONE |
|
fi |
|
|
|
|
|
###Patch RC Side and restart network |
|
echo "" |
|
echo "Patching Phantom 3 Standard / 4K - RC . . ." |
|
iw reg set BO |
|
iw dev wlan0 set txpower limit $RCDBM |
|
sleep 1 |
|
|
|
echo "" |
|
echo "Restarting Services, it may take a moment . . ." |
|
kill -9 `ps | grep udhcpd | grep -v grep | awk '{print $1}'` |
|
sleep 3 |
|
kill -9 `cat /tmp/run/wifi-phy0.pid` |
|
sleep 3 |
|
|
|
/usr/sbin/hostapd -P /var/run/wifi-phy0.pid -B /var/run/hostapd-phy0.conf |
|
sleep 3 |
|
/usr/sbin/udhcpd -S /etc/udhcpd.conf & |
|
sleep 3 |
|
|
|
|
|
###Final Checking, can be remove |
|
echo "" |
|
echo "Listing Services . . ." |
|
ps | grep hostapd | grep -v grep |
|
ps | grep apsrv | grep -v grep |
|
ps | grep udhcpd | grep -v grep |
|
|
|
echo "" |
|
echo "Checking Final Result at $DRONE . . ." |
|
ping -c 1 -w 60 $DRONE &> /dev/null |
|
if [ $? -ne 0 ] |
|
then |
|
echo "ERROR : Phantom 3 Standard / 4K at $DRONE is unreachable" |
|
exit 1 |
|
else |
|
{ sleep 1;echo "iwinfo";sleep 1;} | telnet $DRONE |
|
echo "" |
|
echo "Checking Final Result at RC . . ." |
|
iwinfo |
|
echo "Patch Completed, Enjoy." |
|
fi |