Skip to content

Commit

Permalink
Added APN username and password setting
Browse files Browse the repository at this point in the history
  • Loading branch information
stanleyhuangyc committed Oct 18, 2023
1 parent 938d072 commit bf282f4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions libraries/FreematicsPlus/FreematicsNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ void CellSIMCOM::end()
}
}

bool CellSIMCOM::setup(const char* apn, unsigned int timeout)
bool CellSIMCOM::setup(const char* apn, const char* username, const char* password, unsigned int timeout)
{
uint32_t t = millis();
bool success = false;
Expand Down Expand Up @@ -300,8 +300,11 @@ bool CellSIMCOM::setup(const char* apn, unsigned int timeout)

sendCommand("AT+CGNAPN\r");
if (apn && *apn) {
sprintf(m_buffer, "AT+CNCFG=0,0,\"%s\"\r", apn);
//sprintf(m_buffer, "AT+CNCFG=0,0,\"%s\",\"APN_USERNAME\",\"APN_PASSWORD\",3\r", apn);
if (username && password) {
sprintf(m_buffer, "AT+CNCFG=0,0,\"%s\",\"%s\",\"%s\",3\r", apn, username, password);
} else {
sprintf(m_buffer, "AT+CNCFG=0,0,\"%s\"\r", apn);
}
sendCommand(m_buffer);
}
sendCommand("AT+CNACT=0,1\r");
Expand Down Expand Up @@ -349,7 +352,10 @@ bool CellSIMCOM::setup(const char* apn, unsigned int timeout)
if (apn && *apn) {
sprintf(m_buffer, "AT+CGSOCKCONT=1,\"IP\",\"%s\"\r", apn);
sendCommand(m_buffer);
//sendCommand("AT+CSOCKAUTH=1,1,\"APN_PASSWORD\",\"APN_USERNAME\"\r");
if (username && password) {
sprintf(m_buffer, "AT+CSOCKAUTH=1,1,\"%s\",\"%s\"\r", username, password);
sendCommand(m_buffer);
}
}

sendCommand("AT+CSOCKSETPN=1\r");
Expand Down
2 changes: 1 addition & 1 deletion libraries/FreematicsPlus/FreematicsNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class CellSIMCOM
public:
virtual bool begin(CFreematics* device);
virtual void end();
virtual bool setup(const char* apn, unsigned int timeout = 30000);
virtual bool setup(const char* apn, const char* username = 0, const char* password = 0, unsigned int timeout = 30000);
virtual bool setGPS(bool on);
virtual String getIP();
int RSSI();
Expand Down

0 comments on commit bf282f4

Please sign in to comment.