Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions examples/ModemTest/ModemTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const uint8_t GSM_UART_RX = 41;
const uint8_t GSM_UART_TX = 42;
const uint16_t GSM_UART_BUFFER_SIZE = 1024;
const char* GSM_APN = "internet";
const char* GSM_USER = nullptr;
const char* GSM_PASS = nullptr;
const char* GSM_USER = "";
const char* GSM_PASS = "";

// TCP configuration
const char* TCP_SERVER = "api.ipify.org";
Expand Down
1 change: 1 addition & 0 deletions src/SIM7600Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ namespace SIM7600 {
X(EmptyLine) \
X(GPSNotFixed) \
X(InvalidAntennaVoltage) \
X(InvalidAPN) \
X(InvalidBuffer) \
X(InvalidCallback) \
X(InvalidClientName) \
Expand Down
32 changes: 28 additions & 4 deletions src/SIM7600Modem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,17 +813,41 @@ bool Modem::isCurrentlyRegisteredOnNetwork() const { return (_registered_on_netw
RegStatus Modem::getCurrentRegistrationStatus() const { return _current_reg_status; }

Status Modem::configureAPN(const char* apn, const char* user, const char* password) {
if (apn == nullptr) {
SIM7600_LOGE(tag, "APN cannot be null");
return Status::InvalidAPN;
}

const char* user_str;
const char* pass_str;

if (user == nullptr) {
user_str = nullptr;
} else if (strlen(user) == 0) {
user_str = nullptr;
} else {
user_str = user;
}

if (password == nullptr) {
pass_str = nullptr;
} else if (strlen(password) == 0) {
pass_str = nullptr;
} else {
pass_str = password;
}

SIM7600_LOGI(tag,
"Configuring APN: %s, USER: %s, PASS: %s",
apn,
user ? user : "-empty-",
password ? password : "-empty-");
(user_str != nullptr) ? user_str : "-empty-",
(pass_str != nullptr) ? pass_str : "-empty-");

Status status;

// Set authentication if needed
if (user != nullptr && password != nullptr) {
status = sendATCmd("AT+CGAUTH=1,1,\"%s\",\"%s\"", password, user);
if (user_str != nullptr && pass_str != nullptr) {
status = sendATCmd("AT+CGAUTH=1,1,\"%s\",\"%s\"", pass_str, user_str);
if (status != Status::Success) return status;

status = waitForResponse(AT_OK);
Expand Down
6 changes: 3 additions & 3 deletions src/SIM7600Modem.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,9 @@ class Modem {

/**
* @brief Configure the APN settings for GPRS connection.
* @param apn Access Point Name.
* @param user Username for APN, if required.
* @param password Password for APN, if required.
* @param apn Access Point Name. Cannot be nullptr or an empty string.
* @param user Username for APN, if required. Can be nullptr or an empty string.
* @param password Password for APN, if required. Can be nullptr or an empty string.
* @return Status::Success on success, error code otherwise.
*/
Status configureAPN(const char* apn, const char* user = nullptr, const char* password = nullptr);
Expand Down