Configuraing and using the GPS

The GPS module used by the Infrafon can be controlled using the ‘gps’ device config. As the GPS module requires a certain amount of energy (battery mAh) to run, it is generally kept in either the ‘off’ state (uses practically no power, but increases time to fix (TTF) when turned on) or the ‘sleep’ state (uses a small amount of power, but is faster to fix).

The control of when to enable the GPS, and how long to run it for, is controlled by the config attached to the ‘gps’ in the ‘dev’ json config. As for all other device config, this can be set either in the global json config at allocaztion time, or sent in the fly via an MQTT message (assuming the device is connected). The config attributes look like this:

"gps":{
	"scanDurationSecs":300,
	"scanIntervalSecs":0,
	"stopOnFirstFix":true,
	"alwaysOn":true
}

The ‘scanIntervalSecs’ defines if the GPS will regularly be asked to find a fix (0=no, >0=yes) and how often (expressed in seconds between fix attempts). If set to 0, the GPS fix is only attempted via a manual request - an MQTT message with GPS parameters (or null if no changes) or via the ‘GPS’ button in the system DV (you can also add such a button to your own DV of course!)

Once the GPS is running, it will search for the satellites for the time specified in ‘scanDurationSecs’ - or forever if this is set to 0! Be aware the time to find a fix may be typically up to 1 minutes from a warm start (GPS was sleeping before), 3-5 minutes from a cold start, or it may never manage to find a fix if the device is indoors or the sky is otherwise obscured! Once a fix is found, the GPS continues for the full duraction given, unless ‘stopOnFirstFix’ is set to true, in which case it stops. It can be interesting to let the GPS run for the full time period, as the precision of the fix will increase as more data is collected.

Finally, the ‘alwaysOn’ attribute let you set the behaviour when the GPS is not running - if set to ‘true’ then the GPS is in ‘sleep’ mode (more poower, but faster next fix), if ‘false’ it is held in reset between fix attempts. Generally, if your application aims to have regular GPS fixes (eg every 5 minutes), it is best to have alawysOn=true to get faster fixes, but if it only asks for fixes from tiime to time then set ‘alwaysOn’ to false.

Returned data - sent once the GPS scan has finished (scanDurationSecs expired or stopOnFirstFix):

"gps": {"lat": 48.5737, "hdop": 1.1, "alt": 41.1, "heading": 50, "speed": 0, "at": 1677776939, "lon": -3.817612}

The results of the GPS run contain the result of the search (latitude, longitude, altitude) as well as an indication of the accuracy of the fix ie how close to reality it might be. This is expressed as the ‘hdop’ value, which equates apporoximately to the radius of the circle around the given point in which the real position may be…

The heading and speed indications will only be meaningful if the GPS has been left to run during the movement as the GPS calculates them based on the difference between each fix (1 per second).

Future enhancements may add timers for how long to run after first fix, and how often to send fix updates if running for a long time.