Satellite Count function

How do I create a function that counts the satellites the drone is connected to?

It’s sent with the MAVLink message GPS_RAW_INT in the field satellites_visible.

def print_satellite_count(connection):
while True:
msg = connection.recv_match(type=‘GPS_RAW_INT’, blocking=True)
if msg is not None:
satellites_visible = msg.satellites_visible
print(f"Satellites Visible: {satellites_visible}")
break # Exit the loop after receiving the GPS information

this does not work

What autopilot are you using? PX4 or ArduPilot?