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:
Mon Mar 24 09:58:46 2014 +0000
Parent:
22:3a595f7826af
Child:
24:8f9b678a7932
Commit message:
fix

Changed in this revision

MbedSmartRest.lib Show annotated file Show diff for this revision Revisions of this file
apndb.cpp Show annotated file Show diff for this revision Revisions of this file
apndb.h Show annotated file Show diff for this revision Revisions of this file
common.h 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/MbedSmartRest.lib	Thu Feb 20 14:38:53 2014 +0000
+++ b/MbedSmartRest.lib	Mon Mar 24 09:58:46 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/vwochnik/code/MbedSmartRest/#478414cc15a4
+http://mbed.org/users/vwochnik/code/MbedSmartRest/#844856ab160d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apndb.cpp	Mon Mar 24 09:58:46 2014 +0000
@@ -0,0 +1,34 @@
+#include "apndb.h"
+#include "stdlib.h"
+#include "stdio.h"
+#include "string.h"
+
+#define APNDB_COUNT 5
+
+// 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 = "" }
+};
+
+apndb_t * apndb_get(const char * imsi)
+{
+    char chr1[8], chr2[8];
+    size_t len;
+    
+    for (size_t i = 0; i < APNDB_COUNT; i++) {
+        strcpy(chr1, apndb[i].mcc);
+        strcat(chr1, apndb[i].mnc);
+        len = strlen(chr1);
+        strncpy(chr2, imsi, len);
+        chr2[len] = '\0';
+        
+        if (strcmp(chr1, chr2) == 0)
+            return &apndb[i];
+    }
+    
+    return NULL;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/apndb.h	Mon Mar 24 09:58:46 2014 +0000
@@ -0,0 +1,16 @@
+#ifndef APNDB_H
+#define APNDb_H
+
+// Defiles the base type for storing mcc/mnc-apn/user/pass tuples
+typedef struct
+{
+    char mcc[4]; // mobile country code
+    char mnc[4]; // mobile network code
+    char apn[32];
+    char user[32];
+    char pass[32];
+} apndb_t;
+
+apndb_t * apndb_get(const char * imsi);
+
+#endif
\ No newline at end of file
--- a/common.h	Thu Feb 20 14:38:53 2014 +0000
+++ b/common.h	Mon Mar 24 09:58:46 2014 +0000
@@ -48,6 +48,7 @@
 extern MbedSmartRest client;
 
 const char * imei();
+const char * imsi();
 const char * cellId();
 const char * iccid();
 sigq_t * signalQuality();
--- a/main.cpp	Thu Feb 20 14:38:53 2014 +0000
+++ b/main.cpp	Mon Mar 24 09:58:46 2014 +0000
@@ -1,10 +1,12 @@
 #include "common.h"
+#include "apndb.h"
 #include "io.h"
 #include "ATResultBuffer.h"
 
 C027 c027;
 ATCommandsInterface *cmdIface = NULL;
 char cIMEI[21] = "";
+char cIMSI[16] = "";
 char cCellId[9] = "";
 char cICCID[24] = "";
 sigq_t sigQ = {0, 0};
@@ -24,9 +26,26 @@
     cmdIface = modem.getATCommandsInterface();
     
     puts("Connecting...");
-    if (modem.connect("public4.m2minternet.com")) {
-        puts("GPRS connection failure.");
-        return 2;
+    if (modem.connect("")) {
+        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);
+        
+        if (modem.connect("public4.m2minternet.com")) {
+            puts("GPRS connection failure.");
+            return 2;
+        }
+        printf("IMSI: %s\n", imsi());
+        apn = apndb_get(imsi());
+        if (apn == NULL)
+            puts("No APN found.");
+        else
+            printf("APN: %s\n", apn->apn);
     }
     
     // get before starting program as they're permanent
@@ -34,6 +53,9 @@
         puts("Couldn't read IMEI or ICCID.");
         return 2;
     }
+    
+    // Shown on display
+    signalQuality();
 
     puts("Starting program...");    
     
@@ -67,6 +89,23 @@
     return cIMEI;
 }
 
+const char * imsi()
+{
+    ATCommandsInterface::ATResult result;
+    ATResultBuffer buffer;
+    
+    if ((cmdIface == NULL) || (strlen(cIMSI)))
+        return cIMSI;
+
+    cmdIface->execute("AT+CIMI", &buffer, &result);
+    if (ATCommandsInterface::ATResult::AT_OK == result.result)
+        strcpy(cIMSI, buffer.getLastLine());
+    else
+        cIMSI[0] = '\0';
+
+    return cIMSI;
+}
+
 const char * cellId()
 {
     int len; uint32_t cellId;