import serial import time # Set up the serial connection to the SIM800 module ser = serial.Serial('/dev/serial0', baudrate=9600, timeout=1) def send_at_command(command, delay=1): """Send an AT command to the SIM800 module.""" ser.write((command + '\r').encode()) time.sleep(delay) reply = ser.read(ser.inWaiting()).decode() return reply # Enable GPS send_at_command("AT+CGNSPWR=1") # Check GPS status (optional) gps_status = send_at_command("AT+CGNSPWR?") print("GPS Status: ", gps_status) # Get the GPS location location_data = send_at_command("AT+CGNSINF", delay=2) print("Location Data: ", location_data) ser.close()
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter