Skip to content

Commit 3491da0

Browse files
committed
Add getNetworkAssignedIPAddress
1 parent 2d4e399 commit 3491da0

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3509,6 +3509,58 @@ SARA_R5_error_t SARA_R5::activatePDPcontext(bool status, int cid)
35093509
return err;
35103510
}
35113511

3512+
SARA_R5_error_t SARA_R5::getNetworkAssignedIPAddress(int profile, IPAddress *address)
3513+
{
3514+
char *command;
3515+
char *response;
3516+
SARA_R5_error_t err;
3517+
int scanNum;
3518+
int profileStore = 0;
3519+
int paramVals[4];
3520+
3521+
command = sara_r5_calloc_char(strlen(SARA_R5_NETWORK_ASSIGNED_DATA) + 16);
3522+
if (command == NULL)
3523+
return SARA_R5_ERROR_OUT_OF_MEMORY;
3524+
sprintf(command, "%s=%d,0", SARA_R5_NETWORK_ASSIGNED_DATA, profile);
3525+
3526+
response = sara_r5_calloc_char(strlen(SARA_R5_NETWORK_ASSIGNED_DATA) + 32);
3527+
if (response == NULL)
3528+
{
3529+
free(command);
3530+
return SARA_R5_ERROR_OUT_OF_MEMORY;
3531+
}
3532+
3533+
err = sendCommandWithResponse(command, SARA_R5_RESPONSE_OK, response,
3534+
SARA_R5_STANDARD_RESPONSE_TIMEOUT);
3535+
3536+
if (err == SARA_R5_ERROR_SUCCESS)
3537+
{
3538+
scanNum = sscanf(response, "+UPSND: %d,0,\"%d.%d.%d.%d\"",
3539+
&profileStore,
3540+
&paramVals[0], &paramVals[1], &paramVals[2], &paramVals[3]);
3541+
if (scanNum != 5)
3542+
{
3543+
if (_printDebug == true)
3544+
{
3545+
_debugPort->print(F("getNetworkAssignedIPAddress: error: scanNum is "));
3546+
_debugPort->println(scanNum);
3547+
}
3548+
free(command);
3549+
free(response);
3550+
return SARA_R5_ERROR_UNEXPECTED_RESPONSE;
3551+
}
3552+
3553+
IPAddress tempAddress = { (uint8_t)paramVals[0], (uint8_t)paramVals[1],
3554+
(uint8_t)paramVals[2], (uint8_t)paramVals[3] };
3555+
*address = tempAddress;
3556+
}
3557+
3558+
free(command);
3559+
free(response);
3560+
3561+
return err;
3562+
}
3563+
35123564
bool SARA_R5::isGPSon(void)
35133565
{
35143566
SARA_R5_error_t err;

src/SparkFun_u-blox_SARA-R5_Arduino_Library.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ const char SARA_R5_MESSAGE_PDP_CONFIG[] = "+UPSD"; // Packet switched
131131
const char SARA_R5_MESSAGE_PDP_ACTION[] = "+UPSDA"; // Perform the action for the specified PSD profile
132132
const char SARA_R5_MESSAGE_PDP_CONTEXT_ACTIVATE[] = "+CGACT"; // Activates or deactivates the specified PDP context
133133
const char SARA_R5_MESSAGE_ENTER_PPP[] = "D";
134+
const char SARA_R5_NETWORK_ASSIGNED_DATA[] = "+UPSND"; // Packet switched network-assigned data
134135
// ### GPIO
135136
const char SARA_R5_COMMAND_GPIO[] = "+UGPIOC"; // GPIO Configuration
136137
// ### IP
@@ -702,7 +703,7 @@ class SARA_R5 : public Print
702703
SARA_R5_error_t setPDPconfiguration(int profile, SARA_R5_pdp_configuration_parameter_t parameter, IPAddress value); // Set parameters in the chosen PSD profile
703704
SARA_R5_error_t performPDPaction(int profile, SARA_R5_pdp_actions_t action); // Performs the requested action for the specified PSD profile.
704705
SARA_R5_error_t activatePDPcontext(bool status, int cid = -1); // Activates or deactivates the specified PDP context. Default to all (cid = -1)
705-
SARA_R5_error_t getNetworkAssignedIPAddress(int profile, IPAddress *address);
706+
SARA_R5_error_t getNetworkAssignedIPAddress(int profile, IPAddress *address); // Get the dynamic IP address assigned during PDP context activation
706707

707708
// GPS
708709
typedef enum

0 commit comments

Comments
 (0)