Cellular example 1

Files at this revision

API Documentation at this revision

Comitter:
mab5449
Date:
Thu Sep 07 19:41:20 2017 +0000
Commit message:
Initial commit

Changed in this revision

.gitignore Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r fb873be06e31 .gitignore
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.gitignore	Thu Sep 07 19:41:20 2017 +0000
@@ -0,0 +1,4 @@
+.build
+.mbed
+projectfiles
+*.py*
diff -r 000000000000 -r fb873be06e31 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Sep 07 19:41:20 2017 +0000
@@ -0,0 +1,63 @@
+#include "mbed.h"
+#include "OnboardCellularInterface.h"
+
+/* SIM pin code goes here */
+#define PIN_CODE    "1234"
+
+/* Network credentials like APN go here, e.g.,
+    "apn, username, password" */
+#define CREDENTIALS "internet"
+
+/* Number of retries */
+#define RETRY_COUNT 3
+
+OnboardCellularInterface iface;
+
+nsapi_error_t do_connect()
+{
+    nsapi_error_t retcode;
+    bool disconnected = false;
+    uint8_t retry_counter = 0;
+
+    while (!iface.is_connected()) {
+
+        retcode = iface.connect();
+        if (retcode == NSAPI_ERROR_AUTH_FAILURE) {
+            printf("\n\nAuthentication Failure. Exiting application\n");
+            return retcode;
+        } else if (retcode != NSAPI_ERROR_OK) {
+            printf("\n\nCouldn't connect: %d, will retry\n", retcode);
+            retry_counter++;
+            continue;
+        } else if (retcode != NSAPI_ERROR_OK && retry_counter > RETRY_COUNT) {
+            printf("\n\nFatal connection failure: %d\n", retcode);
+            return retcode;
+        }
+
+        break;
+    }
+
+    printf("\n\nConnection Established.\n");
+
+    return NSAPI_ERROR_OK;
+}
+
+int main()
+{
+    /* Set Pin code for SIM card */
+    iface.set_sim_pin(PIN_CODE);
+
+    /* Set network credentials here, e.g., APN*/
+    iface.set_credentials(CREDENTIALS);
+
+    printf("\n\nmbed-os-example-cellular, Connecting...\n");
+
+    /* Attempt to connect to a cellular network */
+    if (do_connect() == NSAPI_ERROR_OK) {
+        printf("\n\nSuccess. Exiting \n\n");
+        return 0;
+    }
+
+    printf("\n\nFailure. Exiting \n\n");
+    return -1;
+}
\ No newline at end of file
diff -r 000000000000 -r fb873be06e31 mbed-os.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Thu Sep 07 19:41:20 2017 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#98ba8acb83cfc65f30a8a0771a27c71443ab093a