Official reference client implementation for Cumulocity SmartREST on u-blox C027.

Dependencies:   C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed

Fork of MbedSmartRestMain by Vincent Wochnik

Files at this revision

API Documentation at this revision

Comitter:
vwochnik
Date:
Sun May 25 17:46:19 2014 +0000
Parent:
27:bfd402593acc
Child:
29:853741b9ea3b
Commit message:
update info functions to new driver. use apn db.

Changed in this revision

apndb.cpp 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
--- a/apndb.cpp	Thu May 22 18:07:13 2014 +0000
+++ b/apndb.cpp	Sun May 25 17:46:19 2014 +0000
@@ -7,11 +7,7 @@
 
 // Contains all tuples
 apndb_t apndb[] = {
-    { .mcc = "123", .mnc = "023", .apn = "apn", .user = "user", .pass = "" },
-    { .mcc = "123", .mnc = "023", .apn = "apn", .user = "user", .pass = "" },
-    { .mcc = "204", .mnc = "04", .apn = "Vodafone NL", .user = "user", .pass = "" },
-    { .mcc = "123", .mnc = "023", .apn = "apn", .user = "user", .pass = "" },
-    { .mcc = "123", .mnc = "023", .apn = "apn", .user = "user", .pass = "" }
+    { .mcc = "204", .mnc = "04", .apn = "public4.m2minternet.com", .user = "", .pass = "" }
 };
 
 apndb_t * apndb_get(const char * imsi)
--- a/main.cpp	Thu May 22 18:07:13 2014 +0000
+++ b/main.cpp	Sun May 25 17:46:19 2014 +0000
@@ -2,33 +2,14 @@
 #include "apndb.h"
 #include "io.h"
 
-//----------------------------------------------------------------------
-// You may need to configure these parameters
- 
-/** Set your secret SIM pin here "1234"
-*/
 #define SIMPIN      NULL
  
-/** The APN of your network operator, sometimes it is "internet" 
-    check your contract with the network operator
-*/
-#define APN         "public4.m2minternet.com"
- 
-/** Set the user name for your APN, or NULL if not needed
-*/
-#define USERNAME    NULL
- 
-/** Set the password for your APN, or NULL if not needed
-*/
-#define PASSWORD    NULL 
- 
 C027 c027;
 MDMSerial mdm;
-char cIMEI[21] = "ADASDF1312";
-char cIMSI[16] = "";
-char cCellId[9] = "";
-char cICCID[24] = "12345";
-sigq_t sigQ = {0, 0};
+sigq_t sigQ = {};
+char cCellId[8+1];
+MDMParser::DevStatus devStatus = {};
+MDMParser::NetStatus netStatus = {};
 
 int main()
 {
@@ -41,29 +22,39 @@
     c027.mdmWakeup();
     c027.mdmReset();
     c027.mdmPower(true);
-    
-    /*puts("Searching for login...");
-    // get imsi number
-    printf("IMSI: %s\n", imsi());
-    apndb_t *apn = apndb_get(imsi());
-    if (apn == NULL)
-        puts("No APN found.");
-    else
-        printf("APN: %s\n", apn->apn);
-    */
+    Thread::wait(2000);
 
-    if (!mdm.connect(SIMPIN, APN,USERNAME,PASSWORD, true)) {    
-        puts("GPRS connection failure.");
-        return 2;
+    puts("Initializing modem.");
+    if (!mdm.init(SIMPIN, &devStatus)) {
+        puts("Modem initialization failed. Check your PIN number.");
+        return 1;
+    }
+
+    puts("Searching for login...");
+    apndb_t *apn = apndb_get(devStatus.imsi);
+    if (apn == NULL) {
+        puts("No APN found. Stop.");
+        return 1;
     }
 
-    /*printf("IMSI: %s\n", imsi());
-    apn = apndb_get(imsi());
-    if (apn == NULL)
-        puts("No APN found.");
-    else
-        printf("APN: %s\n", apn->apn);
-    */
+    // wait until we are connected
+    int i = 60;
+    while (!mdm.checkNetStatus(&netStatus)) {
+        if ((netStatus.reg == MDMParser::REG_DENIED) || (i-- == 0))
+            break;
+        Thread::wait(2000);
+    }
+
+    if ((netStatus.reg == MDMParser::REG_DENIED) || (i == 0)) {
+        puts("Network connection failed.");
+        return 1;
+    }
+
+    puts("Joining Network.");
+    if (mdm.join(apn->apn, apn->user, apn->pass) == NOIP) {
+        puts("Could not join network. Check APN and credentials.");
+        return 1;
+    }
 
     // get before starting program as they're permanent
     if ((!strlen(imei())) || (!strlen(iccid()))) {
@@ -90,29 +81,39 @@
 
 const char * imei()
 {
-    return cIMEI;
+    return devStatus.imei;
 }
 
 const char * imsi()
 {
-    return cIMSI;
+    return devStatus.imsi;
 }
 
 const char * cellId()
 {
+    if (!mdm.checkNetStatus(&netStatus))
+        return NULL;
+
+    if (snprintf(cCellId, sizeof(cCellId), "%X", netStatus.ci) < 1)
+        return NULL;
+        
     return cCellId;
 }
 
 const char * iccid()
 {
-    return cICCID;
+    return devStatus.ccid;
 }
 
 sigq_t * signalQuality()
 {
     sigQ.rssi = 0; sigQ.ber = 0;
+    if (!mdm.checkNetStatus(&netStatus))
+        return NULL;
+
+    sigQ.rssi = netStatus.rssi;
+    sigQ.ber = netStatus.ber;
     
-    lcd_signal(0, 0);
-
+    lcd_signal(sigQ.rssi, sigQ.ber);
     return &sigQ;
 }