How to capture and geotag a image with Raspberry Pi 4 as a companion computer to a Pixhawk Orange Cube

Hello, All. I’m quite new to the DIY drones community and programing. I want to build a drone with a Pixhawk orange cube with Copter 4.5.1 and a computer companion Raspberry Pi 4 with its own camera module V2.
Objective:
To trigger the camera on my command from Mission Planner and Geotag the picture with the data from the Pixhawk’s GPS. I have successfully made the serial connection between the Pixhawk and Raspberry Pi. I have employed a relay module that will act as a button to trigger the RPi camera from the GPIO pin with a signal from the autopilot.
I saw a solution in a older post ( Capture geotagged image with Arducam 16mp autofoucus camera, Respberry pi 4 and Pixhawk - #9 by Werner_Pretorius ) and I tried to add lines of code to obtain the desired result.
The main question is if the code below would work? If not could anybody point me in the right direction? Thank you all in advance for your attention!

import RPi.GPIO as GPIO
from picamera2 import Picamera2
import asyncio
import os
from datetime import datetime
import exifread
import dronekit
import time
import shutil

image_path=“/home/pi/my_captures/” #folder for iamges

camera configuration and initialization
camera = Picamera2()
camera_config = camera.create_still_configuration(main={“size”: (1920, 1080)}, lores={“size”: (640, 480)}, display=“lores”)
camera.configure(camera_config)

gpio pins setup
GPIO.setmode(GPIO.BCM)

#Connect to the drone and wait for GPS fix
print(“Connecting to vehicle…”)
vehicle = dronekit.connect(‘/dev/ttyAMA0’, baud=57600)
print(“Waiting for GPS fix…”)
while not vehicle.gps_0.fix_type:
pass
print(“GPS fix obtained.”)

async def capture_photo(channel):
filename = datetime.now().strftime(“%Y%m%d_%H%M%S.jpg”)
temp_file = “/run/shm/{}”.format(filename) # use the ramdisk for faster I/O
camera.start_and_capture_file(temp_file)
return temp_file

async def get_gps_data():
return (vehicle.location.global_frame.lat,
vehicle.location.global_frame.lon,
vehicle.location.global_frame.alt)

async def geotag(temp_file, gps_data):
latitude, longitude, altitude = gps_data
exiftool_cmd = [‘exiftool’, ‘-GPSLatitude={}’.format(latitude), ‘-GPSLongitude={}’.format(longitude), ‘-GPSAltitude={}’.format(altitude), temp_file]

try:
    subprocess.run(exiftool_cmd, check=True)
except subprocess.CalledProcessError as e:
    print("Error geotagging photo: ", e)
    return False

return True

GPIO.setup(16, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.add_event_detect(16, GPIO.FALLING, callback= capture_photo, bouncetime=1000)

main function

async def main():
while True:
temp_file_task = asyncio.create_task(capture_photo())
gps_data_task = asyncio.create_task(get_gps_data())
temp_file = await temp_file_task
gps_data = await gps_data_task
await geotag(temp_file, gps_data)

execute the whole code?

try:
while True:
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()