Skip to content

v1.1.0 #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6002c47
Merge branch 'main' into release_candidate
PaulZC Jan 9, 2022
c96f441
Add reentry protection for poll and bufferedPoll
PaulZC Jan 13, 2022
4a06062
Add SARA-R5_Example15_GNSS_NTRIP_Caster
PaulZC Jan 14, 2022
f2cae0c
Update socketRead to respect _saraR5maxSocketRead. Update Example15
PaulZC Jan 15, 2022
39ed676
Update SparkFun_u-blox_SARA-R5_Arduino_Library.cpp
PaulZC Jan 15, 2022
b823e85
Add missing closeConnection's
PaulZC Jan 15, 2022
ee9b6c7
Add base64 for Mbed platforms (Artemis & NRF52840)
PaulZC Jan 15, 2022
8591d75
Change debug print to write
PaulZC Jan 17, 2022
26e06a9
Disable response debug prints - they were causing serial buffer overruns
PaulZC Jan 17, 2022
1503630
Avoid compiler warnings
PaulZC Jan 17, 2022
2fd66ae
Add getFileContents(String filename, char *contents)
PaulZC Jan 17, 2022
9d69e1e
Update SparkFun_u-blox_SARA-R5_Arduino_Library.cpp
PaulZC Jan 17, 2022
2f9d637
Update examples 12 and 14 to use the updated getFileContents
PaulZC Jan 17, 2022
21cda94
Update example 15 to use setSocketReadCallbackPlus for binary compati…
PaulZC Jan 17, 2022
a03c336
Remove String.toString(). Use setSocketReadCallbackPlus in the binary…
PaulZC Jan 17, 2022
004eb4a
Allocate memory for _saraRXBuffer, _pruneBuffer & _saraResponseBackl…
PaulZC Jan 17, 2022
e6fc72b
Decrease socket write @ timeout to 5 seconds
PaulZC Jan 17, 2022
a2134bc
Store the NTRIP credentials etc. in allocated memory - to avoid stack…
PaulZC Jan 17, 2022
138bb85
Allocate memory for the AssistNow data
PaulZC Jan 18, 2022
f21d982
v1.1.0
PaulZC Jan 18, 2022
58986bd
Add Example 16 - works better on Mbed OS
PaulZC Jan 18, 2022
4cc47e0
Update README.md
PaulZC Jan 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ SparkFun u-blox SARA-R5 Arduino Library
</tr>
</table>

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.
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).

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.

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.

You can install this library using the Arduino IDE Library Manager: search for _**SparkFun u-blox SARA-R5**_

## Repository Contents

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,13 @@ void setup()
IPAddress myAddress;
mySARA.getNetworkAssignedIPAddress(0, &myAddress);
Serial.print(F("\r\nMy IP Address is: "));
Serial.println(myAddress.toString());
Serial.print(myAddress[0]);
Serial.print(F("."));
Serial.print(myAddress[1]);
Serial.print(F("."));
Serial.print(myAddress[2]);
Serial.print(F("."));
Serial.println(myAddress[3]);

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Expand Down Expand Up @@ -392,8 +398,14 @@ void setup()
}
}

Serial.print(F("Remote address is "));
Serial.println(theAddress.toString());
Serial.print(F("Remote address is: "));
Serial.print(theAddress[0]);
Serial.print(F("."));
Serial.print(theAddress[1]);
Serial.print(F("."));
Serial.print(theAddress[2]);
Serial.print(F("."));
Serial.println(theAddress[3]);

// Open the socket
socketNum = mySARA.socketOpen(SARA_R5_TCP);
Expand Down Expand Up @@ -525,7 +537,13 @@ void printSocketParameters(int socket)
IPAddress remoteAddress;
int remotePort;
mySARA.querySocketRemoteIPAddress(socket, &remoteAddress, &remotePort);
Serial.println(remoteAddress.toString());
Serial.print(remoteAddress[0]);
Serial.print(F("."));
Serial.print(remoteAddress[1]);
Serial.print(F("."));
Serial.print(remoteAddress[2]);
Serial.print(F("."));
Serial.println(remoteAddress[3]);

Serial.print(F("Socket status (TCP sockets only): "));
SARA_R5_tcp_socket_status_t socketStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ void processSocketListen(int listeningSocket, IPAddress localIP, unsigned int li
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

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

if ((theData[0] == 0x04) && (theData[1] == 0x05) && (theData[2] == 0x06) && (theData[3] == 0x07)) // Look for the "Pong"
{
// Use the const char * version
//const char ping[] = { 0x00, 0x01, 0x02, 0x03 };
//mySARA.socketWrite(socket, ping, 4); // Send the "Ping"

// Or use the String version. Both are OK for binary data.
String ping = "";
ping.concat('\0'); // Construct the ping in a binary-friendly way
ping.concat('\1');
ping.concat('\2');
ping.concat('\3');
mySARA.socketWrite(socket, ping); // Send the "Ping"

// Use the const char * version for binary data
const char ping[] = { 0x00, 0x01, 0x02, 0x03 };
mySARA.socketWrite(socket, ping, 4); // Send the "Ping"

pingCount++;
}

Expand Down Expand Up @@ -215,13 +207,13 @@ void processPSDAction(int result, IPAddress ip)
if (result == 0)
Serial.print(F(" (success)"));
Serial.print(F(" IP Address: \""));
Serial.print(String(ip[0]));
Serial.print(ip[0]);
Serial.print(F("."));
Serial.print(String(ip[1]));
Serial.print(ip[1]);
Serial.print(F("."));
Serial.print(String(ip[2]));
Serial.print(ip[2]);
Serial.print(F("."));
Serial.print(String(ip[3]));
Serial.print(ip[3]);
Serial.println(F("\""));
}

Expand Down Expand Up @@ -311,7 +303,13 @@ void setup()
IPAddress myAddress;
mySARA.getNetworkAssignedIPAddress(0, &myAddress);
Serial.print(F("\r\nMy IP Address is: "));
Serial.println(myAddress.toString());
Serial.print(myAddress[0]);
Serial.print(F("."));
Serial.print(myAddress[1]);
Serial.print(F("."));
Serial.print(myAddress[2]);
Serial.print(F("."));
Serial.println(myAddress[3]);

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Expand All @@ -321,7 +319,7 @@ void setup()
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

// Set a callback to process the socket data
mySARA.setSocketReadCallback(&processSocketData);
mySARA.setSocketReadCallbackPlus(&processSocketData);

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Expand Down Expand Up @@ -409,8 +407,14 @@ void setup()
}
}

Serial.print(F("Remote address is "));
Serial.println(theAddress.toString());
Serial.print(F("Remote address is: "));
Serial.print(theAddress[0]);
Serial.print(F("."));
Serial.print(theAddress[1]);
Serial.print(F("."));
Serial.print(theAddress[2]);
Serial.print(F("."));
Serial.println(theAddress[3]);

// Open the socket
socketNum = mySARA.socketOpen(SARA_R5_TCP);
Expand Down Expand Up @@ -541,7 +545,13 @@ void printSocketParameters(int socket)
IPAddress remoteAddress;
int remotePort;
mySARA.querySocketRemoteIPAddress(socket, &remoteAddress, &remotePort);
Serial.println(remoteAddress.toString());
Serial.print(remoteAddress[0]);
Serial.print(F("."));
Serial.print(remoteAddress[1]);
Serial.print(F("."));
Serial.print(remoteAddress[2]);
Serial.print(F("."));
Serial.println(remoteAddress[3]);

Serial.print(F("Socket status (TCP sockets only): "));
SARA_R5_tcp_socket_status_t socketStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,13 @@ void setup()
IPAddress myAddress;
mySARA.getNetworkAssignedIPAddress(0, &myAddress);
Serial.print(F("\r\nMy IP Address is: "));
Serial.println(myAddress.toString());
Serial.print(myAddress[0]);
Serial.print(F("."));
Serial.print(myAddress[1]);
Serial.print(F("."));
Serial.print(myAddress[2]);
Serial.print(F("."));
Serial.println(myAddress[3]);

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Expand Down Expand Up @@ -419,7 +425,13 @@ void setup()
}

Serial.print(F("Remote address is "));
Serial.println(theAddress.toString());
Serial.print(theAddress[0]);
Serial.print(F("."));
Serial.print(theAddress[1]);
Serial.print(F("."));
Serial.print(theAddress[2]);
Serial.print(F("."));
Serial.println(theAddress[3]);

// Open the sockets
for (int i = 0; i < numConnections; i++)
Expand Down Expand Up @@ -569,7 +581,13 @@ void printSocketParameters(int socket)
IPAddress remoteAddress;
int remotePort;
mySARA.querySocketRemoteIPAddress(socket, &remoteAddress, &remotePort);
Serial.println(remoteAddress.toString());
Serial.print(remoteAddress[0]);
Serial.print(F("."));
Serial.print(remoteAddress[1]);
Serial.print(F("."));
Serial.print(remoteAddress[2]);
Serial.print(F("."));
Serial.println(remoteAddress[3]);

Serial.print(F("Socket status (TCP sockets only): "));
SARA_R5_tcp_socket_status_t socketStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ void processSocketData(int socket, const char *theData, int length, IPAddress re
Serial.print(F("Data received on socket "));
Serial.print(socket);
Serial.print(F(" from IP "));
Serial.print(remoteAddress.toString());
Serial.print(remoteAddress[0]);
Serial.print(F("."));
Serial.print(remoteAddress[1]);
Serial.print(F("."));
Serial.print(remoteAddress[2]);
Serial.print(F("."));
Serial.print(remoteAddress[3]);
Serial.print(F(" using port "));
Serial.print(remotePort);
Serial.print(F(" :"));
Expand All @@ -148,18 +154,10 @@ void processSocketData(int socket, const char *theData, int length, IPAddress re
{
if (pingCount[connection] < pingPongLimit)
{
// Use the const char * version
//const char ping[] = { 0x00, 0x01, 0x02, 0x03 };
//mySARA.socketWriteUDP(socket, remoteAddress, remotePort, ping, 4); // Send the "Ping"
// Use the const char * version for binary data
const char ping[] = { 0x00, 0x01, 0x02, 0x03 };
mySARA.socketWriteUDP(socket, remoteAddress, remotePort, ping, 4); // Send the "Ping"

// Or use the String version. Both are OK for binary data.
String ping = "";
ping.concat('\0'); // Construct the ping in a binary-friendly way
ping.concat('\1');
ping.concat('\2');
ping.concat('\3');
mySARA.socketWriteUDP(socket, remoteAddress.toString(), remotePort, ping); // Send the "Ping"

pingCount[connection]++;
}
}
Expand Down Expand Up @@ -196,7 +194,13 @@ void processPSDAction(int result, IPAddress ip)
if (result == 0)
Serial.print(F(" (success)"));
Serial.print(F(" IP Address: \""));
Serial.print(ip.toString());
Serial.print(ip[0]);
Serial.print(F("."));
Serial.print(ip[1]);
Serial.print(F("."));
Serial.print(ip[2]);
Serial.print(F("."));
Serial.print(ip[3]);
Serial.println(F("\""));
}

Expand Down Expand Up @@ -292,7 +296,13 @@ void setup()
IPAddress myAddress;
mySARA.getNetworkAssignedIPAddress(0, &myAddress);
Serial.print(F("\r\nMy IP Address is: "));
Serial.println(myAddress.toString());
Serial.print(myAddress[0]);
Serial.print(F("."));
Serial.print(myAddress[1]);
Serial.print(F("."));
Serial.print(myAddress[2]);
Serial.print(F("."));
Serial.println(myAddress[3]);

// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Expand Down Expand Up @@ -344,7 +354,13 @@ void setup()
}

Serial.print(F("Remote address is "));
Serial.println(theAddress.toString());
Serial.print(theAddress[0]);
Serial.print(F("."));
Serial.print(theAddress[1]);
Serial.print(F("."));
Serial.print(theAddress[2]);
Serial.print(F("."));
Serial.println(theAddress[3]);

// Open the sockets
for (int i = 0; i < numConnections; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,62 @@ void prettyPrintString(String theString) // Pretty-print a String in HEX and ASC

Serial.println();
}

//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

void prettyPrintChars(char *theData, int theLength) // Pretty-print char data in HEX and ASCII format
{
Serial.println();
Serial.print(F("String length is "));
Serial.print(theLength);
Serial.print(F(" (0x"));
Serial.print(theLength, HEX);
Serial.println(F(")"));
Serial.println();

for (int i = 0; i < theLength; i += 16)
{
if (i < 10000) Serial.print(F("0"));
if (i < 1000) Serial.print(F("0"));
if (i < 100) Serial.print(F("0"));
if (i < 10) Serial.print(F("0"));
Serial.print(i);

Serial.print(F(" 0x"));

if (i < 0x1000) Serial.print(F("0"));
if (i < 0x100) Serial.print(F("0"));
if (i < 0x10) Serial.print(F("0"));
Serial.print(i, HEX);

Serial.print(F(" "));

int j;
for (j = 0; ((i + j) < theLength) && (j < 16); j++)
{
if (theData[i + j] < 0x10) Serial.print(F("0"));
Serial.print(theData[i + j], HEX);
Serial.print(F(" "));
}

if (((i + j) == theLength) && (j < 16))
{
for (int k = 0; k < (16 - (theLength % 16)); k++)
{
Serial.print(F(" "));
}
}

for (j = 0; ((i + j) < theLength) && (j < 16); j++)
{
if ((theData[i + j] >= 0x20) && (theData[i + j] <= 0x7E))
Serial.write(theData[i + j]);
else
Serial.print(F("."));
}

Serial.println();
}

Serial.println();
}
Loading