Skip to content

Instantly share code, notes, and snippets.

@LouWii LouWii/enable_telnet.md
Last active Dec 7, 2016

Embed
What would you like to do?
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 (note: it's the file in this gist), 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

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

Here is what I did on the DRONE-side using a WINDOWS system:

  • Turn on the Remote Control
  • Turn on the Drone
  • Connect your Windows device to the WiFi signal of the Remote Control
  • Open a Windows command prompt (Start -> Run -> "cmd")
  • Make note of the current directory for your Command Prompt window. It is typically set to C:\Users\<your username>.
  • Type in ftp 192.168.1.2 followed by Enter
  • Type in user name root followed by Enter
  • Type in password Big~9China followed by Enter
  • You should see a "230 Login successful." response
  • Type in cd /etc/init.d/ followed by Enter
  • You should see a "250 Directory successfully changed." response
  • Type in type binary followed by Enter
  • You should see a "200 Switching to Binary mode." response
  • Type in get rcS followed by Enter. Note that the S is a capital S...
  • The rcS file will be downloaded into the current directory for your Command Prompt window (see step 5)

Now we start editing the file on your Windows device...

  • Start the Notepad++ editor and open the rcS file Note:Do NOT use the Windows Notepad editor (!)

  • In Notepad++, using the menu structure at the top of the screen, verify that the file encoding is set to "Encode in UTF-8" (Encoding -> "Encode in UTF-8"). This should already be selected but it does not hurt to verify...

  • Scroll down to line 61 and change it: From: #telnetd -l /bin/ash & To: telnetd -l /bin/ash & So you remove the #-character from the beginning of the line

  • Now ADD the following lines to the end of the file: iw reg set US iw dev wlan0 set tx power limit 2700

  • Now save the file and close Notepad++

Now you need to upload the modified file to your drone...

  • Back in your FTP-session... Type in "put rcS" You should see a "226 Transfer complete" response
  • Terminate your FTP session: Type in "bye" followed by Enter You should see a "221 Goodbye." response
  • Now restart the drone.

At this point you have modified the drone to enable telnet, set the region to US to enable FCC mode and you have configured the WiFi driver to use a maximum transmit power of 27dbm.

When the drone is back online, you can use telnet to connect to the drone. I recommend using Putty. When you have established a telnet session to the drone at IP address 192.168.1.2 you can use the command "iwinfo" to see the active WiFi parameters. Look for the line that starts with "Tx-Power:"

Now, if your drone does not come online anymore you may have made a typo whilst modifying the rcS file. So be careful.

I hope this helps.

#!/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
You can’t perform that action at this time.