Skip to content

Instantly share code, notes, and snippets.

@LouWii
Last active December 7, 2016 03:55
Show Gist options
  • Select an option

  • Save LouWii/8e1b42db76388fe2c1dd772a749ad47c to your computer and use it in GitHub Desktop.

Select an option

Save LouWii/8e1b42db76388fe2c1dd772a749ad47c to your computer and use it in GitHub Desktop.
Scan environment and set the best channel possible on your DJI Phantom 3 Standard controller and drone (requires telnet enabled)

Content from http://www.phantompilots.com/threads/phantom-3-standard-range-mod-lets-do-it-together.80721/page-15#post-840050

To avoid more and more user brick the RC/Drone, I discover a new solution to do this mod:

1) connect RC/Drone

2) ftp to 192.168.1.1

3) get /sbin/djiled.sh to PC

4) open it by notepad++ / gedit / vi

5) add telnetd -l /bin/ash & at line 2, you must add at line2 before the while loop started

6) put djiled.sh back to RC, make sure file mode = 775 (rwx rwx r_x)

7) repeat step 3-6 at 192.168.1.2

8) make sure nothing wrong then reboot

by adding telnetd -l /bin/ash to djiled.sh, telnet will start when system boot, so we can use telnet to access rc/drone without touching the important file "rcS". If u make anything wrong in djiled.sh, the wifi still can startup and u can do it again until success (well, that's what I guess, i dont want to try...)

For step 9-14, if your rc/drone are using fcc mode as default, then you can skip it, dont touch the rcS file. Use my "channel 13 mod" script at post#266, it will do 27dbm mod for you. so rcS remain as DJI original one make no chance to brick ! For more detail about "channel 13 mod", take a look at post#199-200 you can type "iw reg get" to check you are in fcc or ce

9) telnet to 192.168.1.2 (yes, patch drone side first)

10) run following command 1 by 1 to patch the rcS, it will make a copy, patch FCC mode, set open channel 1-13 and 27dbm

cp /etc/init.d/rcS /etc/init.d/rcS.bck
sed -i 's/GB/OK/g' /etc/init.d/rcS
echo "iw reg set BO" >>/etc/init.d/rcS
echo "iw dev wlan0 set txpower limit 2700" >>/etc/init.d/rcS

PS: you can vi /etc/init.d/rcS to edit by yourself too, don't try if you ask what is vi

11) cat /etc/init.d/rcS

make sure only new content is added (no diff installed, so you have to check file by yourself)

12) ls -ltr /etc/init.d/rcS

make sure it have execute mode (rwx rwx r_x)

13) repeat step 10 to 12 @192.168.1.1

14) correct me if any step is wrong or missing, then reboot rc + drone

patch the rcS by telnet at RC/Drone can avoid incorrect EOL format and file changed to non-executable accidentally

in addition, you can use "channel 13 mod" at post#266, just download and save setchan.sh at /usr/sbin (192.168.1.1 only) then run, default will auto select best channel from 1 to 13 for you. You can execute as "setchan.sh 13" to force it to use channel 13 (1 to 13)

---------not suggest to auto start, because need to modify rcS file, u can simply telnet to 192.168.1.1 on your phone and run setchan.sh manually ---------

if you want to make setchan.sh autorun when boot, use following command at 192.168.1.1

echo "sleep 30" >>/etc/init.d/rcS
echo "setchan.sh" >>/etc/init.d/rcS

or, if you want to use channel 13 only

echo "sleep 30" >>/etc/init.d/rcS
echo "setchan.sh 13" >>/etc/init.d/rcS
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment