I want to send a string from my PC to my companion computer (raspberry PI) over Pixhawk.
You can see the structure that I want to create below
PC → Telemetry → Pixhawk → Telemetry → RaspberryPI
For this purpose, I’m using the code below for listening the outputs from the telemetry.
import sys
import time
from pymavlink import mavutil
# Connect to the serial port
master = mavutil.mavlink_connection('/dev/serial0', baud=57600)
# Wait for the heartbeat message
master.wait_heartbeat()
while True:
# Get a MAVLink message
msg = master.recv_msg()
# Print the message if it is not a null message
if msg is not None:
print(msg)
# Sleep for a short amount of time
time.sleep(0.01)
But I couldn’t find a way to send the string. I couldn’t find something about it in the web except this page. But there is not much information to do the actual operation.
Can you help me out please, how can I send a string?
import time
from pymavlink import mavutil
# Connect to Pixhawk over serial port
master = mavutil.mavlink_connection('COM9', baud=57600)
# Wait for the heartbeat message to confirm the connection
master.wait_heartbeat()
# Send a status text message with severity info
text = "Hello Pixhawk".encode('utf-8')
master.mav.statustext_send(mavutil.mavlink.MAV_SEVERITY_INFO, text)
# Wait a bit to give Pixhawk time to process the message
time.sleep(1)
Then, I catch this command from my Raspberry PI with the code below. You can change the if statement with the “commandGCS:”. I add it for identifying my strings from other mavlink messages. I will add “commandGCS:” to every string I sent.
import time
from pymavlink import mavutil
# Connect to Pixhawk over serial port
master = mavutil.mavlink_connection('/dev/serial0', baud=57600)
# Wait for the heartbeat message to confirm the connection
master.wait_heartbeat()
# Receive messages from Pixhawk
while True:
msg = master.recv_msg()
if msg and msg.get_type() == "STATUSTEXT":
text = msg.text
if text.startswith("commandGCS:"):
# Process the message
print("Received command:", text)
# You can add your own logic here to handle the received message
Hope it could help to future people. Don’t forget to change the connection addresses and baudrates according to your configuration.
Sorry, I have tried the program, the receiving program can run well, but I am experiencing problems with the sending program. The data is still not sent to the pixhawk (I’ve changed the port to match my pc’s port “/dev/ttyUSB0”).