@@ -89,8 +89,7 @@ nsapi_error_t UBLOX_AT_CellularContext::open_data_channel()
8989 _at.cmd_start (" AT+UPSND=" PROFILE " ,8" );
9090 _at.cmd_stop ();
9191 _at.resp_start (" +UPSND:" );
92- _at.read_int ();
93- _at.read_int ();
92+ _at.skip_param (2 );
9493 active = _at.read_int ();
9594 _at.resp_stop ();
9695
@@ -133,7 +132,7 @@ bool UBLOX_AT_CellularContext::activate_profile(const char *apn,
133132 // Set up the APN
134133 if (apn) {
135134 success = false ;
136- _at.cmd_start (" AT+UPSD=0 ,1," );
135+ _at.cmd_start (" AT+UPSD=" PROFILE " ,1," );
137136 _at.write_string (apn);
138137 _at.cmd_stop ();
139138 _at.resp_start ();
@@ -183,7 +182,7 @@ bool UBLOX_AT_CellularContext::activate_profile(const char *apn,
183182 for (int protocol = nsapi_security_to_modem_security (NSAPI_SECURITY_NONE);
184183 success && (protocol <= nsapi_security_to_modem_security (NSAPI_SECURITY_CHAP)); protocol++) {
185184 if ((_auth == NSAPI_SECURITY_UNKNOWN) || (nsapi_security_to_modem_security (_auth) == protocol)) {
186- _at.cmd_start (" AT+UPSD=0 ,6," );
185+ _at.cmd_start (" AT+UPSD=" PROFILE " ,6," );
187186 _at.write_int (protocol);
188187 _at.cmd_stop ();
189188 _at.resp_start ();
@@ -192,14 +191,29 @@ bool UBLOX_AT_CellularContext::activate_profile(const char *apn,
192191 if (_at.get_last_error () == NSAPI_ERROR_OK) {
193192 // Activate, wait upto 30 seconds for the connection to be made
194193 _at.set_at_timeout (30000 );
195- _at.cmd_start (" AT+UPSDA=0 ,3" );
194+ _at.cmd_start (" AT+UPSDA=" PROFILE " ,3" );
196195 _at.cmd_stop ();
197196 _at.resp_start ();
198197 _at.resp_stop ();
199198 _at.restore_at_timeout ();
200199
201200 if (_at.get_last_error () == NSAPI_ERROR_OK) {
202- activated = true ;
201+ Timer t1;
202+ t1.start ();
203+ while (!(t1.read () >= 180 )) {
204+ _at.cmd_start (" AT+UPSND=" PROFILE " ,8" );
205+ _at.cmd_stop ();
206+ _at.resp_start (" +UPSND:" );
207+ _at.skip_param (2 );
208+ _at.read_int () ? activated = true : activated = false ;
209+ _at.resp_stop ();
210+
211+ if (activated) { // If context is activated, exit while loop and return status
212+ break ;
213+ }
214+ wait_ms (5000 ); // Wait for 5 seconds and then try again
215+ }
216+ t1.stop ();
203217 }
204218 }
205219 }
0 commit comments