15
15
16
16
You will need to have a valid mountpoint available. To see available mountpoints go here: http://rtk2go.com:2101/
17
17
18
- This is a proof of concept to show how to connect to a caster via HTTP.
18
+ This is a proof of concept to show how to connect to a caster via HTTP.
19
19
20
20
For more information about NTRIP Clients and the differences between Rev1 and Rev2 of the protocol
21
21
please see: https://www.use-snip.com/kb/knowledge-base/ntrip-rev1-versus-rev2-formats/
22
22
23
- "In broad protocol terms, the NTRIP client must first connect (get an HTTP “OK” reply) and only then
24
- should it send the sentence. NTRIP protocol revision 2 (which does not have very broad industry
23
+ "In broad protocol terms, the NTRIP client must first connect (get an HTTP “OK” reply) and only then
24
+ should it send the sentence. NTRIP protocol revision 2 (which does not have very broad industry
25
25
acceptance at this time) does allow sending the sentence in the original header."
26
26
https://www.use-snip.com/kb/knowledge-base/subtle-issues-with-using-ntrip-client-nmea-183-strings/
27
-
27
+
28
28
Feel like supporting open source hardware?
29
29
Buy a board from SparkFun!
30
30
ZED-F9P RTK2: https://www.sparkfun.com/products/16481
@@ -52,10 +52,10 @@ SFE_UBLOX_GNSS myGNSS;
52
52
53
53
// Global variables
54
54
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
55
- long lastReceivedRTCM_ms = 0 ; // 5 RTCM messages take approximately ~300ms to arrive at 115200bps
55
+ long lastReceivedRTCM_ms = 0 ; // 5 RTCM messages take approximately ~300ms to arrive at 115200bps
56
56
int maxTimeBeforeHangup_ms = 10000 ; // If we fail to get a complete RTCM frame after 10s, then disconnect from caster
57
57
58
- bool transmitLocation = true ; // By default we will transmit the units location via GGA sentence.
58
+ bool transmitLocation = true ; // By default we will transmit the units location via GGA sentence.
59
59
int timeBetweenGGAUpdate_ms = 10000 ; // GGA is required for Rev2 NTRIP casters. Don't transmit but once every 10 seconds
60
60
long lastTransmittedGGA_ms = 0 ;
61
61
@@ -76,15 +76,15 @@ void setup()
76
76
77
77
Wire.begin (); // Start I2C
78
78
79
- while (myGNSS.begin () == false ) // Connect to the Ublox module using Wire port
79
+ while (myGNSS.begin () == false ) // Connect to the Ublox module using Wire port
80
80
{
81
81
Serial.println (F (" u-blox GPS not detected at default I2C address. Please check wiring. Freezing." ));
82
82
delay (2000 );
83
83
// while (1);
84
84
}
85
85
Serial.println (F (" u-blox module connected" ));
86
86
87
- myGNSS.setI2COutput (COM_TYPE_UBX | COM_TYPE_NMEA); // Set the I2C port to output both NMEA and UBX messages
87
+ myGNSS.setI2COutput (COM_TYPE_UBX | COM_TYPE_NMEA); // Set the I2C port to output both NMEA and UBX messages
88
88
myGNSS.setPortInput (COM_PORT_I2C, COM_TYPE_UBX | COM_TYPE_NMEA | COM_TYPE_RTCM3); // Be sure RTCM3 input is enabled. UBX + RTCM3 is not a valid state.
89
89
90
90
myGNSS.enableNMEAMessage (UBX_NMEA_GGA, COM_PORT_I2C); // Verify the GGA sentence is enabled
@@ -93,7 +93,8 @@ void setup()
93
93
94
94
Serial.print (F (" Connecting to local WiFi" ));
95
95
WiFi.begin (ssid, password);
96
- while (WiFi.status () != WL_CONNECTED) {
96
+ while (WiFi.status () != WL_CONNECTED)
97
+ {
97
98
delay (500 );
98
99
Serial.print (F (" ." ));
99
100
}
@@ -102,15 +103,17 @@ void setup()
102
103
Serial.print (F (" WiFi connected with IP: " ));
103
104
Serial.println (WiFi.localIP ());
104
105
105
- while (Serial.available ()) Serial.read ();
106
+ while (Serial.available ())
107
+ Serial.read ();
106
108
}
107
109
108
110
void loop ()
109
111
{
110
112
if (Serial.available ())
111
113
{
112
114
beginClient ();
113
- while (Serial.available ()) Serial.read (); // Empty buffer of any newline chars
115
+ while (Serial.available ())
116
+ Serial.read (); // Empty buffer of any newline chars
114
117
}
115
118
116
119
Serial.println (F (" Press any key to start NTRIP Client." ));
@@ -126,12 +129,13 @@ void beginClient()
126
129
127
130
Serial.println (F (" Subscribing to Caster. Press key to stop" ));
128
131
delay (10 ); // Wait for any serial to arrive
129
- while (Serial.available ()) Serial.read (); // Flush
132
+ while (Serial.available ())
133
+ Serial.read (); // Flush
130
134
131
135
while (Serial.available () == 0 )
132
136
{
133
137
myGNSS.checkUblox ();
134
-
138
+
135
139
// Connect if we are not already. Limit to 5s between attempts.
136
140
if (ntripClient.connected () == false )
137
141
{
@@ -181,13 +185,14 @@ void beginClient()
181
185
String strEncodedCredentials = b.encode (userCredentials);
182
186
char encodedCredentials[strEncodedCredentials.length () + 1 ];
183
187
strEncodedCredentials.toCharArray (encodedCredentials, sizeof (encodedCredentials)); // Convert String to char array
184
- snprintf (credentials, sizeof (credentials), " Authorization: Basic %s\r\n " , encodedCredentials);
185
188
#else
186
189
// Encode with nfriendly library
187
190
int encodedLen = base64_enc_len (strlen (userCredentials));
188
- char encodedCredentials[encodedLen]; // Create array large enough to house encoded data
191
+ char encodedCredentials[encodedLen]; // Create array large enough to house encoded data
189
192
base64_encode (encodedCredentials, userCredentials, strlen (userCredentials)); // Note: Input array is consumed
190
193
#endif
194
+
195
+ snprintf (credentials, sizeof (credentials), " Authorization: Basic %s\r\n " , encodedCredentials);
191
196
}
192
197
strncat (serverRequest, credentials, SERVER_BUFFER_SIZE);
193
198
strncat (serverRequest, " \r\n " , SERVER_BUFFER_SIZE);
@@ -221,7 +226,8 @@ void beginClient()
221
226
int responseSpot = 0 ;
222
227
while (ntripClient.available ())
223
228
{
224
- if (responseSpot == sizeof (response) - 1 ) break ;
229
+ if (responseSpot == sizeof (response) - 1 )
230
+ break ;
225
231
226
232
response[responseSpot++] = ntripClient.read ();
227
233
if (strstr (response, " 200" ) > 0 ) // Look for '200 OK'
@@ -248,10 +254,10 @@ void beginClient()
248
254
Serial.print (F (" Connected to " ));
249
255
Serial.println (casterHost);
250
256
lastReceivedRTCM_ms = millis (); // Reset timeout
251
- ggaTransmitComplete = true ; // Reset to start polling for new GGA data
257
+ ggaTransmitComplete = true ; // Reset to start polling for new GGA data
252
258
}
253
259
} // End attempt to connect
254
- } // End connected == false
260
+ } // End connected == false
255
261
256
262
if (ntripClient.connected () == true )
257
263
{
@@ -263,7 +269,8 @@ void beginClient()
263
269
{
264
270
// Serial.write(ntripClient.read()); //Pipe to serial port is fine but beware, it's a lot of binary data
265
271
rtcmData[rtcmCount++] = ntripClient.read ();
266
- if (rtcmCount == sizeof (rtcmData)) break ;
272
+ if (rtcmCount == sizeof (rtcmData))
273
+ break ;
267
274
}
268
275
269
276
if (rtcmCount > 0 )
@@ -278,12 +285,7 @@ void beginClient()
278
285
}
279
286
280
287
// Provide the caster with our current position as needed
281
- if (ntripClient.connected () == true
282
- && transmitLocation == true
283
- && (millis () - lastTransmittedGGA_ms) > timeBetweenGGAUpdate_ms
284
- && ggaSentenceComplete == true
285
- && ggaTransmitComplete == false
286
- )
288
+ if (ntripClient.connected () == true && transmitLocation == true && (millis () - lastTransmittedGGA_ms) > timeBetweenGGAUpdate_ms && ggaSentenceComplete == true && ggaTransmitComplete == false )
287
289
{
288
290
Serial.print (F (" Pushing GGA to server: " ));
289
291
Serial.println (ggaSentence);
@@ -315,7 +317,8 @@ void beginClient()
315
317
int responseSpot = 0 ;
316
318
while (ntripClient.available ())
317
319
{
318
- if (responseSpot == sizeof (response) - 1 ) break ;
320
+ if (responseSpot == sizeof (response) - 1 )
321
+ break ;
319
322
320
323
response[responseSpot++] = ntripClient.read ();
321
324
if (strstr (response, " 200" ) > 0 ) // Look for '200 OK'
@@ -397,4 +400,4 @@ void SFE_UBLOX_GNSS::processNMEA(char incoming)
397
400
ggaSentenceStarted = false ;
398
401
}
399
402
}
400
- }
403
+ }
0 commit comments