-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchive_code.js
184 lines (140 loc) · 3.29 KB
/
archive_code.js
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
Serial4.setup(9600);
var cmd ="";
//Stop our GPS using the enable pin
function stopGPS(){
console.log("Disabling GPS...");
digitalWrite(C4,0);
}
//Start our GPS using the enable pin
function startGPS(){
Serial4.setup(9600);
var cmd ="";
//Stop our GPS using the enable pin
function stopGPS(){
console.log("Disabling GPS...");
digitalWrite(C4,0);
}
//Start our GPS using the enable pin
function startGPS(){
console.log("Starting GPS...");
pinMode(C4,"output");
digitalWrite(C4,1);
//Turn off GSM
pinMode(C1,"output");
digitalWrite(C1,0);
//After 120 seconds disable the GPS
setTimeout(function (e) { stopGPS(); }, 120000);
}
//Startup function
function onInit() {
startGPS();
//Check for our location every...
setTimeout(function (e) { onInit(); }, 240000);
}
//SMS Sending Script
function sendSMS(input){
console.log("SMS TEXT: ");
console.log(input);
}
//Startup Function Call
onInit();
//Parse the GPS strings
function parse(e){
//Turn the string into an array
var temp = e.split(',');
// print(temp[0]);
if (e.indexOf('$GPGGA') != -1)
{
var sentence = temp.join();
console.log(sentence);
//Parse Time
print('Time: ' +temp[1].substring(0,2)+':'+
temp[1].substring(2,4)+':'+temp[1].substring(4,6));
//If good Fix Then give me the Lat and Long
if (temp[6]==1)
{
//Parse Latitude
print(temp[2] + ' ' +temp[3]);
//Parse Longitude
print(temp[4] + ' ' +temp[5]);
//Disable the GPS as we had a fix
console.log("Fix Found, Disabling GPS...");
digitalWrite(C4,0);
var sms_string = temp[2]+','+temp[3]+','+temp[4]+','+temp[5];
sendSMS(sms_string);
}
}
}
//Receive data from GPS & turn in to a string
Serial4.onData(function (e) {
if (e.data=="\r")
{
parse(cmd);
cmd="";
}
else
{
cmd += e.data;
}
});
console.log("Starting GPS...");
pinMode(C4,"output");
digitalWrite(C4,1);
//After 120 seconds disable the GPS
setTimeout(function (e) { stopGPS(); }, 120000);
}
//Startup function
function onInit() {
startGPS();
//Check for our location every...
setTimeout(function (e) { onInit(); }, 240000);
}
//SMS Sending Script
function sendSMS(input){
console.log("SMS TEXT: ");
console.log(input);
}
//Startup Function Call
onInit();
//Parse the GPS strings
function parse(e){
//Turn the string into an array
var temp = e.split(',');
// print(temp[0]);
if (e.indexOf('$GPGGA') != -1)
{
//digitalPulse(LED1,1,100);
//digitalPulse(LED2,1,100);
//digitalPulse(LED3,1,100);
var sentence = temp.join();
console.log(sentence);
//Parse Time
print('Time: ' +temp[1].substring(0,2)+':'+
temp[1].substring(2,4)+':'+temp[1].substring(4,6));
//If good Fix Then give me the Lat and Long
if (temp[6]==1)
{
//Parse Latitude
print(temp[2] + ' ' +temp[3]);
//Parse Longitude
print(temp[4] + ' ' +temp[5]);
//Disable the GPS as we had a fix
console.log("Fix Found, Disabling GPS...");
digitalWrite(C4,0);
var sms_string = temp[2]+','+temp[3]+','+temp[4]+','+temp[5];
sendSMS(sms_string);
}
}
}
//Receive data from GPS & turn in to a string
Serial4.onData(function (e) {
if (e.data=="\r")
{
parse(cmd);
cmd="";
}
else
{
cmd += e.data;
}
});