how to use a Phantom 3 remote control as a game controller for Mac/Windows - Page 1
Forum section: electronics / projects

author: FrankBuss
author_rank: Unknown
timestamp: March 19, 2016, 03:55:50 pm
content: What do you do if it is raining outside and you can't fly your new copter? Of course you are using the a simulatorBut the simulator which is integrated in the DJI Go smartphone app requires that you turn on the copter and it's not that great on the small screen. This was the reason I tried to use the remote control for my PC or Mac to use more professional simulators.I have the Phantom 3 Standard, with the remote control GL358wA, which connects over WiFi to the smartphone (the remote control creates a WiFi hotspot to which the smartphone connects) instead of using an USB connection like with other DJI models. But there is still an USB port and if I connect it to my Windows PC, it gets enumerated as a serial port. Unfortunately I couldn't find any documentation how to use it, and so far no answer from theDJI dev forum. So I tried to do something with the WiFi network.Turns out there is an open port 2345, which sends the stick positions and I can read it with a simple Python script. WithfoohidI can simulate a gamepad in Python and that's all I need to use it in a flight simulator likeHeli-X, which has a Phantom copter as a model in the free version. Now I can practice flying drones and helicopters with my Mac.Video how I found and hacked the protocol, and how it works:Python source code:Code:import socketimport foohidimport structjoypad = (0x05, 0x01, 0x09, 0x05, 0xa1, 0x01, 0xa1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x10,0x15, 0x00, 0x25, 0x01, 0x95, 0x10, 0x75, 0x01, 0x81, 0x02, 0x05, 0x01, 0x09, 0x30,0x09, 0x31, 0x09, 0x32, 0x09, 0x33, 0x15, 0x81, 0x25, 0x7f, 0x75, 0x08, 0x95, 0x04,0x81, 0x02, 0xc0, 0xc0)try:foohid.destroy("FooHID simple joypad")except:passfoohid.create("FooHID simple joypad", struct.pack('{0}B'.format(len(joypad)), *joypad))s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)s.connect(("192.168.1.1", 2345))def word(b0, b1):return (b0 << 8) | b1def conv(w):return (w / 8 - 128) & 0xffwhile True:data = bytearray(s.recv(1024))# print(' '.join("%02x" % x for x in data))if len(data) == 26:rightX = word(data, data)rightY = word(data, data)leftY = word(data, data)leftX = word(data, data)cam = word(data, data)foohid.send("FooHID simple joypad", struct.pack('H4B', 0,conv(rightX), conv(rightY), conv(leftX), conv(leftY)))print("leftX: %4i, leftY: %4i, rightX: %4i, rightY: %4i, cam: %4i" % (leftX, leftY, rightX, rightY, cam))I tested it on Windows with vJoy. If you have a laptop, you can connect to the Phantom remote control. On my desktop PC I used an USB WiFi dongle, like this, which you can get for less than $5 and free shipping:https://www.amazon.com/150Mbps-802-11n-Wireless-Adapter-Network/dp/B009D8DEPSIn Windows device manager it says "Realtek RTL8188ETV Wireless LAN 802.11n USB 2.0 Network Adapter". Works in Windows 10 without additional driver installation. Then you can see the remote control with the network icon in the task bar and you can connect to it:Note, you should really change the default WiFi password with the mobile phone DJI Go app.Click "yes" to the next question Windows asks. In a DOS prompt you can check the connection with "ipconfig", it should show something like this and the numbers should change when you move the sticks:Code:Drahtlos-LAN-Adapter WLAN:Verbindungsspezifisches DNS-Suffix: localVerbindungslokale IPv6-Adresse . : xxxx::xx:xxxx:xxxx:xxxx%12IPv4-Adresse . . . . . . . . . . : 192.168.1.20Subnetzmaske . . . . . . . . . . : 255.255.255.0Standardgateway . . . . . . . . . :Note: this might not work, if your primary network adapter starts with 192.168.1.*, you have to change this first to something like 192.168.2.*.You can check if the remote sends data by "telnet 192.168.1.1 2345" from a DOS command prompt (you might need to install the telnet client first with the standard Windows applications). If this looks like this, and new garbage characters are written all the time, the connection to your remote works:Next install Python 3. Then use this script to test if the stick positions can be read:Code:import socketimport structs = socket.socket(socket.AF_INET, socket.SOCK_STREAM)s.connect(("192.168.1.1", 2345))def word(b0, b1):return (b0 << 8) | b1def conv(w):return (w / 8 - 128) & 0xffwhile True:data = bytearray(s.recv(1024))if len(data) == 26:rightX = word(data, data)rightY = word(data, data)leftY = word(data, data)leftX = word(data, data)cam = word(data, data)print("leftX: %4i, leftY: %4i, rightX: %4i, rightY: %4i, cam: %4i" % (leftX, leftY, rightX, rightY, cam))Save it as remote.py and start it from a DOS prompt with "python remote.py". It should show something like this:Next donwload and install the vJoySetup.exe driver, I used this version:https://sourceforge.net/projects/vjoystick/files/Beta%202.x/2.1.8.33-110117/For using vJoy with Python, I found a forum post:http://vjoystick.sourceforge.net/joomla256.02/index.php/forum/4-Help/1044-getting-started-with-python. It is really easy to simulate a joystick from a Python script, I added this to my remote.py program:Code:import socketfrom ctypes import *# init vJoyvjoy = CDLL('C:\\Program Files\\vJoy\\x86\\vJoyInterface.dll')vjoy.AcquireVJD(1)vjoy.ResetVJD(1)# connect to remotes = socket.socket(socket.AF_INET, socket.SOCK_STREAM)s.connect(("192.168.1.1", 2345))# some helper functionsdef word(b0, b1):return (b0 << 8) | b1def conv(w):return (w / 8 - 128) & 0xffdef scale(x):return int((x - 364) / 1320 * 32768)# read data from the remote and set the axis in vJoywhile True:data = bytearray(s.recv(1024))if len(data) == 26:rightX = word(data, data)rightY = word(data, data)leftY = word(data, data)leftX = word(data, data)cam = word(data, data)print("leftX: %4i, leftY: %4i, rightX: %4i, rightY: %4i, cam: %4i" % (leftX, leftY, rightX, rightY, cam))vjoy.SetAxis(scale(leftX), 1, 48)vjoy.SetAxis(scale(leftY), 1, 49)vjoy.SetAxis(scale(rightX), 1, 50)vjoy.SetAxis(scale(rightY), 1, 51)Start the script with "python remote.py" from a command prompt, and then you can use the Phantom remote control as a joystick. If you have multiple joysticks connected to your system, configure the vJoy joystick for your game, e.g. heli-x:http://www.heli-x.info/cms/download-2/This game crashes on my system, looks like some problems with the OpenGL driver, but the joystick works. You can test it e.g. with the vJoy monitor program:C:\Program Files\vJoy\x64\JoyMonitor.exeAnother nice quadcopter simulator is FPV Freerider:https://fpv-freerider.itch.ioWorks with no problems in Linux with my Taranis remote, should work in Windows, too, with the vJoy driver and the Phantom remote control.

author: onehunkytenor
author_rank: Newbie
timestamp: January 12, 2017, 11:58:57 pm
content: Hi Frank, would you mind contacting me by email to discuss this project and a couple of ideas I have? You *should* be able to do so via my profile page.Thanks!-Shawn

author: FrankBuss
author_rank: Unknown
timestamp: January 13, 2017, 01:38:25 am
content: Quote from: onehunkytenor on January 12, 2017, 11:58:57 pmAny reason you don't want to discuss it here? PM here works, too, I got your PM. And yes, I have a minute (well, tomorrow, I should already sleeping by now), feel free to write more.I really don't like these messages where you ask if it is ok to write more messages, just ask or tell me what you want to tell me.

author: DaJMasta
author_rank: Super Contributor
timestamp: January 13, 2017, 07:12:52 am
content: But then how would you know if it were ok?!Anyways, looks neat! I would have figured they wouldn't have used wifi for the primary controls because of potential range constraints, and instead of just stuck with it for the higher bandwidth camera stuff. Is it just that the range is that much better when there are no pesky walls in the way, or are they using some sort of boosted antenna to get good range out of it?

author: onehunkytenor
author_rank: Newbie
timestamp: January 15, 2017, 02:17:15 am
content: Thanks, Frank!Looking forward to having some time tomorrow to give it a shot. I'll let you know how it goes-Shawn

author: amyk
author_rank: Super Contributor
timestamp: January 15, 2017, 04:01:25 am
content: "Flugzeug-modus" - literally!

author: Cyril.Anthony
author_rank: Contributor
timestamp: January 17, 2017, 12:15:28 pm
content: Awesome work Frank

author: shaiken
author_rank: Newbie
timestamp: July 25, 2017, 02:45:11 am
content: is that could get data(Image or otherwise) from remote controller by aircraft DJI P3S ?

author: FrankBuss
author_rank: Unknown
timestamp: July 25, 2017, 03:28:07 pm
content: Quote from: shaiken on July 25, 2017, 02:45:11 amI don't think you can get data from the copter with this method. But there is an API to write your own application, which then can do anything you want, like recording the video and controlling the copter:http://developer.dji.comOf course, much more work than my simple hack.

author: shaiken
author_rank: Newbie
timestamp: July 26, 2017, 06:28:23 am
content: hi, i'm noob...my copter type is P3Pthat's no SDK for PC(Wins), so i could not got image and data... right?but i really need a method to get data form remote controller to PC...

author: FrankBuss
author_rank: Unknown
timestamp: July 26, 2017, 01:05:27 pm
content: Right, I think the SDK is for smartphones. So you might need to learn how to write programs for smartphones, first.

author: diwali
author_rank: Newbie
timestamp: February 26, 2018, 02:04:08 pm
content: Hello Frank,I know I'm very late...Sorry for that.I wish so much I could make your hack work for my Phantom 3 SE.Unfortunately I keep disconnected after a few second even in Telnet.I'm working on Windows 10.https://www.dropbox.com/s/5flyt4j1d1f9j6d/Capture.PNG?dl=0Any idea? Thank you

author: FrankBuss
author_rank: Unknown
timestamp: February 26, 2018, 09:05:26 pm
content: No idea.

author: diwali
author_rank: Newbie
timestamp: February 26, 2018, 09:12:55 pm
content: Thank you anyway for your reply.I'll keep trying.

author: Tedztar
author_rank: Newbie
timestamp: February 11, 2019, 04:27:01 am
content: Hey I know this is an old project, it is really cool and useful. Did you ever manage to get the buttons on the controller working with a sim, or did you never work on that?

author: FrankBuss
author_rank: Unknown
timestamp: February 11, 2019, 09:09:53 am
content: There are no buttons on the Phantom 3 remote control. But maybe it is possible to map the two switches as well, but I didn't try it.

author: Tedztar
author_rank: Newbie
timestamp: February 12, 2019, 03:19:52 am
content: Ok, I realised it is the phantom 3 pro controller that has the buttons