-
Notifications
You must be signed in to change notification settings - Fork 0
/
gps_send_pos.txt
119 lines (98 loc) · 3.8 KB
/
gps_send_pos.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/system gps monitor file=gps
:local email "[email protected]";
:put "start script";
:global gpstext [/file get gps.txt contents];
:local longstart [:find $gpstext "longitude" -1];
:local longend [:find $gpstext "\n" $longstart];
:local latstart [:find $gpstext "latitude" -1];
:local latend [:find $gpstext "\n" $latstart];
:local validstart [:find $gpstext "valid" -1];
:local validend [:find $gpstext "\n" $validstart];
:local valid true;
:local zeros "";
:put "start logic";
:if ([:find $gpstext "yes" $validstart] > 0) do={:set valid true;};
:global longitude [:pick $gpstext ($longstart + 11) $longend];
:local degreestart [:find $longitude " " -1];
:local minutestart [:find $longitude " " $degreestart];
:local secondstart [:find $longitude "'" $minutestart];
:local secondend;
:local secfract;
:if ([:len [:find $longitude "." 0]] < 1) do={
:set secondend [:find $longitude "'" $secondstart];
:set secfract "0";
} else={
:set secondend [:find $longitude "." $secondstart];
:set secfract [:pick $longitude ($secondend + 1) ($secondend + 2)];
};
:local longdegree;
:local longdegreelink;
:if ([:pick $longitude 0 1] = "W") do={
:set longdegree "-";
:set longdegreelink "W";
} else={
:set longdegree "+";
:set longdegreelink "E";
};
:set longdegree ($longdegree . [:pick $longitude 2 $minutestart]);
:set longdegreelink ($longdegreelink . [:pick $longitude 2 $minutestart]);
:local longmin [:pick $longitude ($minutestart + 1) $secondstart];
:local longsec [:pick $longitude ($secondstart + 2) $secondend];
:local longfract ((([:tonum $longmin] * 6000) + ([:tonum $longsec] * 100) + ([:tonum $secfract] * 10) ) / 36);
:while (([:len $zeros] + [:len $longfract]) < 4) do={
:set zeros ($zeros . "0");
};
:put $longitude;
:global newlong ($longdegree . "." . $zeros . $longfract);
:global newlonglink ($longdegreelink . "." . $zeros . $longfract);
:global latitude [:pick $gpstext (latstart + 10) $latend];
:set degreestart [:find $latitude " " -1];
:set minutestart [:find $latitude " " $degreestart];
:set secondstart [:find $latitude "'" $minutestart];
:if ([:len [:find $latitude "." 0]] < 1) do={
:set secondend [:find $latitude "'" $secondstart];
:set secfract "0";
} else={
:set secondend [:find $latitude "." $secondstart];
:set secfract [:pick $latitude ($secondend + 1) ($secondend +2)];
};
:local latdegree;
:local latdegreelink;
:if ([:pick $latitude 0 1] = "N") do={
:set latdegree "+";
:set latdegreelink "N";
} else={
:set latdegree "-";
:set latdegreelink "S";
};
:set latdegree ($latdegree . [:pick $latitude 2 $minutestart]);
:set latdegreelink ($latdegreelink . [:pick $latitude 2 $minutestart]);
:local latmin [:pick $latitude ($minutestart + 1) $secondstart];
:local latsec [:pick $latitude ($secondstart + 2) $secondend];
:local latfract ((([:tonum $latmin] * 6000) + ([:tonum $latsec] * 100) +([:tonum $secfract] * 10)) / 36);
:set zeros "";
:while (([:len $zeros] + [:len $latfract]) < 4) do={
:set zeros ($zeros . "0");
};
:global newlat ($latdegree . "." . $zeros . $latfract);
:global newlatlink ($latdegreelink . "." . $zeros . $latfract);
:global coordinates ($newlong . "," . $newlat);
:put "test";
:if (valid) do={
:global oldpos;
:put "vaild position";
:put $oldpos;
:put $coordinates;
:if ($oldpos != $coordinates) do={
:put "Rozne pozycje";
:local str "http://traccar.com:5055/?id=mikrotik&lat=$newlat&lon=$newlong&hdop=10";
/tool fetch url=$str keep-result=no;
:set oldpos $coordinates;
:put "Router gps position invaild3";
};
} else={
/tool e-mail
send to=$email subject="Router gps position invalid" body="Router gps position invalid"
:put "Router gps position invaild";
};
:put "THE END";