Skip to content

Connecting Visualization Client to the Server

Sterv edited this page Jun 22, 2023 · 5 revisions

Connecting the client

The DroCo (visualization application) implements the following API for connecting to the server. When implementing a custom visualization client, the server provides the below-described services. A client must connect using websockets.

Handshake

  • Send a JSON message with the following structure:

    {
       "type":"hello",
       "data":{
          "ctype":1
       }
    }

    where ctype is 1 for the visualization client (0 is for the drone).

  • Receive a JSON message with the following structure:

    {
       "type":"hello_resp",
       "data":{
          "client_id":"54a43cba",
          "rtmp_port":1935
       }
    }

    where client_id is an auto-generated unique 8-digit hex string, which the client needs to use as its unique ID in the following communication and rtmp_port is port to RTMP server.

Drone list request

  • Request:
    {
       "type":"drone_list",
       "data":null
    }
  • Response:
    {
       "type":"drone_list_resp",
       "data":[
          {
             "client_id":"53dc0001",
             "drone_name":"MavicPro",
             "serial":"12345"
          },
          {
             "client_id":"41f28cb6",
             "drone_name":"Phantom",
             "serial":"12345"
          }
       ]
    }
    where the data contains an array of drones that are currently connected to the server.

Flight data save request

Server handles two types of requests related to saving flight data - get and set. First one is request to server, which returns if saving is enabled or not.

  • Request:
    {
      "type":"flight_data_save_get",
      "data":null
    }
  • Response:
    {
      "type":"flight_data_save_get_resp",
      "data":true
    }
    where the data returns flight data save state.

Second type is used to manage flight data saving state.

  • Request:
    {
      "type":"flight_data_save_set",
      "data":false
    }
  • Response:
    {
      "type":"flight_data_save_set_resp",
      "data":null
    }

Video stream save request

Video stream save request works similarly as flight data save except video stream saving is managed for each stream individually. So drone_stream_id (client_id of streaming drone) has to be included.

  • Request:
    {
      "type":"media_record_get",
      "data":{
        "drone_stream_id":"53dc0001"
      }
    }
  • Response:
    {
      "type":"media_record_get_resp",
      "data":false
    }
    where the data returns video stream save state for specified drone.

Second type is used to manage video stream saving state.

  • Request:
    {
      "type":"media_record_set",
      "data":{
        "drone_stream_id":"53dc0001",
        "state":true
      }
    }
  • Response:
    {
      "type":"media_record_set_resp",
      "data":null
    }

Vehicle detection

Vehicle detection consists again of two types of requests - get and set, which are alike video stream requests (only message types differs). Again drone_stream_id (client_id of streaming drone) has to be included.

  • Request:
    {
      "type":"vehicle_detection_get",
      "data":{
        "drone_stream_id":"53dc0001"
      }
    }
  • Response:
    {
      "type":"vehicle_detection_get_resp",
      "data":false
    }
    where the data returns vehicle detection state for specified drone.

Second type is used to manage vehicle detection state.

  • Request:
    {
      "type":"vehicle_detection_set",
      "data":{
        "drone_stream_id":"53dc0001",
        "state":true
      }
    }
  • Response:
    {
      "type":"vehicle_detection_set_resp",
      "data":null
    }

Client, which requested server to detect vehicles, periodically receives vehicle detection result in following format:

{
  "type":"vehicle_detection_rects",
  "data":{
      "client_id":"53dc0001",
      "rects":[
          { "x": 40.5, "y": 20.3, "w": 80, "h": 90 },
          { "x": 202.8, "y": 80.9, "w": 20, "h": 20 },
          { "x": 400, "y": 29.6, "w": 40, "h": 60 },
          { "x": 140.5, "y": 760.2, "w": 60, "h": 50 }
      ]
  }
}

where the client_id specifies drone stream and rects are results of detection in form of rectangles. Coordinates x and y are top left corner of rectangle. Values w and h are width and height of the rectangle.