GPS receiver for location, time, and navigation data
Interfaces with the optional GPS module for position, altitude, speed, and satellite-synchronized time. The GPS runs continuously in the background once initialized, updating location data as fixes are acquired. Can auto-sync the system clock from GPS time for accurate timestamps without network access.
local loc = ez.gps.get_location()
if loc and loc.valid then
print(string.format("Position: %.6f, %.6f", loc.lat, loc.lon))
print(string.format("Altitude: %.1f m", loc.alt))
if loc.age > 5000 then
print("Warning: GPS data is stale")
end
end
local mov = ez.gps.get_movement()
if mov then
print(string.format("Speed: %.1f km/h", mov.speed))
print(string.format("Heading: %.0f°", mov.course))
end
local sat = ez.gps.get_satellites()
if sat then
print(string.format("Satellites: %d", sat.count))
if sat.hdop < 2 then
print("Excellent accuracy")
elseif sat.hdop < 5 then
print("Good accuracy")
else
print("Poor accuracy")
end
end
local stats = ez.gps.get_stats()
if stats then
print("Chars received:", stats.chars)
print("Valid sentences:", stats.sentences)
print("Failed checksums:", stats.failed)
if stats.failed > stats.sentences * 0.1 then
print("Warning: high checksum failure rate")
end
end
local t = ez.gps.get_time()
if t and t.valid then
print(string.format("UTC: %04d-%02d-%02d %02d:%02d:%02d",
t.year, t.month, t.day, t.hour, t.min, t.sec))
end
if ez.gps.init() then
print("GPS ready")
else
print("GPS init failed")
end
if ez.gps.is_valid() then
status_bar:set_gps_icon("fix")
else
status_bar:set_gps_icon("searching")
end
local info = ez.gps.query_chip()
if info then print("Chip:", info.hw, "FW:", info.sw) end
ez.gps.send_command("PCAS06,0") -- query firmware version
ez.gps.send_command("PCAS04,7") -- enable GPS+BDS+GLONASS on L76K
if ez.gps.sync_time() then
print("System clock synced to GPS")
local t = ez.system.get_time()
print("Current UTC:", t.hour, t.min, t.sec)
end
-- Manual GPS polling loop
while true do
ez.gps.update()
local loc = ez.gps.get_location()
if loc and loc.valid then
print(loc.lat, loc.lon)
end
ez.system.delay(100)
end