Code: Select all
on GPS#travelled do
let,1,[GPS#spd#d2.0]*3.6 // Store speed in km/h in variable #1
Publish,"%sysname%/GPS/Distanz Trigger/Speed", [int#1]
Publish,"%sysname%/GPS/Distanz Trigger/Longitude", [GPS#long]
Publish,"%sysname%/GPS/Distanz Trigger/Latitude", [GPS#lat]
endon
You first store the speed in km/h in variable #1.
When accessing this via [var#1] you get it as a floating point value.
But since you try to format it anyway, you can also fetch it as an integer value. [int#1]
You can store values in as many variables as you like.
For example you can also compute the average speed, since the GPS does output a new value every second.
Code: Select all
on GPS#travelled do
let,1,[GPS#spd#d2.0]*3.6 // Store speed in km/h in variable #1
let,2,[var#1}+[var#2] // collect the sum of all speeds in var#2
let,3,[int#3]+1 // Count how many stored in the sum
Publish,"%sysname%/GPS/Distanz Trigger/Speed", [int#1]
Publish,"%sysname%/GPS/Distanz Trigger/Longitude", [GPS#long]
Publish,"%sysname%/GPS/Distanz Trigger/Latitude", [GPS#lat]
endon
On Rules#Timer=2 do
Publish,"%sysname%/GPS/Distanz Trigger/Speed", [GPS#spd#d2.0]
Publish,"%sysname%/GPS/Distanz Trigger/Longitude", [GPS#long]
Publish,"%sysname%/GPS/Distanz Trigger/Latitude", [GPS#lat]
// Publish,"%sysname%/GPS/Distanz Trigger/Altitude", [GPS#alt#d0.0]
Publish,"%sysname%/GPS/Distanz Trigger/ODO", [GPS#dist#d0.0]
if [int#3] > 0
let,4,[var#2]/[int#3]
endif
Publish,"%sysname%/GPS/Distanz Trigger/AvgSpd", [var#4#d2.0]
let,2,0
let,3,0
timerSet,2,120
endon
The let command allows for all kinds of calculations.
In theory you could also do the computations in the publish command, but the calculations are then not always run as expected.
Using the let command it is way more predictable
