From 2391a0289e557a67d24f565a72a0fe54398eb9fc Mon Sep 17 00:00:00 2001 From: Jan-Tarek Butt Date: Mon, 15 Apr 2019 21:16:00 +0200 Subject: [PATCH] package/gluon-geolocator: only write on flash if position has change significantly. Signed-off-by: Jan-Tarek Butt --- .../luasrc/lib/gluon/geolocator/geolocator | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/package/gluon-geolocator/luasrc/lib/gluon/geolocator/geolocator b/package/gluon-geolocator/luasrc/lib/gluon/geolocator/geolocator index 3ec5771c..51a938bb 100755 --- a/package/gluon-geolocator/luasrc/lib/gluon/geolocator/geolocator +++ b/package/gluon-geolocator/luasrc/lib/gluon/geolocator/geolocator @@ -115,10 +115,18 @@ if not next(pos) then os.exit(1) end if not uci:get_bool(GLC, "settings", "static_location") then + + local old_lat = uci:get(LOC, uci:get_first(LOC, 'location'), 'latitude') + local old_lon = uci:get(LOC, uci:get_first(LOC, 'location'), 'longitude') + uci:set(LOC, uci:get_first(LOC, 'location'), 'latitude', pos.lat) uci:set(LOC, uci:get_first(LOC, 'location'), 'longitude', pos.lon) uci:save(LOC) - uci:commit(LOC) + + -- Commit only if no coordinates have been stored before or the Nodes Pos have change significantly +- 22m + if (old_lat == nil or old_lon == nil) or ( math.abs(math.abs(old_lat) - math.abs(pos.lat)) > 0.0002 or math.abs(math.abs(old_lon) - math.abs(pos.lon)) > 0.0002 ) then + uci:commit(LOC) + end end local timestap = io.open(TIME_STAMP, "w") if timestap ~= nil then