dronefleet/mavlink

Connect Demo for mav_server

elinxer opened this issue · 5 comments

i try to connect mav_server on 127.0.0.1:50051 tcp,on the mavsdk is done, but this code is error:

       // This example uses a TCP socket, however we may also use a UDP socket by injecting
        // PipedInputStream/PipedOutputStream to MavlinkConnection, or even USB by using any
        // implementation that will eventually yield an InputStream and an OutputStream.
        try (Socket socket = new Socket("127.0.0.1", 50051)) {
            // After establishing a connection, we proceed to building a MavlinkConnection instance.
            MavlinkConnection connection = MavlinkConnection.create(
                    socket.getInputStream(),
                    socket.getOutputStream());

            System.out.println(socket.toString());

            int systemId = 255;
            int componentId = 0;
            Heartbeat heartbeat = Heartbeat.builder()
                    .type(MavType.MAV_TYPE_GCS)
                    .autopilot(MavAutopilot.MAV_AUTOPILOT_INVALID)
                    .systemStatus(MavState.MAV_STATE_UNINIT)
                    .mavlinkVersion(3)
                    .build();

            // Write an unsigned heartbeat
            connection.send2(systemId, componentId, heartbeat);

            MavlinkMessage message;
            while ((message = connection.next()) != null) {
                Object p = message.getRawBytes();
                System.out.println(p);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

Error:

:processResources UP-TO-DATE
:classes
:testMainTcpPx4.main()
Socket[addr=/127.0.0.1,port=50051,localport=61393]
java.io.EOFException: End of stream
	at io.dronefleet.mavlink.protocol.MavlinkPacketReader.next(MavlinkPacketReader.java:47)
	at io.dronefleet.mavlink.MavlinkConnection.next(MavlinkConnection.java:238)
	at px4.testMainTcpPx4.main(testMainTcpPx4.java:49)

BUILD SUCCESSFUL

Total time: 9.917 secs
17:59:09: Task execution finished ':testMainTcpPx4.main()'.

i use px4 mav:

sudo docker run --rm -it jonasvautherin/px4-gazebo-headless 10.9.127.54 10.9.127.54

the 50051 port is nornal:

image

i need help or somebody can leave a demo for it.

@benbarkay hello,can you help me or Just give me an idea,or just demo will okk

tks ben, but the docker container port is 14540,14550 etc, that is exisit and open. Is there a demo you can give me. 0.0

@elinxer did you able to connect?

@elinxer I figure the problem
I using mavproxy to check communication and heart beat.
you need to set in MAVprxy you need tcpIn : 127.0.0.1:14550, and connect to that, then you will able to see heartBeat