Skip to content

Commit 4e94a9d

Browse files
authored
Merge pull request #14 from sparkfun/release_candidate
v1.1.0
2 parents 550baba + 4cc47e0 commit 4e94a9d

File tree

21 files changed

+2199
-163
lines changed

21 files changed

+2199
-163
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ SparkFun u-blox SARA-R5 Arduino Library
1212
</tr>
1313
</table>
1414
15-
An Arduino library for the u-blox SARA-R5 LTE-M / NB-IoT modules with secure cloud, as used on the SparkFun MicroMod Asset Tracker and SparkFun LTE GNSS Breakout - SARA-R5.
15+
An Arduino library for the u-blox SARA-R5 LTE-M / NB-IoT modules with secure cloud, as used on the [SparkFun MicroMod Asset Tracker](https://www.sparkfun.com/products/17272) and the [SparkFun LTE GNSS Breakout - SARA-R5](https://www.sparkfun.com/products/18031).
16+
17+
v1.1 has had a thorough update and includes new features and examples. This library now supports up to 7 simultaneous TCP or UDP sockets. There are new examples to show how to play ping pong with multiple TCP and UDP sockets.
18+
19+
v1.1 also supports binary data transfers correctly. There are new examples showing how you can integrate this library with the [SparkFun u-blox GNSS Arduino Library](https://github.com/sparkfun/SparkFun_u-blox_GNSS_Arduino_Library) and use the SARA-R5 to: download AssistNow Online and Offline data and push it to the GNSS; open a connection to a NTRIP Caster (such as RTK2go, Skylark or Emlid Caster) and push RTK correction data to the GNSS.
20+
21+
You can install this library using the Arduino IDE Library Manager: search for _**SparkFun u-blox SARA-R5**_
1622

1723
## Repository Contents
1824

examples/SARA-R5_Example10_SocketPingPong/SARA-R5_Example10_SocketPingPong.ino

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,13 @@ void setup()
294294
IPAddress myAddress;
295295
mySARA.getNetworkAssignedIPAddress(0, &myAddress);
296296
Serial.print(F("\r\nMy IP Address is: "));
297-
Serial.println(myAddress.toString());
297+
Serial.print(myAddress[0]);
298+
Serial.print(F("."));
299+
Serial.print(myAddress[1]);
300+
Serial.print(F("."));
301+
Serial.print(myAddress[2]);
302+
Serial.print(F("."));
303+
Serial.println(myAddress[3]);
298304

299305
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
300306

@@ -392,8 +398,14 @@ void setup()
392398
}
393399
}
394400

395-
Serial.print(F("Remote address is "));
396-
Serial.println(theAddress.toString());
401+
Serial.print(F("Remote address is: "));
402+
Serial.print(theAddress[0]);
403+
Serial.print(F("."));
404+
Serial.print(theAddress[1]);
405+
Serial.print(F("."));
406+
Serial.print(theAddress[2]);
407+
Serial.print(F("."));
408+
Serial.println(theAddress[3]);
397409

398410
// Open the socket
399411
socketNum = mySARA.socketOpen(SARA_R5_TCP);
@@ -525,7 +537,13 @@ void printSocketParameters(int socket)
525537
IPAddress remoteAddress;
526538
int remotePort;
527539
mySARA.querySocketRemoteIPAddress(socket, &remoteAddress, &remotePort);
528-
Serial.println(remoteAddress.toString());
540+
Serial.print(remoteAddress[0]);
541+
Serial.print(F("."));
542+
Serial.print(remoteAddress[1]);
543+
Serial.print(F("."));
544+
Serial.print(remoteAddress[2]);
545+
Serial.print(F("."));
546+
Serial.println(remoteAddress[3]);
529547

530548
Serial.print(F("Socket status (TCP sockets only): "));
531549
SARA_R5_tcp_socket_status_t socketStatus;

examples/SARA-R5_Example10_SocketPingPong_BinaryTCP/SARA-R5_Example10_SocketPingPong_BinaryTCP.ino

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,14 @@ void processSocketListen(int listeningSocket, IPAddress localIP, unsigned int li
143143
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
144144

145145
// processSocketData is provided to the SARA-R5 library via a
146-
// callback setter -- setSocketReadCallback. (See setup())
147-
void processSocketData(int socket, String theData)
146+
// callback setter -- setSocketReadCallbackPlus. (See setup())
147+
void processSocketData(int socket, const char *theData, int dataLength, IPAddress remoteAddress, int remotePort)
148148
{
149149
Serial.println();
150150
Serial.print(F("Data received on socket "));
151151
Serial.print(socket);
152152
Serial.print(F(" :"));
153-
for (int i = 0; i < theData.length(); i++)
153+
for (int i = 0; i < dataLength; i++)
154154
{
155155
Serial.print(F(" 0x"));
156156
if (theData[i] < 16)
@@ -168,18 +168,10 @@ void processSocketData(int socket, String theData)
168168

169169
if ((theData[0] == 0x04) && (theData[1] == 0x05) && (theData[2] == 0x06) && (theData[3] == 0x07)) // Look for the "Pong"
170170
{
171-
// Use the const char * version
172-
//const char ping[] = { 0x00, 0x01, 0x02, 0x03 };
173-
//mySARA.socketWrite(socket, ping, 4); // Send the "Ping"
174-
175-
// Or use the String version. Both are OK for binary data.
176-
String ping = "";
177-
ping.concat('\0'); // Construct the ping in a binary-friendly way
178-
ping.concat('\1');
179-
ping.concat('\2');
180-
ping.concat('\3');
181-
mySARA.socketWrite(socket, ping); // Send the "Ping"
182-
171+
// Use the const char * version for binary data
172+
const char ping[] = { 0x00, 0x01, 0x02, 0x03 };
173+
mySARA.socketWrite(socket, ping, 4); // Send the "Ping"
174+
183175
pingCount++;
184176
}
185177

@@ -215,13 +207,13 @@ void processPSDAction(int result, IPAddress ip)
215207
if (result == 0)
216208
Serial.print(F(" (success)"));
217209
Serial.print(F(" IP Address: \""));
218-
Serial.print(String(ip[0]));
210+
Serial.print(ip[0]);
219211
Serial.print(F("."));
220-
Serial.print(String(ip[1]));
212+
Serial.print(ip[1]);
221213
Serial.print(F("."));
222-
Serial.print(String(ip[2]));
214+
Serial.print(ip[2]);
223215
Serial.print(F("."));
224-
Serial.print(String(ip[3]));
216+
Serial.print(ip[3]);
225217
Serial.println(F("\""));
226218
}
227219

@@ -311,7 +303,13 @@ void setup()
311303
IPAddress myAddress;
312304
mySARA.getNetworkAssignedIPAddress(0, &myAddress);
313305
Serial.print(F("\r\nMy IP Address is: "));
314-
Serial.println(myAddress.toString());
306+
Serial.print(myAddress[0]);
307+
Serial.print(F("."));
308+
Serial.print(myAddress[1]);
309+
Serial.print(F("."));
310+
Serial.print(myAddress[2]);
311+
Serial.print(F("."));
312+
Serial.println(myAddress[3]);
315313

316314
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
317315

@@ -321,7 +319,7 @@ void setup()
321319
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
322320

323321
// Set a callback to process the socket data
324-
mySARA.setSocketReadCallback(&processSocketData);
322+
mySARA.setSocketReadCallbackPlus(&processSocketData);
325323

326324
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
327325

@@ -409,8 +407,14 @@ void setup()
409407
}
410408
}
411409

412-
Serial.print(F("Remote address is "));
413-
Serial.println(theAddress.toString());
410+
Serial.print(F("Remote address is: "));
411+
Serial.print(theAddress[0]);
412+
Serial.print(F("."));
413+
Serial.print(theAddress[1]);
414+
Serial.print(F("."));
415+
Serial.print(theAddress[2]);
416+
Serial.print(F("."));
417+
Serial.println(theAddress[3]);
414418

415419
// Open the socket
416420
socketNum = mySARA.socketOpen(SARA_R5_TCP);
@@ -541,7 +545,13 @@ void printSocketParameters(int socket)
541545
IPAddress remoteAddress;
542546
int remotePort;
543547
mySARA.querySocketRemoteIPAddress(socket, &remoteAddress, &remotePort);
544-
Serial.println(remoteAddress.toString());
548+
Serial.print(remoteAddress[0]);
549+
Serial.print(F("."));
550+
Serial.print(remoteAddress[1]);
551+
Serial.print(F("."));
552+
Serial.print(remoteAddress[2]);
553+
Serial.print(F("."));
554+
Serial.println(remoteAddress[3]);
545555

546556
Serial.print(F("Socket status (TCP sockets only): "));
547557
SARA_R5_tcp_socket_status_t socketStatus;

examples/SARA-R5_Example10_SocketPingPong_MultipleTCP/SARA-R5_Example10_SocketPingPong_MultipleTCP.ino

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,13 @@ void setup()
320320
IPAddress myAddress;
321321
mySARA.getNetworkAssignedIPAddress(0, &myAddress);
322322
Serial.print(F("\r\nMy IP Address is: "));
323-
Serial.println(myAddress.toString());
323+
Serial.print(myAddress[0]);
324+
Serial.print(F("."));
325+
Serial.print(myAddress[1]);
326+
Serial.print(F("."));
327+
Serial.print(myAddress[2]);
328+
Serial.print(F("."));
329+
Serial.println(myAddress[3]);
324330

325331
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
326332

@@ -419,7 +425,13 @@ void setup()
419425
}
420426

421427
Serial.print(F("Remote address is "));
422-
Serial.println(theAddress.toString());
428+
Serial.print(theAddress[0]);
429+
Serial.print(F("."));
430+
Serial.print(theAddress[1]);
431+
Serial.print(F("."));
432+
Serial.print(theAddress[2]);
433+
Serial.print(F("."));
434+
Serial.println(theAddress[3]);
423435

424436
// Open the sockets
425437
for (int i = 0; i < numConnections; i++)
@@ -569,7 +581,13 @@ void printSocketParameters(int socket)
569581
IPAddress remoteAddress;
570582
int remotePort;
571583
mySARA.querySocketRemoteIPAddress(socket, &remoteAddress, &remotePort);
572-
Serial.println(remoteAddress.toString());
584+
Serial.print(remoteAddress[0]);
585+
Serial.print(F("."));
586+
Serial.print(remoteAddress[1]);
587+
Serial.print(F("."));
588+
Serial.print(remoteAddress[2]);
589+
Serial.print(F("."));
590+
Serial.println(remoteAddress[3]);
573591

574592
Serial.print(F("Socket status (TCP sockets only): "));
575593
SARA_R5_tcp_socket_status_t socketStatus;

examples/SARA-R5_Example10_SocketPingPong_MultipleUDP/SARA-R5_Example10_SocketPingPong_MultipleUDP.ino

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,13 @@ void processSocketData(int socket, const char *theData, int length, IPAddress re
121121
Serial.print(F("Data received on socket "));
122122
Serial.print(socket);
123123
Serial.print(F(" from IP "));
124-
Serial.print(remoteAddress.toString());
124+
Serial.print(remoteAddress[0]);
125+
Serial.print(F("."));
126+
Serial.print(remoteAddress[1]);
127+
Serial.print(F("."));
128+
Serial.print(remoteAddress[2]);
129+
Serial.print(F("."));
130+
Serial.print(remoteAddress[3]);
125131
Serial.print(F(" using port "));
126132
Serial.print(remotePort);
127133
Serial.print(F(" :"));
@@ -148,18 +154,10 @@ void processSocketData(int socket, const char *theData, int length, IPAddress re
148154
{
149155
if (pingCount[connection] < pingPongLimit)
150156
{
151-
// Use the const char * version
152-
//const char ping[] = { 0x00, 0x01, 0x02, 0x03 };
153-
//mySARA.socketWriteUDP(socket, remoteAddress, remotePort, ping, 4); // Send the "Ping"
157+
// Use the const char * version for binary data
158+
const char ping[] = { 0x00, 0x01, 0x02, 0x03 };
159+
mySARA.socketWriteUDP(socket, remoteAddress, remotePort, ping, 4); // Send the "Ping"
154160

155-
// Or use the String version. Both are OK for binary data.
156-
String ping = "";
157-
ping.concat('\0'); // Construct the ping in a binary-friendly way
158-
ping.concat('\1');
159-
ping.concat('\2');
160-
ping.concat('\3');
161-
mySARA.socketWriteUDP(socket, remoteAddress.toString(), remotePort, ping); // Send the "Ping"
162-
163161
pingCount[connection]++;
164162
}
165163
}
@@ -196,7 +194,13 @@ void processPSDAction(int result, IPAddress ip)
196194
if (result == 0)
197195
Serial.print(F(" (success)"));
198196
Serial.print(F(" IP Address: \""));
199-
Serial.print(ip.toString());
197+
Serial.print(ip[0]);
198+
Serial.print(F("."));
199+
Serial.print(ip[1]);
200+
Serial.print(F("."));
201+
Serial.print(ip[2]);
202+
Serial.print(F("."));
203+
Serial.print(ip[3]);
200204
Serial.println(F("\""));
201205
}
202206

@@ -292,7 +296,13 @@ void setup()
292296
IPAddress myAddress;
293297
mySARA.getNetworkAssignedIPAddress(0, &myAddress);
294298
Serial.print(F("\r\nMy IP Address is: "));
295-
Serial.println(myAddress.toString());
299+
Serial.print(myAddress[0]);
300+
Serial.print(F("."));
301+
Serial.print(myAddress[1]);
302+
Serial.print(F("."));
303+
Serial.print(myAddress[2]);
304+
Serial.print(F("."));
305+
Serial.println(myAddress[3]);
296306

297307
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
298308

@@ -344,7 +354,13 @@ void setup()
344354
}
345355

346356
Serial.print(F("Remote address is "));
347-
Serial.println(theAddress.toString());
357+
Serial.print(theAddress[0]);
358+
Serial.print(F("."));
359+
Serial.print(theAddress[1]);
360+
Serial.print(F("."));
361+
Serial.print(theAddress[2]);
362+
Serial.print(F("."));
363+
Serial.println(theAddress[3]);
348364

349365
// Open the sockets
350366
for (int i = 0; i < numConnections; i++)

examples/SARA-R5_Example12_AssistNowOnline/SARA-R5_AssistNow_Online.ino

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,62 @@ void prettyPrintString(String theString) // Pretty-print a String in HEX and ASC
186186

187187
Serial.println();
188188
}
189+
190+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
191+
192+
void prettyPrintChars(char *theData, int theLength) // Pretty-print char data in HEX and ASCII format
193+
{
194+
Serial.println();
195+
Serial.print(F("String length is "));
196+
Serial.print(theLength);
197+
Serial.print(F(" (0x"));
198+
Serial.print(theLength, HEX);
199+
Serial.println(F(")"));
200+
Serial.println();
201+
202+
for (int i = 0; i < theLength; i += 16)
203+
{
204+
if (i < 10000) Serial.print(F("0"));
205+
if (i < 1000) Serial.print(F("0"));
206+
if (i < 100) Serial.print(F("0"));
207+
if (i < 10) Serial.print(F("0"));
208+
Serial.print(i);
209+
210+
Serial.print(F(" 0x"));
211+
212+
if (i < 0x1000) Serial.print(F("0"));
213+
if (i < 0x100) Serial.print(F("0"));
214+
if (i < 0x10) Serial.print(F("0"));
215+
Serial.print(i, HEX);
216+
217+
Serial.print(F(" "));
218+
219+
int j;
220+
for (j = 0; ((i + j) < theLength) && (j < 16); j++)
221+
{
222+
if (theData[i + j] < 0x10) Serial.print(F("0"));
223+
Serial.print(theData[i + j], HEX);
224+
Serial.print(F(" "));
225+
}
226+
227+
if (((i + j) == theLength) && (j < 16))
228+
{
229+
for (int k = 0; k < (16 - (theLength % 16)); k++)
230+
{
231+
Serial.print(F(" "));
232+
}
233+
}
234+
235+
for (j = 0; ((i + j) < theLength) && (j < 16); j++)
236+
{
237+
if ((theData[i + j] >= 0x20) && (theData[i + j] <= 0x7E))
238+
Serial.write(theData[i + j]);
239+
else
240+
Serial.print(F("."));
241+
}
242+
243+
Serial.println();
244+
}
245+
246+
Serial.println();
247+
}

0 commit comments

Comments
 (0)