# A Cyber-Physical System for Wildfire Detection and Firefighting
## 3 Materials and Methods
### Nuclio Serverless Function  
The following code snippet Listing 1 is an example of the JavaScript functions handler managed by the Nuclio platform. The functions are characterized by an event trigger that takes two parameters: _context_ and _event_. The event parameter contains data that the function needs to execute. The process first parses the JSON data in the event body, then checks if the sensor data indicates a fire, and if so, it sends a notification to the IFTTT web service that automatically generates a message for the Telegram chatbot. The notification messages include the sensor value and the geographic value of the fire position. ``` exports.handler=function(context,event){ varforestJson=JSON.parse(event.body); if(forestJson.sensor==\"FIRE_ON\"){ for(leti=0;i<1;i++){ rest.post( '[[https://maker.iftttt.com/trigger/fire_notification/with/key/](https://maker.iftttt.com/trigger/fire_notification/with/key/)]([https://maker.iftttt.com/trigger/fire_notification/with/key/](https://maker.iftttt.com/trigger/fire_notification/with/key/))'+ iftttt_event_key,{data:{value1:forestJson.sensor,

Figure 9: Node-RED flow for the UAV monitoring dashboard. value2: forestJson.position[0], value3: forestJson.position[1]}}).on('complete', function(data){console.log(\"Foreststatus: \"+forestJson.sensor+ \"Latitude: \"+forestJson.position[0]+ \"Longitude: \"+forestJson.position[1]);}); } } context.callback(\"\"); };...

### ROS-Based UAV Node

The UAV node is a crucial component of our cyber-physical system for wildfire detection and firefighting. As previously mentioned, this node is an integrated system composed of an ROS/MAVROS environment installed on the companion computer that is responsible for processing the data acquired by the UAV's sensors, including cameras and other environmental sensors. It also provides a platform for implementing advanced algorithms for processing sensor data and for controlling the UAV's behavior. The PX4 Autopilot, on the other hand, is responsible for generating the control signals needed to navigate the UAV to specific locations in the wildfire-affected area. The use of MAVROS as a middleware enables seamless communication between the ROS environment and the PX4 Autopilot, allowing for the real-time exchange of sensor data and control signals. This communication is critical for ensuring that the UAV operates safely and effectively, and it is essential for implementing advanced algorithms for wildfire detection, firefighting, and collaboration with all the other distributed systems that are involved in the architecture. UAV ROS Launcher

In order to test the behavior of the UAV, how to detect fire spots, and how to avoid a collision, a 3D simulation environment has been used. The setup of the simulated UAV environment consists of the following ROS launcher:

* **Local Planner Launcher**: This is used for launching a simulation environment for a UAV with triple-depth cameras and a local planner nodelet
* **UAV Controller Launcher**: This provides functions to set different modes of operation for the PX4 Flight Controller Unit. It includes functions for takeoff, landing, arming, and disarming the FCU, as well as for setting different flight modes such as AUTO, STABILIZED, OFFBOARD, ALTCTL, and POSTCL modes. These functions use ROS and MAVROS service proxies to call FCU commands and change the mode of the UAV. * **YOLOv5 Detection Launcher:** This specifies the detection configuration parameters for the YOLOv5 model, including the weights and data paths, confidence and IoU thresholds, the maximum number of detections, a device used for inference, and line thickness for bounding box visualization. The launch file also allows for setting the input image topic and output topic for the YOLOv5 detection node, as well as the option to publish annotated images and visualize the results using an OpenCV window. * **ROS-Bridge Launcher:** This is a protocol that enables bidirectional communication between a client and a server over a single TCP connection.