I have been trying to write a python script that gets current locational data and have not been having any luck with it. Anyone write a script similar to that or could offer any advice? Thanks.
Would this work? Or are you looking for a script to call the IC2 API?
import requests
from requests.auth import HTTPBasicAuth
Replace with your actual Peplink router IP, username, and password
ROUTER_IP = “192.168.1.1”
USERNAME = “admin”
PASSWORD = “your_password”
def get_gps_location():
url = f"https://{ROUTER_IP}/api/status.gps"
try:
response = requests.get(url, auth=HTTPBasicAuth(USERNAME, PASSWORD), verify=False)
response.raise_for_status()
data = response.json()
if data.get("gps_status") == "active":
location = {
"latitude": data.get("latitude"),
"longitude": data.get("longitude"),
"altitude": data.get("altitude"),
"speed": data.get("speed"),
"heading": data.get("heading")
}
return location
else:
return {"error": "GPS not active or no fix available."}
except Exception as e:
return {"error": str(e)}
Run and print location
if name == “main”:
location = get_gps_location()
print(location)