Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 0:fb873be06e31, committed 2017-09-07
- Comitter:
- mab5449
- Date:
- Thu Sep 07 19:41:20 2017 +0000
- Commit message:
- Initial commit
Changed in this revision
--- /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*
--- /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
--- /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