# Real-Time UAV Trash Monitoring System
## 3 Message Queuing System
In our experiment, the confluent-Kafka API had the best throughput both in the producer and the consumer. The three topics _gcs_, _trash_, and _command_ were used in the UAV trash monitoring system. We used one Kafka broker to handle the messages from the UAVs. The topic _gcs_ was used to collect the stream of the UAVs' flight data, and each UAV produced one partition with one replica. The topic _trash_ collected the trash data, which are detected by the UAV, and all the UAVs sent the data to the same partition in the topic. The UAV real-time maps consumed the topic _gcs_ and _trash_ to monitor the status of each UAV and the polluted area of the trash. The topic _command_ collected the commands sent by the base station and was partitioned with the number of UAVs. Figure 12 shows the Kafka configuration in the UAV trash monitoring system. The fire-and-forget method was used to increase the throughput in the topic _gcs_. The asynchronous method was used to gain the good throughput/latency tradeoff in the topic _trash_. The synchronous method was used to guarantee the reliability of data in the topic _command_. A web service is a good way to exchange data between applications that are built in different operating systems or programming languages. In the UAV marine trash monitoring system, the Python web framework Django was used [30] to develop a website that ran on a computer to listen to requests from clients via HTTP (HyperText Transfer Protocol). The real-time UAV trash map used Leaflet [31], a JavaScript library for interactive \begin{table}
\begin{tabular}{c c c c} \hline
**API** & **Time(s)** & **MB/s** & **Msg/s** \\ \hline confluent-kafka & 2.32 & 41.11 & 431,034.19 \\ \hline pykafka & 89.48 & 1.07 & 11,176.24 \\ \hline kafka-python & 250.72 & 0.37 & 3930.44 \\ \hline \end{tabular}
\end{table} 
Table 1: Comparison of the throughput to Kafka producer with three Python APIs. Figure 12: The Kafka configuration in the UAV trash monitoring system. \begin{table}
\begin{tabular}{c c c c} \hline
**API** & **Time(s)** & **MB/s** & **Msg/s** \\ \hline confluent-kafka & 5.36 & 17.8 & 186,679.93 \\ \hline pykafka & 130.84 & 0.73 & 7642.8 \\ \hline kafka-python & 115.36 & 0.83 & 8668.59 \\ \hline \end{tabular}
\end{table} 
Table 2: Comparison of the throughput to Kafka consumer with three Python APIs. maps, along with the Django website and the Kafka broker to develop a monitoring system for trash pollution. The consumers accessed the data from Kafka through the web service, and the trash information such as GPS and the polluted area, which is collected by the UAV, were displayed on the map. For the design of a video streaming server, the UAVs used a 4G network to send the video stream to the server then publish it. Multiple users could subscribe to the video stream server with 30 FPS (Frames per Seconds) via the website. The UAV flew to the waypoints and used the current height and FOV (field of view) of an onboard camera to calculate the position where the UAV should detect the trash with no-repeat trash detection and sent the image back to the server. Additionally, the UAV sent the real-time video stream to the server continuously. ZeroMQ [32] is a concurrency framework based on the socket with in-process, inter-process, and TCP communications. The ImageZMQ [33] is a Python API built for video streaming based on the ZeroMQ framework. To suit the different network conditions, we used the ImageZMQ API with the auto image size tuning method, auto reconnection mechanism, and JPEG compression [34]. In the auto reconnection mechanism, we set the timeout to 1.8 s (this value depended on the network condition of the server and the UAV via trial and error). If the disconnection time was higher than the timeout, the UAV reconnected to the video streaming server automatically. The UAV recorded the number of timeouts that occurred and used it to tune the appropriate image size automatically (the more timeouts occurred, the smaller the image size via trial and error was) to send the video stream to the server.