Skip to content

Non blocking connect #31

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
11 changes: 8 additions & 3 deletions src/ArduinoCellular.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ bool ArduinoCellular::connect(String apn, String username, String password, bool
return true;
}

if(connectToGPRS(apn.c_str(), username.c_str(), password.c_str())){
if(connectToGPRS(apn.c_str(), username.c_str(), password.c_str(), waitForever)){
auto response = this->sendATCommand("+QIDNSCFG=1,\"8.8.8.8\",\"8.8.4.4\"");

if(response.indexOf("OK") != -1){
Expand Down Expand Up @@ -187,11 +187,16 @@ bool ArduinoCellular::isConnectedToOperator(){
return modem.isNetworkConnected();
}

bool ArduinoCellular::connectToGPRS(const char * apn, const char * gprsUser, const char * gprsPass){
bool ArduinoCellular::connectToGPRS(const char * apn, const char * gprsUser, const char * gprsPass, bool waitForever){
if(this->debugStream != nullptr){
this->debugStream->println("Connecting to 4G network...");
}
while(!modem.gprsConnect(apn, gprsUser, gprsPass)) {

if(!waitForever) {
return false;
}

if(this->debugStream != nullptr){
this->debugStream->print(".");
}
Expand Down Expand Up @@ -243,7 +248,7 @@ bool ArduinoCellular::awaitNetworkRegistration(bool waitForever){
this->debugStream->println("Waiting for network registration...");
}
while (!modem.waitForNetwork(waitForNetworkTimeout)) {

if(!waitForever) {
return false;
}
Expand Down
3 changes: 1 addition & 2 deletions src/ArduinoCellular.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,7 @@ class ArduinoCellular {
SimStatus getSimStatus();

private:
bool connectToGPRS(const char * apn, const char * gprsUser, const char * gprsPass);

bool connectToGPRS(const char * apn, const char * gprsUser, const char * gprsPass, bool waitForever = true);

/**
* @brief Waits for network registration. (Blocking call)
Expand Down
Loading