Skip to content

Commit 6357b31

Browse files
committed
Moving prints to flash.
1 parent 7c7c8c2 commit 6357b31

File tree

1 file changed

+40
-31
lines changed

1 file changed

+40
-31
lines changed

examples/ZED-F9P/Example15_NTRIPClient/Example15_NTRIPClient.ino

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
This is a proof of concept to show how to connect to a caster via HTTP. Using WiFi for a rover
1717
is generally a bad idea because of limited WiFi range in the field.
1818
19+
For more information about NTRIP Clients and the differences between Rev1 and Rev2 of the protocol
20+
please see: https://www.use-snip.com/kb/knowledge-base/ntrip-rev1-versus-rev2-formats/
21+
1922
Feel like supporting open source hardware?
2023
Buy a board from SparkFun!
2124
ZED-F9P RTK2: https://www.sparkfun.com/products/16481
@@ -50,7 +53,7 @@ int maxTimeBeforeHangup_ms = 10000; //If we fail to get a complete RTCM frame af
5053
void setup()
5154
{
5255
Serial.begin(115200);
53-
Serial.println("NTRIP testing");
56+
Serial.println(F("NTRIP testing"));
5457

5558
Wire.begin(); //Start I2C
5659

@@ -66,23 +69,27 @@ void setup()
6669

6770
myGNSS.setNavigationFrequency(1); //Set output in Hz.
6871

69-
Serial.print("Connecting to local WiFi");
72+
Serial.print(F("Connecting to local WiFi"));
7073
WiFi.begin(ssid, password);
7174
while (WiFi.status() != WL_CONNECTED) {
7275
delay(500);
73-
Serial.print(".");
76+
Serial.print(F("."));
7477
}
7578
Serial.println();
7679

77-
Serial.print("WiFi connected with IP: ");
80+
Serial.print(F("WiFi connected with IP: "));
7881
Serial.println(WiFi.localIP());
7982

8083
while (Serial.available()) Serial.read();
8184
}
8285

8386
void loop()
8487
{
85-
if (Serial.available()) beginClient();
88+
if (Serial.available())
89+
{
90+
beginClient();
91+
while (Serial.available()) Serial.read(); //Empty buffer of any newline chars
92+
}
8693

8794
Serial.println(F("Press any key to start NTRIP Client."));
8895

@@ -95,36 +102,37 @@ void beginClient()
95102
WiFiClient ntripClient;
96103
long rtcmCount = 0;
97104

98-
Serial.println("Subscribing to Caster. Press key to stop");
105+
Serial.println(F("Subscribing to Caster. Press key to stop"));
99106
delay(10); //Wait for any serial to arrive
100107
while (Serial.available()) Serial.read(); //Flush
101108

102109
while (Serial.available() == 0)
103110
{
104-
//Connect if we are not already
111+
//Connect if we are not already. Limit to 5s between attempts.
105112
if (ntripClient.connected() == false)
106113
{
107-
Serial.print("Opening socket to");
114+
Serial.print(F("Opening socket to "));
108115
Serial.println(casterHost);
109116

110117
if (ntripClient.connect(casterHost, casterPort) == false) //Attempt connection
111118
{
112-
Serial.println("Connection to caster failed");
119+
Serial.println(F("Connection to caster failed"));
120+
return;
113121
}
114122
else
115123
{
116-
Serial.print("Connected to ");
124+
Serial.print(F("Connected to "));
117125
Serial.print(casterHost);
118-
Serial.print(": ");
126+
Serial.print(F(": "));
119127
Serial.println(casterPort);
120128

121-
Serial.print("Requesting NTRIP Data from mount point ");
129+
Serial.print(F("Requesting NTRIP Data from mount point "));
122130
Serial.println(mountPoint);
123131

124132
const int SERVER_BUFFER_SIZE = 512;
125133
char serverRequest[SERVER_BUFFER_SIZE];
126134

127-
snprintf(serverRequest, SERVER_BUFFER_SIZE, "GET /%s HTTP/1.0\r\nUser-Agent: SparkFun u-blox NTRIPClient v1.0\r\n",
135+
snprintf(serverRequest, SERVER_BUFFER_SIZE, "GET /%s HTTP/1.0\r\nUser-Agent: NTRIP SparkFun u-blox Client v1.0\r\n",
128136
mountPoint);
129137

130138
char credentials[512];
@@ -138,7 +146,7 @@ void beginClient()
138146
char userCredentials[sizeof(casterUser) + sizeof(casterUserPW) + 1]; //The ':' takes up a spot
139147
snprintf(userCredentials, sizeof(userCredentials), "%s:%s", casterUser, casterUserPW);
140148

141-
Serial.print("Sending credentials: ");
149+
Serial.print(F("Sending credentials: "));
142150
Serial.println(userCredentials);
143151

144152
#if defined(ARDUINO_ARCH_ESP32)
@@ -158,13 +166,13 @@ void beginClient()
158166
strncat(serverRequest, credentials, SERVER_BUFFER_SIZE);
159167
strncat(serverRequest, "\r\n", SERVER_BUFFER_SIZE);
160168

161-
Serial.print("serverRequest size: ");
169+
Serial.print(F("serverRequest size: "));
162170
Serial.print(strlen(serverRequest));
163-
Serial.print(" of ");
171+
Serial.print(F(" of "));
164172
Serial.print(sizeof(serverRequest));
165-
Serial.println(" bytes available");
173+
Serial.println(F(" bytes available"));
166174

167-
Serial.println("Sending server request:");
175+
Serial.println(F("Sending server request:"));
168176
Serial.println(serverRequest);
169177
ntripClient.write(serverRequest, strlen(serverRequest));
170178

@@ -174,7 +182,7 @@ void beginClient()
174182
{
175183
if (millis() - timeout > 5000)
176184
{
177-
Serial.println("Mountpoint timed out!");
185+
Serial.println(F("Caster timed out!"));
178186
ntripClient.stop();
179187
return;
180188
}
@@ -194,23 +202,26 @@ void beginClient()
194202
connectionSuccess = true;
195203
if (strstr(response, "401") > 0) //Look for '401 Unauthorized'
196204
{
197-
Serial.println("Hey - your credentials look bad! Check you caster username and password.");
205+
Serial.println(F("Hey - your credentials look bad! Check you caster username and password."));
198206
connectionSuccess = false;
199207
}
200208
}
201209
response[responseSpot] = '\0';
202210

211+
Serial.print(F("Caster responded with: "));
212+
Serial.println(response);
213+
203214
if (connectionSuccess == false)
204215
{
205-
Serial.print("Failed to connect to ");
216+
Serial.print(F("Failed to connect to "));
206217
Serial.print(casterHost);
207-
Serial.print(": ");
218+
Serial.print(F(": "));
208219
Serial.println(response);
209-
delay(5000); //Don't spam with lots of connection attempts
220+
return;
210221
}
211222
else
212223
{
213-
Serial.print("Connected to ");
224+
Serial.print(F("Connected to "));
214225
Serial.println(casterHost);
215226
lastReceivedRTCM_ms = millis(); //Reset timeout
216227
}
@@ -236,15 +247,15 @@ void beginClient()
236247

237248
//Push RTCM to GNSS module over I2C
238249
myGNSS.pushRawData(rtcmData, rtcmCount, false);
239-
Serial.print("RTCM pushed to ZED: ");
250+
Serial.print(F("RTCM pushed to ZED: "));
240251
Serial.println(rtcmCount);
241252
}
242253
}
243254

244255
//Close socket if we don't have new data for 10s
245256
if (millis() - lastReceivedRTCM_ms > maxTimeBeforeHangup_ms)
246257
{
247-
Serial.println("RTCM timeout. Disconnecting...");
258+
Serial.println(F("RTCM timeout. Disconnecting..."));
248259
if (ntripClient.connected() == true)
249260
ntripClient.stop();
250261
return;
@@ -253,9 +264,7 @@ void beginClient()
253264
delay(10);
254265
}
255266

256-
Serial.println("User pressed a key");
257-
Serial.println("Disconnecting...");
267+
Serial.println(F("User pressed a key"));
268+
Serial.println(F("Disconnecting..."));
258269
ntripClient.stop();
259-
260-
while (Serial.available()) Serial.read(); //Empty buffer of any newline chars
261-
}
270+
}

0 commit comments

Comments
 (0)