Skip to content

Instantly share code, notes, and snippets.

@maatthc
Last active May 9, 2022 07:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maatthc/30a7498e6e76c46a0206e0b1e8d753dc to your computer and use it in GitHub Desktop.
Save maatthc/30a7498e6e76c46a0206e0b1e8d753dc to your computer and use it in GitHub Desktop.
To connect to Eachine EX4 using Qgroundcontrol/MAVlink running on a computer, first run this script.
import socket
from time import sleep
DRONE_IP = '172.50.10.1'
DRONE_BOND_PORT = 4646
RESET_CMD=b'{"CMD":0,"PARAM":-1}\n'
BOND_CMD=b'{"CMD":89,"PARAM":1}\n'
EXPECTED_SERVER_RESPONSE = '{ "CMD": 89, "PARAM": -1, "RESULT": 1 }'
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = (DRONE_IP,DRONE_BOND_PORT)
sock.connect(server_address)
try:
sock.send(RESET_CMD)
print('1. Received from server: ', sock.recv(5000).decode())
sleep(1)
sock.send(BOND_CMD)
print('2. Received from server: ', sock.recv(5000).decode())
sleep(2)
result = sock.recv(5000).decode()
print('3. Received from server: ', result)
if result == EXPECTED_SERVER_RESPONSE:
print('IP address bond success!')
else:
print('IP address bond failed!')
finally:
print('Closing socket ..')
sock.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment