From 2ec96e9db4dddea7ea9aa34996395c445b20cb67 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Mon, 6 Aug 2018 14:21:55 +0200 Subject: add script 'gps-track' --- global-config | 3 +++ gps-track | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 gps-track diff --git a/global-config b/global-config index e5750c6..82b5eab 100644 --- a/global-config +++ b/global-config @@ -37,6 +37,9 @@ # ntp settings. A pool can rotate servers. :global "ntp-pool" "pool.ntp.org"; +# This is the address used to send gps data to. +:global "gps-track-url" "https://example.com/index.php"; + # Enable this to fetch scripts from given url. :global "script-updates-fetch" true; :global "script-updates-baseurl" "https://git.eworm.de/cgit.cgi/routeros-scripts/plain/"; diff --git a/gps-track b/gps-track new file mode 100644 index 0000000..bb4f370 --- /dev/null +++ b/gps-track @@ -0,0 +1,33 @@ +# RouterOS script: gps-track +# Copyright (c) 2018 Christian Hesse +# +# track gps data by sending json data to http server + +:global "identity"; +:global "gps-track-url"; + +:local gpslat; +:local gpslon; +:local gpsvalid; + +/ system gps monitor once do={ + :set $gpslat $("latitude"); + :set $gpslon $("longitude"); + :set $gpsvalid $("valid"); +} + +if ($gpsvalid) do={ + :tool fetch mode=http \ + url=$"gps-track-url" \ + check-certificate=yes-without-crl \ + http-method=post \ + http-content-type="application/json" \ + http-data=("{" . \ + "\"lat\":\"" . $gpslat . "\"," . \ + "\"lon\":\"" . $gpslon . "\"," . \ + "\"identity\":\"" . $identity . "\"" . \ + "}"); + :log debug ("Sending gps data for tracking: " . \ + "lat: " . $gpslat . " " . \ + "lon: " . $gpslon); +} -- cgit v1.2.3-54-g00ecf