-
Notifications
You must be signed in to change notification settings - Fork 57
/
GPS_Acceleration.ino
298 lines (250 loc) · 9.01 KB
/
GPS_Acceleration.ino
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/**
* @file GPS_Acceleration.ino
* @author Lewis He ([email protected])
* @license MIT
* @copyright Copyright (c) 2024 Shenzhen Xin Yuan Electronic Technology Co., Ltd
* @date 2024-09-09
* @note
* GPS acceleration only supports A7670X/A7608X (excluding A7670G and other versions that do not support positioning).
* SIM7670G does not support GPS acceleration function
*/
#include "utilities.h"
#define TINY_GSM_RX_BUFFER 1024 // Set RX buffer to 1Kb
// Set serial for debug console (to the Serial Monitor, default speed 115200)
#define SerialMon Serial
// Define the serial console for debug prints, if needed
#define TINY_GSM_DEBUG SerialMon
// See all AT commands, if wanted
// #define DUMP_AT_COMMANDS
#include <TinyGsmClient.h>
#ifdef DUMP_AT_COMMANDS // if enabled it requires the streamDebugger lib
#include <StreamDebugger.h>
StreamDebugger debugger(SerialAT, SerialMon);
TinyGsm modem(debugger);
#else
TinyGsm modem(SerialAT);
#endif
#ifdef TINY_GSM_MODEM_SIM7672
#error "SIM7670G is not support gps acceleration"
#endif
// It depends on the operator whether to set up an APN. If some operators do not set up an APN,
// they will be rejected when registering for the network. You need to ask the local operator for the specific APN.
// APNs from other operators are welcome to submit PRs for filling.
// #define NETWORK_APN "CHN-CT" //CHN-CT: China Telecom
void setup()
{
Serial.begin(115200);
// Turn on DC boost to power on the modem
#ifdef BOARD_POWERON_PIN
pinMode(BOARD_POWERON_PIN, OUTPUT);
digitalWrite(BOARD_POWERON_PIN, HIGH);
#endif
// Set modem reset pin ,reset modem
pinMode(MODEM_RESET_PIN, OUTPUT);
digitalWrite(MODEM_RESET_PIN, !MODEM_RESET_LEVEL); delay(100);
digitalWrite(MODEM_RESET_PIN, MODEM_RESET_LEVEL); delay(2600);
digitalWrite(MODEM_RESET_PIN, !MODEM_RESET_LEVEL);
// Turn on modem
pinMode(BOARD_PWRKEY_PIN, OUTPUT);
digitalWrite(BOARD_PWRKEY_PIN, LOW);
delay(100);
digitalWrite(BOARD_PWRKEY_PIN, HIGH);
delay(1000);
digitalWrite(BOARD_PWRKEY_PIN, LOW);
// Set modem baud
SerialAT.begin(115200, SERIAL_8N1, MODEM_RX_PIN, MODEM_TX_PIN);
Serial.println("Start modem...");
delay(3000);
int retry = 0;
while (!modem.testAT(1000)) {
Serial.println(".");
if (retry++ > 10) {
digitalWrite(BOARD_PWRKEY_PIN, LOW);
delay(100);
digitalWrite(BOARD_PWRKEY_PIN, HIGH);
delay(1000);
digitalWrite(BOARD_PWRKEY_PIN, LOW);
retry = 0;
}
}
Serial.println();
delay(200);
String modemName = "UNKOWN";
while (1) {
modemName = modem.getModemName();
if (modemName == "UNKOWN") {
Serial.println("Unable to obtain module information normally, try again");
delay(1000);
} else if (modemName.startsWith("A7670G")) {
while (1) {
Serial.println("A7670G does not support built-in GPS function, please run examples/GPSShield");
delay(1000);
}
} else {
Serial.print("Model Name:");
Serial.println(modemName);
break;
}
delay(5000);
}
modem.sendAT("+SIMCOMATI");
modem.waitResponse();
// Check if SIM card is online
SimStatus sim = SIM_ERROR;
while (sim != SIM_READY) {
sim = modem.getSimStatus();
switch (sim) {
case SIM_READY:
Serial.println("SIM card online");
break;
case SIM_LOCKED:
Serial.println("The SIM card is locked. Please unlock the SIM card first.");
// const char *SIMCARD_PIN_CODE = "123456";
// modem.simUnlock(SIMCARD_PIN_CODE);
break;
default:
break;
}
delay(1000);
}
//SIM7672G Can't set network mode
if (!modem.setNetworkMode(MODEM_NETWORK_AUTO)) {
Serial.println("Set network mode failed!");
}
String mode = modem.getNetworkModes();
Serial.print("Current network mode : ");
Serial.println(mode);
#ifdef NETWORK_APN
Serial.printf("Set network apn : %s\n", NETWORK_APN);
modem.sendAT(GF("+CGDCONT=1,\"IP\",\""), NETWORK_APN, "\"");
if (modem.waitResponse() != 1) {
Serial.println("Set network apn error !");
}
#endif
// Check network registration status and network signal status
int16_t sq ;
Serial.print("Wait for the modem to register with the network.");
RegStatus status = REG_NO_RESULT;
while (status == REG_NO_RESULT || status == REG_SEARCHING || status == REG_UNREGISTERED) {
status = modem.getRegistrationStatus();
switch (status) {
case REG_UNREGISTERED:
case REG_SEARCHING:
sq = modem.getSignalQuality();
Serial.printf("[%lu] Signal Quality:%d\n", millis() / 1000, sq);
delay(1000);
break;
case REG_DENIED:
Serial.println("Network registration was rejected, please check if the APN is correct");
return ;
case REG_OK_HOME:
Serial.println("Online registration successful");
break;
case REG_OK_ROAMING:
Serial.println("Network registration successful, currently in roaming mode");
break;
default:
Serial.printf("Registration Status:%d\n", status);
delay(1000);
break;
}
}
Serial.println();
Serial.printf("Registration Status:%d\n", status);
delay(1000);
String ueInfo;
if (modem.getSystemInformation(ueInfo)) {
Serial.print("Inquiring UE system information:");
Serial.println(ueInfo);
}
if (!modem.enableNetwork()) {
Serial.println("Enable network failed!");
}
delay(5000);
String ipAddress = modem.getLocalIP();
Serial.print("Network IP:"); Serial.println(ipAddress);
/*
* A7608 B08 firmware has GPS positioning problems. If it is B08 version, you need to upgrade the A7608 firmware.
*
* Manufacturer: INCORPORATED
* Model: A7608SA-H
* Revision: A50C4B08A7600M7
* A7600M7_B08V02_220929
* QCN:
* IMEI: xxxxxxxxxxxxx
* MEID:
* +GCAP: +CGSM,+FCLASS,+DS
* DeviceInfo:
*
* +CGNSSINFO: 2,04,00,21.xxxxx,N,114.xxxxxxxx,E,020924,094145.00,-34.0,1.403,,6.9,6.8,1.0,03
*/
Serial.println("Enabling GPS/GNSS/GLONASS");
while (!modem.enableGPS(MODEM_GPS_ENABLE_GPIO)) {
Serial.print(".");
}
Serial.println();
Serial.println("GPS Enabled");
// Set GPS Baud to 115200
modem.setGPSBaud(115200);
// GPS acceleration only supports A7670X/A7608X (excluding A7670G and other versions that do not support positioning).
// SIM7670G does not support GPS acceleration function
Serial.println("GPS acceleration is enabled");
if (!modem.enableAGPS()) {
Serial.println(" failed !!!");
}else{
Serial.println(" success!!!");
}
}
void loop()
{
float lat2 = 0;
float lon2 = 0;
float speed2 = 0;
float alt2 = 0;
int vsat2 = 0;
int usat2 = 0;
float accuracy2 = 0;
int year2 = 0;
int month2 = 0;
int day2 = 0;
int hour2 = 0;
int min2 = 0;
int sec2 = 0;
uint8_t fixMode = 0;
for (;;) {
Serial.println("Requesting current GPS/GNSS/GLONASS location");
if (modem.getGPS(&fixMode, &lat2, &lon2, &speed2, &alt2, &vsat2, &usat2, &accuracy2,
&year2, &month2, &day2, &hour2, &min2, &sec2)) {
Serial.print("FixMode:"); Serial.println(fixMode);
Serial.print("Latitude:"); Serial.print(lat2, 6); Serial.print("\tLongitude:"); Serial.println(lon2, 6);
Serial.print("Speed:"); Serial.print(speed2); Serial.print("\tAltitude:"); Serial.println(alt2);
Serial.print("Visible Satellites:"); Serial.print(vsat2); Serial.print("\tUsed Satellites:"); Serial.println(usat2);
Serial.print("Accuracy:"); Serial.println(accuracy2);
Serial.print("Year:"); Serial.print(year2);
Serial.print("\tMonth:"); Serial.print(month2);
Serial.print("\tDay:"); Serial.println(day2);
Serial.print("Hour:"); Serial.print(hour2);
Serial.print("\tMinute:"); Serial.print(min2);
Serial.print("\tSecond:"); Serial.println(sec2);
break;
} else {
Serial.println("Couldn't get GPS/GNSS/GLONASS location, retrying in 15s.");
delay(15000UL);
}
}
Serial.println("Retrieving GPS/GNSS/GLONASS location again as a string");
String gps_raw = modem.getGPSraw();
Serial.print("GPS/GNSS Based Location String:");
Serial.println(gps_raw);
Serial.println("Disabling GPS");
modem.disableGPS();
while (1) {
if (SerialAT.available()) {
Serial.write(SerialAT.read());
}
if (Serial.available()) {
SerialAT.write(Serial.read());
}
delay(1);
}
}