Community discussions

MikroTik App
 
alanpatx
just joined
Topic Author
Posts: 11
Joined: Fri Mar 01, 2013 10:16 am

Upgrade to v6.44, http and GPS information

Wed Apr 17, 2019 12:10 pm

Hi,
I am sending some data from routeros to a dashboarding application called Thingsboard via http/curl.

I recently upgraded to routeros v6.44 and I read in the forums that I need to change the fetch command from "http-content-type" to http-header-field="Content-Type: xxx".

I have done this and it works for one of my scripts. However, it does not work for the script that sends the GPS position information. In this case, the script appears to run OK as the GPS data appears in the CLI in the correct format, but does not update the Thingsboard application. Nothing has changed in Thingsboard, the only change is the routeros upgrade and the above syntax. Here is the script:

Code: Select all

{
:global lat
:global lon
/system gps monitor once do={
:set $lat $("latitude")
:set $lon $("longitude")
};
:tool fetch mode=http url="http://10.0.1.186/api/v1/<<my key>>/telemetry" port=9090 http-method=post \
http-data=("{\"latitude\":\"" . $lat . "\",\"longitude\":\"" . $lon . "\"}") http-header-field="Content-Type:application/json"
:put ("{\"latitude\":\"" . $lat . "\",\"longitude\":\"" . $lon . "\"}")
};
This results in an output as follows when run in CLI:

Code: Select all

[admin@gsm_bl02a] > system script run tracker
date-and-time: apr/17/2019 08:32:23
latitude: N 55 58' 9.78''
longitude: W 3 9' 53.10''
altitude: 22.500000m
speed: 2.759480 km/h
destination-bearing: none
true-bearing: 19.850000 deg. True
magnetic-bearing: none
valid: yes
satellites: 6
fix-quality: 1
horizontal-dilution: 1.7
status: finished
downloaded: 0KiBC-z pause]
duration: 1s

{"latitude":"N 55 58' 9.78''","longitude":"W 3 9' 53.10''"}
To me, this looks correct, but whereas previously the latest telemetry would appear in the device information in Thingsboard, after the upgrade to 6.44 this no longer happens (nothing is received from this particular script though another script on the same board sending LTE signal information works OK). GPS info is in the same format it was previously (DMS).

Any help appreciated.

Alan
 
alanpatx
just joined
Topic Author
Posts: 11
Joined: Fri Mar 01, 2013 10:16 am

Re: Upgrade to v6.44, http and GPS information

Fri Apr 19, 2019 3:18 pm

Update: If the GPS signal is absent, the script successfully posts the word "none" in the values for latitude and longitude. When the GPS signal becomes valid, nothing is posted, even though the correct lat/long values are printed in the terminal.
 
gpsmap
just joined
Posts: 4
Joined: Mon Nov 30, 2020 11:30 am

Re: Upgrade to v6.44, http and GPS information

Wed Dec 02, 2020 7:33 pm

Good afternoon, We offer our option
_______________________________________
Server www.gpsmap.am
_______________________________________
Location API
https://gpsmap.am/server/api/api_loc.ph ... =100|acc=1|
___________________________________________________________________________________________________________________________________________________________

Mikrotik gps tracking script
:local serverURL "https://gpsmap.am/server/api/api_loc.php"
:local fakeImei "013227005456465"
:local SIMslot "0"
:local button "0"

:global isDebug


# :put $isDebug - check current state
# :set $isDebug "terminal" - log to terminal
# :set $isDebug "off" - logging off

# Current Debug status
:set $isDebug "off"



:local gpsDateTime
:local lat
:local lon
:local alt
:local gpsSpeed
:local bearing
:local gpsValid
:local sats
:local hdop
:local DateTime
:local outputURL


#Check and set coordinate format and get data from GPS
:if ( [/system gps get coordinate-format ] != "dd") do={/system gps set coordinate-format=dd}


/system gps monitor once do={
:set $gpsDateTime $("date-and-time")
:set $lat [:pick $("latitude") 0 7]
:set $lon [:pick $("longitude") 0 8]
:set $alt $("altitude")
:set $gpsSpeed $("speed")
:set $bearing $("true-bearing")
:set $gpsValid $("valid")
:set $sats $("satellites")
:set $hdop $("horizontal-dilution")}

:set $alt [:pick $alt 0 [:find $alt "."]]
:set $gpsSpeed ([:pick $gpsSpeed 0 [:find $gpsSpeed "."]].".0")
:set $bearing ([:pick $bearing 0 [:find $bearing "."]].".0")

# Reformating date and time.
:local day [ :pick $gpsDateTime 4 6 ]
:local month [ :pick $gpsDateTime 0 3 ]
:local year [ :pick $gpsDateTime 7 11 ]
:local time [ :pick $gpsDateTime 12 19]
:local DateTime "$year-$month-$day $time"

:set $outputURL ("$serverURL?imei=$fakeImei&dt=$DateTime&lat=$lat&lng=$lon&altitude=$alt&angle=$bearing&speed=$gpsSpeed&loc_valid=1")

:if ($isDebug = "terminal") do={
:put $gpsDateTime
:put $DateTime
:put $lat
:put $lon
:put $alt
:put $gpsSpeed
:put $bearing
:put $gpsValid
:put $sats
:put $hdop
:put $serverURL
:put $fakeImei
:put $battVoltage
:put $SIMslot
:put $button
:put $outputURL
}

/tool fetch mode=http url="$outputURL" output=none

Who is online

Users browsing this forum: onnyloh and 8 guests