Mavlink data to text or CSV file

Is there any other way of receiving the MAVLINK data when parameters (other than NetID) are different.

No, there are not. It is just not possible, if each modem is using a different language they will not understand each other.

ALL need to have at least the same:

  • Number of Channels
  • Air Speed
  • Seed
  • NetID
  • Min Freq
  • Max Freq
  • Max Window

other than the above parameters , Min Freq, Max Freq, Max Window also need to be same for both modules for receiving the MAVLINK data even though NetID’s are same right?

I edited the post above.

Thank You, If i have any doubts I will message in this forum. Please help

what are the changes made in the above code? i am not able to find any changes

There are no changes, it is just the code you posted, but with ` characters in the beginning and end

Code is correct only right
Sometimes I am getting OK response and sometimes i am not getting OK response

No, I did not look at the code, nor did anyone else. And now you deleted it ! ??

Why?

I will send the modified code of which i sent and deleted before
Actually I modified the original Sikset.py code

current_version = “v0.0.8”
import serial, time
from optparse import OptionParser
import chardet
from pymavlink import mavutil

serial_speeds = {2400: 2, 4800: 4, 9600: 9, 19200: 19, 38400: 38, 57600: 57, 115200: 115}
air_speeds = (4, 8, 16, 24, 32, 64, 96, 128, 192, 250)
netids = range(1,256)
txpowers = range(1,31)
default_serial_port = “COM9”

parser = OptionParser(usage=“%prog [-p port_filepath] [-b baud]”, version=“%prog " + current_version)
#parser.add_option(”-v", “–verbose”, action=“store_true”, dest=“verbose”, help=“Enables extra information output (debugging).”, default=“False”)
parser.add_option(“-p”, “–port”, action=“store”, type=“string”, dest=“port”, help=“Serial port filepath. Default: %s” % default_serial_port, default=default_serial_port)
parser.add_option(“-l”, “–local”, action=“store_true”, dest=“local_radio”, help=“Work with the local radio. Default. Can’t be used simultaneously with remote option.”, default=True)
parser.add_option(“-r”, “–remote”, action=“store_false”, dest=“local_radio”, help=“Work with the remote radio.”)
parser.add_option(“-b”, “–baud”, action=“store”, type=“int”, dest=“baud”, help=“Speed in baud (SERIAL_SPEED). Valid speeds: %s. If no baud specified, it will test.” % (serial_speeds.keys()) + “. (factory default: 57)”, default=“57600”)
parser.add_option(“–adr”, action=“store”, type=“int”, dest=“adr”, help=“Set the air data rate (AIR_SPEED) in kbps. Valid speeds: " + ', '.join(map(str, air_speeds)) + “. (factory default: 128)”, default=None)
parser.add_option(”–netid", action=“store”, type=“int”, dest=“netid”,default = 25, help=“Network ID number (NETID). Valid IDs: 0 to 499 (factory default: 25)”,)

(options,args) = parser.parse_args()

serial port connection
ser = serial.Serial(default_serial_port,baudrate=57600,timeout=1)
print(f"Serial Port is : {ser.portstr}")

#Getting response
#def get_response(ser):

“”“Gets a response from the serial port and decodes it.”“”

response = b’’

ser.flushOutput()

#ser.flushOutput()

time.sleep(0.1) # Add a short delay before reading

while ser.inWaiting() > 0:

response += ser.readline()

result = chardet.detect(response)

encoding = result[‘encoding’] if result[‘confidence’] > 0.9 else ‘latin-1’

response = response.decode(encoding)

time.sleep(1)

#print(“Full response:”, response) # Print the entire response

return response

def get_response(ser):
“”“Gets a response from the serial port and decodes it.”“”
sleep_time_after_buffer_read = 2
inBuffer = ser.inWaiting()
#vprint(“Characters in receive buffer before reading:”, inBuffer)
response = ser.readline(inBuffer)
# Detect encoding using chardet
result = chardet.detect(response)
encoding = result[‘encoding’] if result[‘confidence’] > 0.9 else ‘latin-1’
response = ser.readline(inBuffer).decode(encoding)
#time.sleep(1)
#print(“Full response:”, response) # Print the entire response
return response

if options.local_radio is True:
command_prefix = “AT”
else:
command_prefix = “RT”

def command_mode():
ser.flushOutput()
ser.flushInput()
print(“Entering into the Command mode”)
time.sleep(1)

#command = command_prefix.encode() + b"O\r\n"
#ser.write(command)
#print(f"Sent Command : {command}")
#time.sleep(1)

command = b"+++"
ser.write(command)
time.sleep(1)
print(f"Sent Command : {command}")

print(f"Serial port speed set to {ser.baudrate} baud.“)
print(f"Serial Port settings :\n\n {ser}”)
#ser.open()
print(f"Serial port {ser.portstr} opened.")

command_mode()

#Setting the Air data rate
if options.adr != None:
if options.adr in air_speeds:
print(f"Setting AIR DATA RATE to {options.adr}kbit/s.“)
command = command_prefix.encode() + b"S2=%d\r\n” % (options.adr,)
print(f"Sending command: {command}“)
ser.write(command)
time.sleep(1)
response = get_response(ser)
if “OK” in response: # More lenient check for OK in response
print(“Air Data Rate set successfully.”)
else:
print(f"Setting Air Data Rate failed. Response:, {response}”)
exit(106)

#Setting the NetID
if options.netid is not None:
if options.netid in netids:
ser.flushInput()
print(f"Setting network ID (NETID) to {options.netid}.“)
command = command_prefix.encode() + b"S3=%d\r\n” % (options.netid,)
print(f"Sending command: {command}“)
ser.write(command)
time.sleep(1) # Short delay after writing the command
response = get_response(ser)
print(“Response after setting NETID:”, response)
if “OK” in response: # More lenient check for OK in response
print(“NETID set successfully.”)
else:
print(f"Setting NETID failed. Response: {response}”)
exit(106)

command = “%s&W” %(command_prefix)
print(f"Sending command: {command}“)
ser.write(command.encode()+b”\r\n")
time.sleep(1)
response = get_response(ser)

#time.sleep(1)
def trans_radio():
time.sleep(1)
command = b"RTS3?\r\n"
ser.write(command)
print(f"Sending command: {command.decode()}")
time.sleep(1)
response = get_response(ser)
return response

#time.sleep(1)
def recv_radio():
command = command_prefix.encode() + b"S3?\r\n"
ser.write(command)
print("Sending command: ", command.decode())
time.sleep(2) # Short delay after writing the command
response = get_response(ser)
return response

time.sleep(2)
p = recv_radio()
print(“Receiver’s NetID:”,p)
time.sleep(1)

#command_mode()

Send RTS3? command immediately after ATZ for rebooting

time.sleep(1) # Wait for reboot to complete
#print(“\n”)
q = trans_radio()
print(“Transmitter NetID:”, q)

After setting the receiver’s NetID to 25 and sending ATZ command for rebooting

command = “%sZ” % (command_prefix)
print(f"Sending command : {command}“)
ser.write(command.encode() + b”\r\n")

#time.sleep(2)
#print(“\n”)
command = “%sO” %(command_prefix)
print(f"Sending Command : {command}“)
ser.write(command.encode()+b”\r\n")

#ser.close()
if q.strip() == p.strip():
print(“NetID of Receiver matches with the NetID of Transmitter”)
ser.close()
mav_connection = mavutil.mavlink_connection(‘COM9’, baud=57600)
for _ in range(2):
msg = mav_connection.recv_match(type=‘GLOBAL_POSITION_INT’, blocking=True)
#msg.pack(mav)
b = msg.get_msgbuf()
if msg is not None:
# # Extract GPS coordinates from the message
latitude = msg.lat / 1.0e7 # Convert from degrees * 1.0e7 to degrees
longitude = msg.lon / 1.0e7
altitude = msg.alt / 1000.0 # Convert from millimeters to meters
# # Print the coordinates
print(“latitude:”,latitude,“longitude:”,longitude,“Altitude:”,altitude)
# print(f"Latitude : {latitude}, Longitude : {longitude}, Altitude : {altitude}")
print(msg)
f = open(‘sample_4_netid.txt’,‘a’)
f.write(str(msg))
f.write(b.hex())
print(b.hex())
else:
print(“NetID of Receiver does not match with the NetID of Transmitter”)

close the serial port

ser.close()
print(f"Serial port {ser.portstr}, closed.")

how to get the details of all the WiFi networks and WiFi based drones through Linux commands or Python Script? If possible send me the linux commands based on the above

import subprocess

Run the command to retrieve information about all available Wi-Fi networks

devices = subprocess.check_output([‘netsh’, ‘wlan’, ‘show’, ‘network’,‘mode=Bssid’])

Decode the output from bytes to a string

devices = devices.decode(‘ascii’)

Remove carriage return characters

devices = devices.replace(“\r”, “”)

Print the information about all available Wi-Fi networks

print(devices)