Skip to content

Commit c8bd29b

Browse files
author
Antti Kauppila
authored
Merge pull request #47 from ARMmbed/mbed-os-5.7.0-oob
Merge Mbed OS 5.7.0 oob
2 parents 7fee442 + feadcd3 commit c8bd29b

File tree

4 files changed

+79
-31
lines changed

4 files changed

+79
-31
lines changed

README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
# Example cellular application for mbed OS
1+
# Example cellular application for Mbed OS
22

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

55
## Getting started
66

7-
This particular cellular application uses a cellular network and network-socket APIs that are part of [`mbed-os`](github.com/armmbed/mbed-os).
7+
This particular cellular application uses a cellular network and network-socket APIs that are part of [`mbed-os`](https://github.com/ARMmbed/mbed-os).
88

99
The program uses a [generic cellular modem driver](https://github.com/ARMmbed/mbed-os/tree/master/features/netsocket/cellular/generic_modem_driver) using an external IP stack (LWIP) standard 3GPP AT 27.007 AT commands to setup the cellular modem and registers to the network.
1010

1111
After registration, the driver opens a point-to-point protocol (PPP) pipe using LWIP with the cellular modem and connects to internet. This driver currently supports UART data connection type only between your cellular modem and MCU.
1212

13-
For more information on ARM mbed OS cellular APIs and porting guide, please visit the [mbed OS cellular documentation](https://docs.mbed.com/docs/mbed-os-api-reference/en/latest/APIs/communication/cellular/).
13+
For more information on Arm Mbed OS cellular APIs and porting guide, please visit the [Mbed OS cellular API](https://os.mbed.com/docs/latest/reference/cellular-api.html) and [contributing documentation](https://os.mbed.com/docs/latest/reference/contributing-connectivity.html#cellularinterface).
1414

1515
### Download the application
1616

@@ -49,7 +49,9 @@ See the file `mbed_app.json` in the root directory of your application. This fil
4949

5050
### Selecting socket type (TCP or UDP)
5151

52-
You can choose which socket type the application should use. For example:
52+
53+
You can choose which socket type the application should use; however, please note that TCP is a more reliable tranmission protocol. For example:
54+
5355

5456
```json
5557

@@ -70,23 +72,23 @@ If you like details and wish to know about all the AT interactions between the m
7072

7173
### Board support
7274

73-
The [generic cellular modem driver](https://github.com/ARMmbed/mbed-os/tree/master/features/netsocket/cellular/generic_modem_driver) this application uses was written using only a standard AT command set. It uses PPP with an mbed-supported external IP stack. These abilities make the driver essentially generic, or nonvendor specific. However, this particular driver is for onboard-modem types. In other words, the modem exists on the mbed Enabled target as opposed to plug-in modules (shields). For more details, please see our [mbed OS cellular documentation](https://docs.mbed.com/docs/mbed-os-api-reference/en/latest/APIs/communication/cellular/).
75+
The [generic cellular modem driver](https://github.com/ARMmbed/mbed-os/tree/master/features/netsocket/cellular/generic_modem_driver) this application uses was written using only a standard AT command set. It uses PPP with an Mbed-supported external IP stack. These abilities make the driver essentially generic, or nonvendor specific. However, this particular driver is for onboard-modem types. In other words, the modem exists on the Mbed Enabled target as opposed to plug-in modules (shields). For more details, please see our [Mbed OS cellular documentation](https://os.mbed.com/docs/latest/reference/cellular-api.html).
7476

75-
Examples of mbed Enabled boards with onboard modem chips include [u-blox C027](https://developer.mbed.org/platforms/u-blox-C027/) and [MultiTech MTS Dragonfly](https://developer.mbed.org/platforms/MTS-Dragonfly/).
77+
Examples of Mbed Enabled boards with onboard modem chips include [u-blox C027](https://os.mbed.com/platforms/u-blox-C027/) and [MultiTech MTS Dragonfly](https://os.mbed.com/platforms/MTS-Dragonfly/).
7678

7779
## Compiling the application
7880

79-
Use mbed CLI commands to generate a binary for the application. For example, in the case of GCC, use the following command:
81+
Use Mbed CLI commands to generate a binary for the application. For example, in the case of GCC, use the following command:
8082

8183
```sh
8284
$ mbed compile -m YOUR_TARGET_WITH_MODEM -t GCC_ARM
8385
```
8486

8587
## Running the application
8688

87-
Drag and drop the application binary from `BUILD/YOUR_TARGET_WITH_MODEM/GCC_ARM/mbed-os-example-cellular.bin` to your mbed Enabled target hardware, which appears as a USB device on your host machine.
89+
Drag and drop the application binary from `BUILD/YOUR_TARGET_WITH_MODEM/GCC_ARM/mbed-os-example-cellular.bin` to your Mbed Enabled target hardware, which appears as a USB device on your host machine.
8890

89-
Attach a serial console emulator of your choice (for example, PuTTY, Minicom or screen) to your USB device. Set the baudrate to 115200, and reset your board by pressing the reset button.
91+
Attach a serial console emulator of your choice (for example, PuTTY, Minicom or screen) to your USB device. Set the baudrate to 115200 bit/s, and reset your board by pressing the reset button.
9092

9193
You should see an output similar to this:
9294

@@ -102,3 +104,7 @@ Received from echo server 4 Bytes
102104
Success. Exiting
103105
104106
```
107+
108+
## Troubleshooting
109+
110+
If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it.

main.cpp

Lines changed: 61 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
// Number of retries /
4141
#define RETRY_COUNT 3
4242

43+
44+
4345
// CellularInterface object
4446
OnboardCellularInterface iface;
4547

@@ -49,6 +51,34 @@ const char *host_name = "echo.u-blox.com";
4951
// Echo server port (same for TCP and UDP)
5052
const int port = 7;
5153

54+
Mutex PrintMutex;
55+
Thread dot_thread;
56+
57+
#define PRINT_TEXT_LENGTH 128
58+
char print_text[PRINT_TEXT_LENGTH];
59+
void print_function(const char *input_string)
60+
{
61+
PrintMutex.lock();
62+
printf("%s", input_string);
63+
fflush(NULL);
64+
PrintMutex.unlock();
65+
}
66+
67+
void dot_event()
68+
{
69+
70+
while (true) {
71+
wait(4);
72+
if (!iface.is_connected()) {
73+
print_function(".");
74+
} else {
75+
break;
76+
}
77+
}
78+
79+
}
80+
81+
5282
/**
5383
* Connects to the Cellular Network
5484
*/
@@ -61,21 +91,23 @@ nsapi_error_t do_connect()
6191

6292
retcode = iface.connect();
6393
if (retcode == NSAPI_ERROR_AUTH_FAILURE) {
64-
printf("\n\nAuthentication Failure. Exiting application\n");
94+
print_function("\n\nAuthentication Failure. Exiting application\n");
6595
return retcode;
6696
} else if (retcode != NSAPI_ERROR_OK) {
67-
printf("\n\nCouldn't connect: %d, will retry\n", retcode);
97+
snprintf(print_text, PRINT_TEXT_LENGTH, "\n\nCouldn't connect: %d, will retry\n", retcode);
98+
print_function(print_text);
6899
retry_counter++;
69100
continue;
70101
} else if (retcode != NSAPI_ERROR_OK && retry_counter > RETRY_COUNT) {
71-
printf("\n\nFatal connection failure: %d\n", retcode);
102+
snprintf(print_text, PRINT_TEXT_LENGTH, "\n\nFatal connection failure: %d\n", retcode);
103+
print_function(print_text);
72104
return retcode;
73105
}
74106

75107
break;
76108
}
77109

78-
printf("\n\nConnection Established.\n");
110+
print_function("\n\nConnection Established.\n");
79111

80112
return NSAPI_ERROR_OK;
81113
}
@@ -95,49 +127,57 @@ nsapi_error_t test_send_recv()
95127

96128
retcode = sock.open(&iface);
97129
if (retcode != NSAPI_ERROR_OK) {
98-
printf("UDPSocket.open() fails, code: %d\n", retcode);
130+
snprintf(print_text, PRINT_TEXT_LENGTH, "UDPSocket.open() fails, code: %d\n", retcode);
131+
print_function(print_text);
99132
return -1;
100133
}
101134

102135
SocketAddress sock_addr;
103136
retcode = iface.gethostbyname(host_name, &sock_addr);
104137
if (retcode != NSAPI_ERROR_OK) {
105-
printf("Couldn't resolve remote host: %s, code: %d\n", host_name,
138+
snprintf(print_text, PRINT_TEXT_LENGTH, "Couldn't resolve remote host: %s, code: %d\n", host_name,
106139
retcode);
140+
print_function(print_text);
107141
return -1;
108142
}
109143

110144
sock_addr.set_port(port);
111145

112146
sock.set_timeout(15000);
113147
int n = 0;
114-
char *echo_string = "TEST";
148+
const char *echo_string = "TEST";
115149
char recv_buf[4];
116150
#if MBED_CONF_APP_SOCK_TYPE == TCP
117151
retcode = sock.connect(sock_addr);
118152
if (retcode < 0) {
119-
printf("TCPSocket.connect() fails, code: %d\n", retcode);
153+
snprintf(print_text, PRINT_TEXT_LENGTH, "TCPSocket.connect() fails, code: %d\n", retcode);
154+
print_function(print_text);
120155
return -1;
121156
} else {
122-
printf("TCP: connected with %s server\n", host_name);
157+
snprintf(print_text, PRINT_TEXT_LENGTH, "TCP: connected with %s server\n", host_name);
158+
print_function(print_text);
123159
}
124160
retcode = sock.send((void*) echo_string, sizeof(echo_string));
125161
if (retcode < 0) {
126-
printf("TCPSocket.send() fails, code: %d\n", retcode);
162+
snprintf(print_text, PRINT_TEXT_LENGTH, "TCPSocket.send() fails, code: %d\n", retcode);
163+
print_function(print_text);
127164
return -1;
128165
} else {
129-
printf("TCP: Sent %d Bytes to %s\n", retcode, host_name);
166+
snprintf(print_text, PRINT_TEXT_LENGTH, "TCP: Sent %d Bytes to %s\n", retcode, host_name);
167+
print_function(print_text);
130168
}
131169

132170
n = sock.recv((void*) recv_buf, sizeof(recv_buf));
133171
#else
134172

135173
retcode = sock.sendto(sock_addr, (void*) echo_string, sizeof(echo_string));
136174
if (retcode < 0) {
137-
printf("UDPSocket.sendto() fails, code: %d\n", retcode);
175+
snprintf(print_text, PRINT_TEXT_LENGTH, "UDPSocket.sendto() fails, code: %d\n", retcode);
176+
print_function(print_text);
138177
return -1;
139178
} else {
140-
printf("UDP: Sent %d Bytes to %s\n", retcode, host_name);
179+
snprintf(print_text, PRINT_TEXT_LENGTH, "UDP: Sent %d Bytes to %s\n", retcode, host_name);
180+
print_function(print_text);
141181
}
142182

143183
n = sock.recvfrom(&sock_addr, (void*) recv_buf, sizeof(recv_buf));
@@ -146,36 +186,38 @@ nsapi_error_t test_send_recv()
146186
sock.close();
147187

148188
if (n > 0) {
149-
printf("Received from echo server %d Bytes\n", n);
189+
snprintf(print_text, PRINT_TEXT_LENGTH, "Received from echo server %d Bytes\n", n);
190+
print_function(print_text);
150191
return 0;
151192
}
152193

153194
return -1;
154-
155-
return retcode;
156195
}
157196

158197
int main()
159198
{
199+
160200
iface.modem_debug_on(MBED_CONF_APP_MODEM_TRACE);
161201
/* Set Pin code for SIM card */
162202
iface.set_sim_pin(MBED_CONF_APP_SIM_PIN_CODE);
163203

164204
/* Set network credentials here, e.g., APN*/
165205
iface.set_credentials(MBED_CONF_APP_APN, MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD);
166206

167-
printf("\n\nmbed-os-example-cellular, Connecting...\n");
207+
print_function("\n\nmbed-os-example-cellular\n");
208+
print_function("Establishing connection ");
209+
dot_thread.start(dot_event);
168210

169211
/* Attempt to connect to a cellular network */
170212
if (do_connect() == NSAPI_ERROR_OK) {
171213
nsapi_error_t retcode = test_send_recv();
172214
if (retcode == NSAPI_ERROR_OK) {
173-
printf("\n\nSuccess. Exiting \n\n");
215+
print_function("\n\nSuccess. Exiting \n\n");
174216
return 0;
175217
}
176218
}
177219

178-
printf("\n\nFailure. Exiting \n\n");
220+
print_function("\n\nFailure. Exiting \n\n");
179221
return -1;
180222
}
181223
// EOF

mbed-os.lib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
https://github.com/ARMmbed/mbed-os/#5f6572179d66ce4c09d6517b659ac51133cc980d
1+
https://github.com/ARMmbed/mbed-os/#8b54959f5bca08a8ad44a701bafd634afbb38b03

mbed_app.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"config": {
3-
"sock-type": "UDP",
3+
"sock-type": "TCP",
44
"modem_trace": {
55
"help": "Turns AT command trace on/off from the cellular modem, defaults to off",
66
"value": false
@@ -34,4 +34,4 @@
3434
"platform.default-serial-baud-rate": 115200
3535
}
3636
}
37-
}
37+
}

0 commit comments

Comments
 (0)