17
17
#include " mbed.h"
18
18
#include " common_functions.h"
19
19
#include " UDPSocket.h"
20
- #include " OnboardCellularInterface.h"
21
20
#include " CellularLog.h"
22
21
23
22
#define UDP 0
41
40
// Number of retries /
42
41
#define RETRY_COUNT 3
43
42
44
-
45
-
46
- // CellularInterface object
47
- OnboardCellularInterface iface;
43
+ CellularBase *iface;
48
44
49
45
// Echo server hostname
50
46
const char *host_name = MBED_CONF_APP_ECHO_SERVER_HOSTNAME;
@@ -110,7 +106,7 @@ void dot_event()
110
106
{
111
107
while (true ) {
112
108
Thread::wait (4000 );
113
- if (!iface. is_connected ()) {
109
+ if (!iface-> is_connected ()) {
114
110
trace_mutex.lock ();
115
111
printf (" ." );
116
112
fflush (stdout);
@@ -129,8 +125,8 @@ nsapi_error_t do_connect()
129
125
nsapi_error_t retcode = NSAPI_ERROR_OK;
130
126
uint8_t retry_counter = 0 ;
131
127
132
- while (!iface. is_connected ()) {
133
- retcode = iface. connect ();
128
+ while (!iface-> is_connected ()) {
129
+ retcode = iface-> connect ();
134
130
if (retcode == NSAPI_ERROR_AUTH_FAILURE) {
135
131
print_function (" \n\n Authentication Failure. Exiting application\n " );
136
132
} else if (retcode == NSAPI_ERROR_OK) {
@@ -160,14 +156,14 @@ nsapi_error_t test_send_recv()
160
156
UDPSocket sock;
161
157
#endif
162
158
163
- retcode = sock.open (& iface);
159
+ retcode = sock.open (iface);
164
160
if (retcode != NSAPI_ERROR_OK) {
165
161
print_function (" UDPSocket.open() fails, code: %d\n " , retcode);
166
162
return -1 ;
167
163
}
168
164
169
165
SocketAddress sock_addr;
170
- retcode = iface. gethostbyname (host_name, &sock_addr);
166
+ retcode = iface-> gethostbyname (host_name, &sock_addr);
171
167
if (retcode != NSAPI_ERROR_OK) {
172
168
print_function (" Couldn't resolve remote host: %s, code: %d\n " , host_name, retcode);
173
169
return -1 ;
@@ -228,11 +224,14 @@ int main()
228
224
#else
229
225
dot_thread.start (dot_event);
230
226
#endif // #if MBED_CONF_MBED_TRACE_ENABLE
227
+ iface = CellularBase::get_default_instance ();
228
+ MBED_ASSERT (iface);
229
+
231
230
/* Set Pin code for SIM card */
232
- iface. set_sim_pin (MBED_CONF_APP_SIM_PIN_CODE);
231
+ iface-> set_sim_pin (MBED_CONF_APP_SIM_PIN_CODE);
233
232
234
233
/* Set network credentials here, e.g., APN */
235
- iface. set_credentials (MBED_CONF_APP_APN, MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD);
234
+ iface-> set_credentials (MBED_CONF_APP_APN, MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD);
236
235
237
236
nsapi_error_t retcode = NSAPI_ERROR_NO_CONNECTION;
238
237
0 commit comments