This is an example based on mbed-os cellular APIs that demonstrates a TCP or UDP echo transaction with a public echo server.

This code is forked from https://os.mbed.com/teams/mbed-os-examples/code/mbed-os-example-cellular/

This is an example showing how to use Skywire board with LE910-x module.

In this example, I had used the LE910-EUG module for 4G communication. Mbed OS code wasn't changed for LE910-x, because the Telit' HE910 is included mainline code on Mbed OS already. HE910 and LE910 are most similar. Therefore you can use LE910 via HE910 driver. Please check to configure of mbed_app.json, and initialize code for Skywire board of main.cpp.

Open mbed_app.json, you need to define a UART for the MCU to communicate with the xE910 module.

            "TELIT_HE910.tx"                 : "D1",
            "TELIT_HE910.rx"                 : "D0",
            "TELIT_HE910.provide-default"    : true

If you are using Pelion CM, make the following settings:

            "nsapi.default-cellular-apn"     : "\"stream.co.uk\"",
            "nsapi.default-cellular-username": "\"streamip\"",
            "nsapi.default-cellular-password": "\"streamip\"",

For your information, please see Pelion Connectivity Quick start guide.

320

You can find Skywire sensor shield information though NimbeLink site.

Tested with

  • DISCO_L475VG_IOT01A
  • K64F

1. Import the application into your desktop:

 mbed import https://os.mbed.com/users/Daniel_Lee/code/mbed-os-example-cellular-le910/

 cd mbed-os-example-cellular-le910

2. Compile and program:

mbed compile -t GCC_ARM -m DISCO_L475VG_IOT01A

(supported toolchains : GCC_ARM / ARM / IAR)

3. Download binary to a target board

4. Result

mbed-os-example-cellular


Built: Feb  7 2020, 07:02:27
Starting Skywire board with LE910-EUG Demo...
Waiting for Skywire to Boot...
Wait 15 seconds..
Establishing connection


Connection Established.
TCP: connected with echo.mbedcloudtesting.com server
TCP: Sent 4 Bytes to echo.mbedcloudtesting.com
Received from echo server 4 Bytes


Success. Exiting 
Committer:
Daniel_Lee
Date:
Thu Feb 13 12:16:57 2020 +0000
Revision:
52:a2630c9c1123
Parent:
51:8d0212a4b805
Initialize APN/Username/Password of cellular

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:4611f6cf2413 1 /*
mbed_official 0:4611f6cf2413 2 * Copyright (c) 2017 ARM Limited. All rights reserved.
mbed_official 0:4611f6cf2413 3 * SPDX-License-Identifier: Apache-2.0
mbed_official 0:4611f6cf2413 4 * Licensed under the Apache License, Version 2.0 (the License); you may
mbed_official 0:4611f6cf2413 5 * not use this file except in compliance with the License.
mbed_official 0:4611f6cf2413 6 * You may obtain a copy of the License at
mbed_official 0:4611f6cf2413 7 *
mbed_official 0:4611f6cf2413 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 0:4611f6cf2413 9 *
mbed_official 0:4611f6cf2413 10 * Unless required by applicable law or agreed to in writing, software
mbed_official 0:4611f6cf2413 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
mbed_official 0:4611f6cf2413 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 0:4611f6cf2413 13 * See the License for the specific language governing permissions and
mbed_official 0:4611f6cf2413 14 * limitations under the License.
mbed_official 0:4611f6cf2413 15 */
mbed_official 0:4611f6cf2413 16
mbed_official 0:4611f6cf2413 17 #include "mbed.h"
mbed_official 0:4611f6cf2413 18 #include "common_functions.h"
mbed_official 40:c46ee5b71843 19 #include "CellularNonIPSocket.h"
mbed_official 40:c46ee5b71843 20 #include "CellularDevice.h"
mbed_official 0:4611f6cf2413 21 #include "UDPSocket.h"
mbed_official 6:5678c0b6f74e 22 #include "CellularLog.h"
mbed_official 0:4611f6cf2413 23
mbed_official 0:4611f6cf2413 24 #define UDP 0
mbed_official 0:4611f6cf2413 25 #define TCP 1
mbed_official 40:c46ee5b71843 26 #define NONIP 2
mbed_official 0:4611f6cf2413 27
mbed_official 0:4611f6cf2413 28 // Number of retries /
mbed_official 0:4611f6cf2413 29 #define RETRY_COUNT 3
mbed_official 0:4611f6cf2413 30
mbed_official 28:232da3ce8a88 31 NetworkInterface *iface;
mbed_official 0:4611f6cf2413 32
mbed_official 0:4611f6cf2413 33 // Echo server hostname
mbed_official 11:23ea0907186e 34 const char *host_name = MBED_CONF_APP_ECHO_SERVER_HOSTNAME;
mbed_official 0:4611f6cf2413 35
mbed_official 0:4611f6cf2413 36 // Echo server port (same for TCP and UDP)
mbed_official 11:23ea0907186e 37 const int port = MBED_CONF_APP_ECHO_SERVER_PORT;
mbed_official 0:4611f6cf2413 38
mbed_official 6:5678c0b6f74e 39 static rtos::Mutex trace_mutex;
mbed_official 6:5678c0b6f74e 40
mbed_official 6:5678c0b6f74e 41 #if MBED_CONF_MBED_TRACE_ENABLE
mbed_official 6:5678c0b6f74e 42 static void trace_wait()
mbed_official 6:5678c0b6f74e 43 {
mbed_official 6:5678c0b6f74e 44 trace_mutex.lock();
mbed_official 6:5678c0b6f74e 45 }
mbed_official 6:5678c0b6f74e 46
mbed_official 6:5678c0b6f74e 47 static void trace_release()
mbed_official 6:5678c0b6f74e 48 {
mbed_official 6:5678c0b6f74e 49 trace_mutex.unlock();
mbed_official 6:5678c0b6f74e 50 }
mbed_official 6:5678c0b6f74e 51
mbed_official 6:5678c0b6f74e 52 static char time_st[50];
mbed_official 6:5678c0b6f74e 53
mbed_official 6:5678c0b6f74e 54 static char* trace_time(size_t ss)
mbed_official 6:5678c0b6f74e 55 {
mbed_official 6:5678c0b6f74e 56 snprintf(time_st, 49, "[%08llums]", Kernel::get_ms_count());
mbed_official 6:5678c0b6f74e 57 return time_st;
mbed_official 6:5678c0b6f74e 58 }
mbed_official 6:5678c0b6f74e 59
mbed_official 6:5678c0b6f74e 60 static void trace_open()
mbed_official 6:5678c0b6f74e 61 {
mbed_official 6:5678c0b6f74e 62 mbed_trace_init();
mbed_official 6:5678c0b6f74e 63 mbed_trace_prefix_function_set( &trace_time );
mbed_official 6:5678c0b6f74e 64
mbed_official 6:5678c0b6f74e 65 mbed_trace_mutex_wait_function_set(trace_wait);
mbed_official 6:5678c0b6f74e 66 mbed_trace_mutex_release_function_set(trace_release);
mbed_official 11:23ea0907186e 67
mbed_official 11:23ea0907186e 68 mbed_cellular_trace::mutex_wait_function_set(trace_wait);
mbed_official 11:23ea0907186e 69 mbed_cellular_trace::mutex_release_function_set(trace_release);
mbed_official 6:5678c0b6f74e 70 }
mbed_official 6:5678c0b6f74e 71
mbed_official 6:5678c0b6f74e 72 static void trace_close()
mbed_official 6:5678c0b6f74e 73 {
mbed_official 11:23ea0907186e 74 mbed_cellular_trace::mutex_wait_function_set(NULL);
mbed_official 11:23ea0907186e 75 mbed_cellular_trace::mutex_release_function_set(NULL);
mbed_official 11:23ea0907186e 76
mbed_official 6:5678c0b6f74e 77 mbed_trace_free();
mbed_official 6:5678c0b6f74e 78 }
mbed_official 6:5678c0b6f74e 79 #endif // #if MBED_CONF_MBED_TRACE_ENABLE
mbed_official 6:5678c0b6f74e 80
mbed_official 2:0f644d6045cf 81 Thread dot_thread(osPriorityNormal, 512);
mbed_official 0:4611f6cf2413 82
mbed_official 6:5678c0b6f74e 83 void print_function(const char *format, ...)
mbed_official 0:4611f6cf2413 84 {
mbed_official 6:5678c0b6f74e 85 trace_mutex.lock();
mbed_official 6:5678c0b6f74e 86 va_list arglist;
mbed_official 6:5678c0b6f74e 87 va_start( arglist, format );
mbed_official 6:5678c0b6f74e 88 vprintf(format, arglist);
mbed_official 6:5678c0b6f74e 89 va_end( arglist );
mbed_official 6:5678c0b6f74e 90 trace_mutex.unlock();
mbed_official 0:4611f6cf2413 91 }
mbed_official 0:4611f6cf2413 92
mbed_official 0:4611f6cf2413 93 void dot_event()
mbed_official 0:4611f6cf2413 94 {
mbed_official 0:4611f6cf2413 95 while (true) {
mbed_official 26:348eec457e58 96 ThisThread::sleep_for(4000);
mbed_official 28:232da3ce8a88 97 if (iface && iface->get_connection_status() == NSAPI_STATUS_GLOBAL_UP) {
mbed_official 13:4bea5334b419 98 break;
mbed_official 13:4bea5334b419 99 } else {
mbed_official 6:5678c0b6f74e 100 trace_mutex.lock();
mbed_official 6:5678c0b6f74e 101 printf(".");
mbed_official 6:5678c0b6f74e 102 fflush(stdout);
mbed_official 6:5678c0b6f74e 103 trace_mutex.unlock();
mbed_official 0:4611f6cf2413 104 }
mbed_official 0:4611f6cf2413 105 }
mbed_official 0:4611f6cf2413 106 }
mbed_official 0:4611f6cf2413 107
mbed_official 0:4611f6cf2413 108 /**
mbed_official 0:4611f6cf2413 109 * Connects to the Cellular Network
mbed_official 0:4611f6cf2413 110 */
mbed_official 0:4611f6cf2413 111 nsapi_error_t do_connect()
mbed_official 0:4611f6cf2413 112 {
mbed_official 6:5678c0b6f74e 113 nsapi_error_t retcode = NSAPI_ERROR_OK;
mbed_official 0:4611f6cf2413 114 uint8_t retry_counter = 0;
mbed_official 0:4611f6cf2413 115
mbed_official 28:232da3ce8a88 116 while (iface->get_connection_status() != NSAPI_STATUS_GLOBAL_UP) {
mbed_official 11:23ea0907186e 117 retcode = iface->connect();
mbed_official 0:4611f6cf2413 118 if (retcode == NSAPI_ERROR_AUTH_FAILURE) {
mbed_official 0:4611f6cf2413 119 print_function("\n\nAuthentication Failure. Exiting application\n");
mbed_official 6:5678c0b6f74e 120 } else if (retcode == NSAPI_ERROR_OK) {
mbed_official 6:5678c0b6f74e 121 print_function("\n\nConnection Established.\n");
mbed_official 6:5678c0b6f74e 122 } else if (retry_counter > RETRY_COUNT) {
mbed_official 6:5678c0b6f74e 123 print_function("\n\nFatal connection failure: %d\n", retcode);
mbed_official 6:5678c0b6f74e 124 } else {
mbed_official 6:5678c0b6f74e 125 print_function("\n\nCouldn't connect: %d, will retry\n", retcode);
mbed_official 0:4611f6cf2413 126 retry_counter++;
mbed_official 0:4611f6cf2413 127 continue;
mbed_official 0:4611f6cf2413 128 }
mbed_official 0:4611f6cf2413 129 break;
mbed_official 0:4611f6cf2413 130 }
mbed_official 6:5678c0b6f74e 131 return retcode;
mbed_official 0:4611f6cf2413 132 }
mbed_official 0:4611f6cf2413 133
mbed_official 0:4611f6cf2413 134 /**
mbed_official 40:c46ee5b71843 135 * Opens:
mbed_official 40:c46ee5b71843 136 * - UDP or TCP socket with the given echo server and performs an echo
mbed_official 40:c46ee5b71843 137 * transaction retrieving current.
mbed_official 40:c46ee5b71843 138 * - Cellular Non-IP socket for which the data delivery path is decided
mbed_official 40:c46ee5b71843 139 * by network's control plane CIoT optimisation setup, for the given APN.
mbed_official 0:4611f6cf2413 140 */
mbed_official 0:4611f6cf2413 141 nsapi_error_t test_send_recv()
mbed_official 0:4611f6cf2413 142 {
mbed_official 0:4611f6cf2413 143 nsapi_size_or_error_t retcode;
mbed_official 0:4611f6cf2413 144 #if MBED_CONF_APP_SOCK_TYPE == TCP
mbed_official 0:4611f6cf2413 145 TCPSocket sock;
mbed_official 40:c46ee5b71843 146 #elif MBED_CONF_APP_SOCK_TYPE == UDP
mbed_official 0:4611f6cf2413 147 UDPSocket sock;
mbed_official 40:c46ee5b71843 148 #elif MBED_CONF_APP_SOCK_TYPE == NONIP
mbed_official 40:c46ee5b71843 149 CellularNonIPSocket sock;
mbed_official 0:4611f6cf2413 150 #endif
mbed_official 0:4611f6cf2413 151
mbed_official 40:c46ee5b71843 152 #if MBED_CONF_APP_SOCK_TYPE == NONIP
mbed_official 40:c46ee5b71843 153 retcode = sock.open((CellularContext*)iface);
mbed_official 40:c46ee5b71843 154 #else
mbed_official 11:23ea0907186e 155 retcode = sock.open(iface);
mbed_official 40:c46ee5b71843 156 #endif
mbed_official 40:c46ee5b71843 157
mbed_official 0:4611f6cf2413 158 if (retcode != NSAPI_ERROR_OK) {
mbed_official 21:e356e039f917 159 #if MBED_CONF_APP_SOCK_TYPE == TCP
mbed_official 21:e356e039f917 160 print_function("TCPSocket.open() fails, code: %d\n", retcode);
mbed_official 40:c46ee5b71843 161 #elif MBED_CONF_APP_SOCK_TYPE == UDP
mbed_official 6:5678c0b6f74e 162 print_function("UDPSocket.open() fails, code: %d\n", retcode);
mbed_official 40:c46ee5b71843 163 #elif MBED_CONF_APP_SOCK_TYPE == NONIP
mbed_official 40:c46ee5b71843 164 print_function("CellularNonIPSocket.open() fails, code: %d\n", retcode);
mbed_official 21:e356e039f917 165 #endif
mbed_official 0:4611f6cf2413 166 return -1;
mbed_official 0:4611f6cf2413 167 }
mbed_official 0:4611f6cf2413 168
mbed_official 40:c46ee5b71843 169 int n = 0;
mbed_official 40:c46ee5b71843 170 const char *echo_string = "TEST";
mbed_official 40:c46ee5b71843 171 char recv_buf[4];
mbed_official 40:c46ee5b71843 172
mbed_official 40:c46ee5b71843 173 sock.set_timeout(15000);
mbed_official 40:c46ee5b71843 174
mbed_official 40:c46ee5b71843 175 #if MBED_CONF_APP_SOCK_TYPE == NONIP
mbed_official 42:cab443dff75e 176 retcode = sock.send((void*) echo_string, strlen(echo_string));
mbed_official 40:c46ee5b71843 177 if (retcode < 0) {
mbed_official 40:c46ee5b71843 178 print_function("CellularNonIPSocket.send() fails, code: %d\n", retcode);
mbed_official 40:c46ee5b71843 179 return -1;
mbed_official 40:c46ee5b71843 180 } else {
mbed_official 40:c46ee5b71843 181 print_function("CellularNonIPSocket: Sent %d Bytes\n", retcode);
mbed_official 40:c46ee5b71843 182 }
mbed_official 40:c46ee5b71843 183
mbed_official 40:c46ee5b71843 184 n = sock.recv((void*) recv_buf, sizeof(recv_buf));
mbed_official 40:c46ee5b71843 185
mbed_official 40:c46ee5b71843 186 #else
mbed_official 40:c46ee5b71843 187
mbed_official 0:4611f6cf2413 188 SocketAddress sock_addr;
mbed_official 11:23ea0907186e 189 retcode = iface->gethostbyname(host_name, &sock_addr);
mbed_official 0:4611f6cf2413 190 if (retcode != NSAPI_ERROR_OK) {
mbed_official 6:5678c0b6f74e 191 print_function("Couldn't resolve remote host: %s, code: %d\n", host_name, retcode);
mbed_official 0:4611f6cf2413 192 return -1;
mbed_official 0:4611f6cf2413 193 }
mbed_official 0:4611f6cf2413 194
mbed_official 0:4611f6cf2413 195 sock_addr.set_port(port);
mbed_official 0:4611f6cf2413 196
mbed_official 0:4611f6cf2413 197 #if MBED_CONF_APP_SOCK_TYPE == TCP
mbed_official 0:4611f6cf2413 198 retcode = sock.connect(sock_addr);
mbed_official 0:4611f6cf2413 199 if (retcode < 0) {
mbed_official 6:5678c0b6f74e 200 print_function("TCPSocket.connect() fails, code: %d\n", retcode);
mbed_official 0:4611f6cf2413 201 return -1;
mbed_official 0:4611f6cf2413 202 } else {
mbed_official 6:5678c0b6f74e 203 print_function("TCP: connected with %s server\n", host_name);
mbed_official 0:4611f6cf2413 204 }
mbed_official 42:cab443dff75e 205 retcode = sock.send((void*) echo_string, strlen(echo_string));
mbed_official 0:4611f6cf2413 206 if (retcode < 0) {
mbed_official 6:5678c0b6f74e 207 print_function("TCPSocket.send() fails, code: %d\n", retcode);
mbed_official 0:4611f6cf2413 208 return -1;
mbed_official 0:4611f6cf2413 209 } else {
mbed_official 6:5678c0b6f74e 210 print_function("TCP: Sent %d Bytes to %s\n", retcode, host_name);
mbed_official 0:4611f6cf2413 211 }
mbed_official 0:4611f6cf2413 212
mbed_official 0:4611f6cf2413 213 n = sock.recv((void*) recv_buf, sizeof(recv_buf));
mbed_official 0:4611f6cf2413 214 #else
mbed_official 0:4611f6cf2413 215
mbed_official 42:cab443dff75e 216 retcode = sock.sendto(sock_addr, (void*) echo_string, strlen(echo_string));
mbed_official 0:4611f6cf2413 217 if (retcode < 0) {
mbed_official 6:5678c0b6f74e 218 print_function("UDPSocket.sendto() fails, code: %d\n", retcode);
mbed_official 0:4611f6cf2413 219 return -1;
mbed_official 0:4611f6cf2413 220 } else {
mbed_official 6:5678c0b6f74e 221 print_function("UDP: Sent %d Bytes to %s\n", retcode, host_name);
mbed_official 0:4611f6cf2413 222 }
mbed_official 0:4611f6cf2413 223
mbed_official 0:4611f6cf2413 224 n = sock.recvfrom(&sock_addr, (void*) recv_buf, sizeof(recv_buf));
mbed_official 0:4611f6cf2413 225 #endif
mbed_official 40:c46ee5b71843 226 #endif
mbed_official 0:4611f6cf2413 227
mbed_official 0:4611f6cf2413 228 sock.close();
mbed_official 0:4611f6cf2413 229
mbed_official 0:4611f6cf2413 230 if (n > 0) {
mbed_official 6:5678c0b6f74e 231 print_function("Received from echo server %d Bytes\n", n);
mbed_official 0:4611f6cf2413 232 return 0;
mbed_official 0:4611f6cf2413 233 }
mbed_official 0:4611f6cf2413 234
mbed_official 0:4611f6cf2413 235 return -1;
mbed_official 0:4611f6cf2413 236 }
mbed_official 0:4611f6cf2413 237
Daniel_Lee 51:8d0212a4b805 238 void init_SkyWire4G()
Daniel_Lee 51:8d0212a4b805 239 {
Daniel_Lee 51:8d0212a4b805 240 DigitalOut myled(LED1); // Main LED
Daniel_Lee 51:8d0212a4b805 241 DigitalOut skywire_en(D12); // Skywire Enable
Daniel_Lee 51:8d0212a4b805 242 DigitalOut skywire_rts(D11); // Skywire Send
Daniel_Lee 51:8d0212a4b805 243 DigitalOut green_LED(A1); // Green LED
Daniel_Lee 51:8d0212a4b805 244 DigitalOut red_LED(A2); // Red LED
Daniel_Lee 51:8d0212a4b805 245 DigitalOut blue_LED(A3); // Blue LED
Daniel_Lee 51:8d0212a4b805 246
Daniel_Lee 51:8d0212a4b805 247 AnalogIn photo_trans(A0); // Photo Transistor
Daniel_Lee 51:8d0212a4b805 248 AnalogIn pot(A5); // Potentiometer
Daniel_Lee 51:8d0212a4b805 249 DigitalIn button1(D3); // Button 1
Daniel_Lee 51:8d0212a4b805 250 DigitalIn button2(A4); // Button 2
Daniel_Lee 51:8d0212a4b805 251 #if 0
Daniel_Lee 51:8d0212a4b805 252 I2C i2c(D14,D15); // Setup I2C bus for sensors
Daniel_Lee 51:8d0212a4b805 253
Daniel_Lee 51:8d0212a4b805 254 LPS331 pressure(i2c); // Pressure Sensor
Daniel_Lee 51:8d0212a4b805 255 LM75B LM75_temp(D14,D15); // Temp Sensor
Daniel_Lee 51:8d0212a4b805 256 // Accelerometer
Daniel_Lee 51:8d0212a4b805 257 LIS3DH accel(i2c, LIS3DH_V_CHIP_ADDR, LIS3DH_DR_NR_LP_100HZ, LIS3DH_FS_2G);
Daniel_Lee 51:8d0212a4b805 258 HTS221 humidity(D14, D15); // Humidity Sensor
Daniel_Lee 51:8d0212a4b805 259 #endif
Daniel_Lee 51:8d0212a4b805 260
Daniel_Lee 51:8d0212a4b805 261 // Turn on blue LED
Daniel_Lee 51:8d0212a4b805 262 green_LED = 0;
Daniel_Lee 51:8d0212a4b805 263 red_LED = 0;
Daniel_Lee 51:8d0212a4b805 264 blue_LED = 1;
Daniel_Lee 51:8d0212a4b805 265
Daniel_Lee 51:8d0212a4b805 266 skywire_rts=0;
Daniel_Lee 51:8d0212a4b805 267 myled=0;
Daniel_Lee 51:8d0212a4b805 268 printf("Starting Skywire board with LE910-EUG Demo...\n");
Daniel_Lee 51:8d0212a4b805 269 printf("Waiting for Skywire to Boot...\n");
Daniel_Lee 51:8d0212a4b805 270
Daniel_Lee 51:8d0212a4b805 271 //Enable Skywire
Daniel_Lee 51:8d0212a4b805 272 skywire_en=0;
Daniel_Lee 51:8d0212a4b805 273 ThisThread::sleep_for(2000);
Daniel_Lee 51:8d0212a4b805 274 skywire_en=1;
Daniel_Lee 51:8d0212a4b805 275 ThisThread::sleep_for(2000);
Daniel_Lee 51:8d0212a4b805 276 skywire_en=0;
Daniel_Lee 51:8d0212a4b805 277
Daniel_Lee 51:8d0212a4b805 278 myled=1;
Daniel_Lee 51:8d0212a4b805 279
Daniel_Lee 51:8d0212a4b805 280 printf("Wait 15 seconds..\n");
Daniel_Lee 51:8d0212a4b805 281 ThisThread::sleep_for(15000);
Daniel_Lee 51:8d0212a4b805 282 }
Daniel_Lee 51:8d0212a4b805 283
Daniel_Lee 51:8d0212a4b805 284
mbed_official 0:4611f6cf2413 285 int main()
mbed_official 0:4611f6cf2413 286 {
mbed_official 6:5678c0b6f74e 287 print_function("\n\nmbed-os-example-cellular\n");
mbed_official 34:6f85d44597ac 288 print_function("\n\nBuilt: %s, %s\n", __DATE__, __TIME__);
mbed_official 34:6f85d44597ac 289 #ifdef MBED_CONF_NSAPI_DEFAULT_CELLULAR_PLMN
mbed_official 36:6294a71c9e9e 290 print_function("\n\n[MAIN], plmn: %s\n", (MBED_CONF_NSAPI_DEFAULT_CELLULAR_PLMN ? MBED_CONF_NSAPI_DEFAULT_CELLULAR_PLMN : "NULL"));
mbed_official 34:6f85d44597ac 291 #endif
mbed_official 34:6f85d44597ac 292
Daniel_Lee 51:8d0212a4b805 293 init_SkyWire4G();
mbed_official 6:5678c0b6f74e 294 print_function("Establishing connection\n");
mbed_official 6:5678c0b6f74e 295 #if MBED_CONF_MBED_TRACE_ENABLE
mbed_official 6:5678c0b6f74e 296 trace_open();
mbed_official 6:5678c0b6f74e 297 #else
mbed_official 6:5678c0b6f74e 298 dot_thread.start(dot_event);
mbed_official 6:5678c0b6f74e 299 #endif // #if MBED_CONF_MBED_TRACE_ENABLE
mbed_official 27:97054be1a741 300
mbed_official 40:c46ee5b71843 301 #if MBED_CONF_APP_SOCK_TYPE == NONIP
mbed_official 40:c46ee5b71843 302 iface = CellularContext::get_default_nonip_instance();
mbed_official 40:c46ee5b71843 303 #else
mbed_official 40:c46ee5b71843 304 iface = CellularContext::get_default_instance();
mbed_official 40:c46ee5b71843 305 #endif
mbed_official 40:c46ee5b71843 306
mbed_official 11:23ea0907186e 307 MBED_ASSERT(iface);
mbed_official 11:23ea0907186e 308
mbed_official 40:c46ee5b71843 309 // sim pin, apn, credentials and possible plmn are taken automatically from json when using NetworkInterface::set_default_parameters()
mbed_official 40:c46ee5b71843 310 iface->set_default_parameters();
mbed_official 40:c46ee5b71843 311
mbed_official 6:5678c0b6f74e 312 nsapi_error_t retcode = NSAPI_ERROR_NO_CONNECTION;
mbed_official 0:4611f6cf2413 313
mbed_official 0:4611f6cf2413 314 /* Attempt to connect to a cellular network */
mbed_official 0:4611f6cf2413 315 if (do_connect() == NSAPI_ERROR_OK) {
mbed_official 6:5678c0b6f74e 316 retcode = test_send_recv();
mbed_official 0:4611f6cf2413 317 }
mbed_official 0:4611f6cf2413 318
mbed_official 26:348eec457e58 319 if (iface->disconnect() != NSAPI_ERROR_OK) {
mbed_official 26:348eec457e58 320 print_function("\n\n disconnect failed.\n\n");
mbed_official 26:348eec457e58 321 }
mbed_official 26:348eec457e58 322
mbed_official 6:5678c0b6f74e 323 if (retcode == NSAPI_ERROR_OK) {
mbed_official 6:5678c0b6f74e 324 print_function("\n\nSuccess. Exiting \n\n");
mbed_official 6:5678c0b6f74e 325 } else {
mbed_official 6:5678c0b6f74e 326 print_function("\n\nFailure. Exiting \n\n");
mbed_official 6:5678c0b6f74e 327 }
mbed_official 26:348eec457e58 328
mbed_official 6:5678c0b6f74e 329 #if MBED_CONF_MBED_TRACE_ENABLE
mbed_official 6:5678c0b6f74e 330 trace_close();
mbed_official 26:348eec457e58 331 #else
mbed_official 26:348eec457e58 332 dot_thread.terminate();
mbed_official 6:5678c0b6f74e 333 #endif // #if MBED_CONF_MBED_TRACE_ENABLE
mbed_official 6:5678c0b6f74e 334
mbed_official 6:5678c0b6f74e 335 return 0;
mbed_official 0:4611f6cf2413 336 }
mbed_official 0:4611f6cf2413 337 // EOF