Gps:time_week_ms returns nil

I am attempting to use some of the GPS tags in LUA

I am using plane 4.3.4 on cube orange

If I try either of these I get an error - “number expected, got nil
Mission planner says 11 sats so I would expect that function to return 11 instead of nil.

gcs:send_text(0, gps:num_sats(instance))
	gcs:send_text(0, gps:time_week_ms( instance ))

Is there a bug with these or am I totally missing something needed to make them work?

What value is instance assigned? In most cases, it should be zero.

Also, if you are running that script immediately upon boot, the GPS may not be initialized before you reference it.

If I assign it 0 or gps:primary_sensor() it was not working.

Turns out the return is an integer. It now works if I use tostring() … Every day is a school day!

This works:

local sat_time = tostring(gps:time_week_ms( 0 ))
	
	gcs:send_text (0, sat_time)
2 Likes

Indeed, Lua is not strictly typed, but your scripts will be less frustrating if you treat it as if it is, where practical.