1515
1616 You will need to have a valid mountpoint available. To see available mountpoints go here: http://rtk2go.com:2101/
1717
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.
1919
2020 For more information about NTRIP Clients and the differences between Rev1 and Rev2 of the protocol
2121 please see: https://www.use-snip.com/kb/knowledge-base/ntrip-rev1-versus-rev2-formats/
2222
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
2525 acceptance at this time) does allow sending the sentence in the original header."
2626 https://www.use-snip.com/kb/knowledge-base/subtle-issues-with-using-ntrip-client-nmea-183-strings/
27-
27+
2828 Feel like supporting open source hardware?
2929 Buy a board from SparkFun!
3030 ZED-F9P RTK2: https://www.sparkfun.com/products/16481
@@ -52,10 +52,10 @@ SFE_UBLOX_GNSS myGNSS;
5252
5353// Global variables
5454// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
5656int maxTimeBeforeHangup_ms = 10000 ; // If we fail to get a complete RTCM frame after 10s, then disconnect from caster
5757
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.
5959int timeBetweenGGAUpdate_ms = 10000 ; // GGA is required for Rev2 NTRIP casters. Don't transmit but once every 10 seconds
6060long lastTransmittedGGA_ms = 0 ;
6161
@@ -76,15 +76,15 @@ void setup()
7676
7777 Wire.begin (); // Start I2C
7878
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
8080 {
8181 Serial.println (F (" u-blox GPS not detected at default I2C address. Please check wiring. Freezing." ));
8282 delay (2000 );
8383 // while (1);
8484 }
8585 Serial.println (F (" u-blox module connected" ));
8686
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
8888 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.
8989
9090 myGNSS.enableNMEAMessage (UBX_NMEA_GGA, COM_PORT_I2C); // Verify the GGA sentence is enabled
@@ -93,7 +93,8 @@ void setup()
9393
9494 Serial.print (F (" Connecting to local WiFi" ));
9595 WiFi.begin (ssid, password);
96- while (WiFi.status () != WL_CONNECTED) {
96+ while (WiFi.status () != WL_CONNECTED)
97+ {
9798 delay (500 );
9899 Serial.print (F (" ." ));
99100 }
@@ -102,15 +103,17 @@ void setup()
102103 Serial.print (F (" WiFi connected with IP: " ));
103104 Serial.println (WiFi.localIP ());
104105
105- while (Serial.available ()) Serial.read ();
106+ while (Serial.available ())
107+ Serial.read ();
106108}
107109
108110void loop ()
109111{
110112 if (Serial.available ())
111113 {
112114 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
114117 }
115118
116119 Serial.println (F (" Press any key to start NTRIP Client." ));
@@ -126,12 +129,13 @@ void beginClient()
126129
127130 Serial.println (F (" Subscribing to Caster. Press key to stop" ));
128131 delay (10 ); // Wait for any serial to arrive
129- while (Serial.available ()) Serial.read (); // Flush
132+ while (Serial.available ())
133+ Serial.read (); // Flush
130134
131135 while (Serial.available () == 0 )
132136 {
133137 myGNSS.checkUblox ();
134-
138+
135139 // Connect if we are not already. Limit to 5s between attempts.
136140 if (ntripClient.connected () == false )
137141 {
@@ -181,13 +185,14 @@ void beginClient()
181185 String strEncodedCredentials = b.encode (userCredentials);
182186 char encodedCredentials[strEncodedCredentials.length () + 1 ];
183187 strEncodedCredentials.toCharArray (encodedCredentials, sizeof (encodedCredentials)); // Convert String to char array
184- snprintf (credentials, sizeof (credentials), " Authorization: Basic %s\r\n " , encodedCredentials);
185188#else
186189 // Encode with nfriendly library
187190 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
189192 base64_encode (encodedCredentials, userCredentials, strlen (userCredentials)); // Note: Input array is consumed
190193#endif
194+
195+ snprintf (credentials, sizeof (credentials), " Authorization: Basic %s\r\n " , encodedCredentials);
191196 }
192197 strncat (serverRequest, credentials, SERVER_BUFFER_SIZE);
193198 strncat (serverRequest, " \r\n " , SERVER_BUFFER_SIZE);
@@ -221,7 +226,8 @@ void beginClient()
221226 int responseSpot = 0 ;
222227 while (ntripClient.available ())
223228 {
224- if (responseSpot == sizeof (response) - 1 ) break ;
229+ if (responseSpot == sizeof (response) - 1 )
230+ break ;
225231
226232 response[responseSpot++] = ntripClient.read ();
227233 if (strstr (response, " 200" ) > 0 ) // Look for '200 OK'
@@ -248,10 +254,10 @@ void beginClient()
248254 Serial.print (F (" Connected to " ));
249255 Serial.println (casterHost);
250256 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
252258 }
253259 } // End attempt to connect
254- } // End connected == false
260+ } // End connected == false
255261
256262 if (ntripClient.connected () == true )
257263 {
@@ -263,7 +269,8 @@ void beginClient()
263269 {
264270 // Serial.write(ntripClient.read()); //Pipe to serial port is fine but beware, it's a lot of binary data
265271 rtcmData[rtcmCount++] = ntripClient.read ();
266- if (rtcmCount == sizeof (rtcmData)) break ;
272+ if (rtcmCount == sizeof (rtcmData))
273+ break ;
267274 }
268275
269276 if (rtcmCount > 0 )
@@ -278,12 +285,7 @@ void beginClient()
278285 }
279286
280287 // 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 )
287289 {
288290 Serial.print (F (" Pushing GGA to server: " ));
289291 Serial.println (ggaSentence);
@@ -315,7 +317,8 @@ void beginClient()
315317 int responseSpot = 0 ;
316318 while (ntripClient.available ())
317319 {
318- if (responseSpot == sizeof (response) - 1 ) break ;
320+ if (responseSpot == sizeof (response) - 1 )
321+ break ;
319322
320323 response[responseSpot++] = ntripClient.read ();
321324 if (strstr (response, " 200" ) > 0 ) // Look for '200 OK'
@@ -397,4 +400,4 @@ void SFE_UBLOX_GNSS::processNMEA(char incoming)
397400 ggaSentenceStarted = false ;
398401 }
399402 }
400- }
403+ }
0 commit comments