I’m trying to send MAVLink commands from my application to SITL “Sim_Vehicly.py” to test my code. As a start I’m trying to send a “Takeoff to height 20” command. My code can send UDP packets to “127.0.0.1:14551”. There is something wrong with my code as MAVProxy doesn’t receive the message. I hope if anyone can tell me where the problem is. When I run sudo tcpdump -i lo -n udp port 14551
the output is 18:42:46.734776 IP 127.0.0.1.39634 > 127.0.0.1.14551: UDP, length 41
Here is the code:
Are you armed? You can only takeoff after being armed. Also, why are you sending it to target component 214 instead of 1? That may be why MAVProxy isn’t forwarding the packet.
Hi Francisco,
Many thanks for your reply.
I’m just trying to send any command to test if I can communicate successfully with MAVProxy, therefore I tried the TakeOff command. When I send TakeOff 20 command from MAVProxy terminal, The console outputs Got MAVLink msg: COMMAND_ACK {command : 22, result : 4}. Yes it doesn’t takeoff because it is not armed but it receives the command successfully which is not the case with my application.
After what you suggested, I set target component id to 1 but still not working.
I think the problem is not with the packet itself. I think the problem is with the connection. I think my program should listen to port 14551 and communicate with whatever writes to this port. But in my case, 18:42:46.734776 IP 127.0.0.1.39634 > 127.0.0.1.14551: UDP, length 41, which doesn’t look right, right?
I don’t know Boost very well, but looking at your code again, it looks like you are doing an UDP client connecting to remote port 14551 - you actually need to do the opposite, an UDP server receiving on local port 14551, then you send packets to the port you receive from.
You can also make MAVProxy have an UDP server you can send messages to by passing the following argument to sim_vehicle.py: --out udpin:127.0.0.1:14552. You can choose another port if you want to.
@OXINARF, Wow, the second suggestion worked for me. Finally. I don’t know how can I thank you
MAVProxy being UDP server and my program is the client will function the same as the opposite, right? I mean nothing will change?