Skip to content

Commit 5996b74

Browse files
committed
Add deleteFile
1 parent 080a36f commit 5996b74

File tree

5 files changed

+46
-9
lines changed

5 files changed

+46
-9
lines changed

examples/SARA-R5_Example12_AssistNowOnline/SARA-R5_AssistNow_Online.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void processHTTPcommandResult(int profile, int command, int result)
4949

5050
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
5151

52-
bool getAssistNowOnlineData(String theFile)
52+
bool getAssistNowOnlineData(String theFilename)
5353
{
5454
// Use HTTP GET to receive the AssistNow_Online data. Store it in the SARA-R5's internal file system.
5555

@@ -75,7 +75,7 @@ bool getAssistNowOnlineData(String theFile)
7575
Serial.println(theRequestStr);
7676

7777
Serial.print(F("getAssistNowOnlineData: the AssistNow data will be stored in: "));
78-
Serial.println(theFile);
78+
Serial.println(theFilename);
7979

8080
// Reset HTTP profile 0
8181
mySARA.resetHTTPprofile(0);
@@ -92,7 +92,7 @@ bool getAssistNowOnlineData(String theFile)
9292
httpResultSeen = false; // Clear the flag
9393

9494
// HTTP GET
95-
mySARA.sendHTTPGET(0, theRequestStr, theFile);
95+
mySARA.sendHTTPGET(0, theRequestStr, theFilename);
9696

9797
// Wait for 20 seconds while calling mySARA.bufferedPoll() to see the HTTP result.
9898
Serial.print(F("getAssistNowOnlineData: Waiting up to 20 seconds for the HTTP Result"));
@@ -114,7 +114,7 @@ bool getAssistNowOnlineData(String theFile)
114114
}
115115

116116
int fileSize;
117-
if (mySARA.getFileSize(theFile, &fileSize) != SARA_R5_SUCCESS)
117+
if (mySARA.getFileSize(theFilename, &fileSize) != SARA_R5_SUCCESS)
118118
{
119119
Serial.print(F("getAssistNowOnlineData: No file written?!"));
120120
return false;

examples/SARA-R5_Example12_AssistNowOnline/SARA-R5_Example12_AssistNowOnline.ino

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ void setup()
156156

157157
// Request the AssistNow data from the server. Data is stored in the SARA's file system.
158158

159-
String theFile = "assistnow_online.ubx"; // The file that will contain the AssistNow Online data
159+
String theFilename = "assistnow_online.ubx"; // The file that will contain the AssistNow Online data
160160

161-
if (getAssistNowOnlineData(theFile) == false) // See SARA-R5_AssistNow_Online.ino
161+
if (getAssistNowOnlineData(theFilename) == false) // See SARA-R5_AssistNow_Online.ino
162162
{
163163
Serial.println(F("getAssistNowOnlineData failed! Freezing..."));
164164
while (1)
@@ -171,7 +171,7 @@ void setup()
171171

172172
// Read the data from file
173173
String theAssistData = "";
174-
if (mySARA.getFileContents(theFile, &theAssistData) != SARA_R5_SUCCESS)
174+
if (mySARA.getFileContents(theFilename, &theAssistData) != SARA_R5_SUCCESS)
175175
{
176176
Serial.println(F("getFileContents failed! Freezing..."));
177177
while (1)
@@ -198,6 +198,13 @@ void setup()
198198

199199
// Set setI2CpollingWait to 125ms to avoid pounding the I2C bus
200200
myGNSS.setI2CpollingWait(125);
201+
202+
// Delete the file after use. This is optional as the SARA will automatically overwrite the file.
203+
// And you might want to reuse it? AssistNow Online data is valid for 2-4 hours.
204+
//if (mySARA.deleteFile(theFilename) != SARA_R5_SUCCESS)
205+
//{
206+
// Serial.println(F("Warning: deleteFile failed!"));
207+
//}
201208
}
202209

203210
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ gpsRequest KEYWORD2
164164
gpsAidingServerConf KEYWORD2
165165
getFileContents KEYWORD2
166166
getFileSize KEYWORD2
167+
deleteFile KEYWORD2
167168
functionality KEYWORD2
168169
sendCustomCommandWithResponse KEYWORD2
169170

src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4133,6 +4133,31 @@ SARA_R5_error_t SARA_R5::getFileSize(String filename, int *size)
41334133
return err;
41344134
}
41354135

4136+
SARA_R5_error_t SARA_R5::deleteFile(String filename)
4137+
{
4138+
SARA_R5_error_t err;
4139+
char *command;
4140+
4141+
command = sara_r5_calloc_char(strlen(SARA_R5_FILE_SYSTEM_DELETE_FILE) + filename.length() + 8);
4142+
if (command == NULL)
4143+
return SARA_R5_ERROR_OUT_OF_MEMORY;
4144+
sprintf(command, "%s=\"%s\"", SARA_R5_FILE_SYSTEM_DELETE_FILE, filename.c_str());
4145+
4146+
err = sendCommandWithResponse(command, SARA_R5_RESPONSE_OK, NULL, SARA_R5_STANDARD_RESPONSE_TIMEOUT);
4147+
4148+
if (err != SARA_R5_ERROR_SUCCESS)
4149+
{
4150+
if (_printDebug == true)
4151+
{
4152+
_debugPort->print(F("deleteFile: Fail: Error: "));
4153+
_debugPort->println(err);
4154+
}
4155+
}
4156+
4157+
free(command);
4158+
return err;
4159+
}
4160+
41364161
SARA_R5_error_t SARA_R5::modulePowerOff(void)
41374162
{
41384163
SARA_R5_error_t err;

src/SparkFun_u-blox_SARA-R5_Arduino_Library.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,10 @@ const char SARA_R5_GNSS_CONFIGURE_SENSOR[] = "+ULOCGNSS"; // Configure GNSS s
167167
const char SARA_R5_GNSS_CONFIGURE_LOCATION[] = "+ULOCCELL"; // Configure cellular location sensor (CellLocate®)
168168
const char SARA_R5_AIDING_SERVER_CONFIGURATION[] = "+UGSRV"; // Configure aiding server (CellLocate®)
169169
// ### File System
170-
const char SARA_R5_FILE_SYSTEM_READ_FILE[] = "+URDFILE"; // Read a file
171-
const char SARA_R5_FILE_SYSTEM_LIST_FILES[] = "+ULSTFILE"; // List of files, size of file, etc.
170+
// TO DO: Add support for file tags. Default tag to USER
171+
const char SARA_R5_FILE_SYSTEM_READ_FILE[] = "+URDFILE"; // Read a file
172+
const char SARA_R5_FILE_SYSTEM_LIST_FILES[] = "+ULSTFILE"; // List of files, size of file, etc.
173+
const char SARA_R5_FILE_SYSTEM_DELETE_FILE[] = "+UDELFILE"; // Delete a file
172174
// ### Response
173175
const char SARA_R5_RESPONSE_OK[] = "OK\r\n";
174176
const char SARA_R5_RESPONSE_ERROR[] = "ERROR\r\n";
@@ -786,8 +788,10 @@ class SARA_R5 : public Print
786788
unsigned int gnssTypes = 65, unsigned int mode = 0, unsigned int dataType = 15);
787789

788790
// File system
791+
// TO DO: add full support for file tags. Default tag to USER
789792
SARA_R5_error_t getFileContents(String filename, String *contents);
790793
SARA_R5_error_t getFileSize(String filename, int *size);
794+
SARA_R5_error_t deleteFile(String filename);
791795

792796
// Functionality
793797
SARA_R5_error_t functionality(SARA_R5_functionality_t function = FULL_FUNCTIONALITY);

0 commit comments

Comments
 (0)