cellular port

Dependencies:   Beep C027_Support C12832 LM75B MMA7660 mbed-rtos mbed nsdl_lib

This is a port of the NSDL HelloWorld for cellular.

To run the example you need a C027 and the ARM mbed application shield. The example uses cellular instead of ethernet and takes the true position from the GPS instead of using a fixed position.

Revision:
8:bd9096c4784c
Parent:
7:6b068978be9a
Child:
9:e4c916c6cb02
--- a/main.cpp	Tue Oct 22 10:50:05 2013 +0000
+++ b/main.cpp	Tue May 20 15:24:18 2014 +0000
@@ -1,6 +1,5 @@
 #include "mbed.h"
-#include "EthernetInterface.h"
-#include "C12832_lcd.h"
+#include "C12832.h"
 #include "nsdl_support.h"
 #include "dbg.h"
 // Include various resources
@@ -9,59 +8,40 @@
 #include "gps.h"
 #include "relay.h"
 
-static C12832_LCD lcd;
-Serial pc(USBTX, USBRX); // tx, rx
+#include "UDPSocket.h"
+#include "Endpoint.h"
+
+//------------------------------------------------------------------------------------
+// You need to configure these cellular modem / SIM parameters.
+// These parameters are ignored for LISA-C200 variants and can be left NULL.
+//------------------------------------------------------------------------------------
+#include "MDM.h"
+//! Set your secret SIM pin here (e.g. "1234"). Check your SIM manual.
+#define SIMPIN      NULL
+/*! The APN of your network operator SIM, sometimes it is "internet" check your 
+    contract with the network operator. You can also try to look-up your settings in 
+    google: https://www.google.de/search?q=APN+list */
+#define APN         "gprs.swisscom.ch"
+//! 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 
+//------------------------------------------------------------------------------------
+
+static C12832 lcd(D11, D13, D12, D7, D10);
 
 // ****************************************************************************
 // Configuration section
 
-// Ethernet configuration
-/* Define this to enable DHCP, otherwise manual address configuration is used */
-#define DHCP
-
-/* Manual IP configurations, if DHCP not defined */
-#define IP      "10.45.0.206"
-#define MASK    "255.255.255.0"
-#define GW      "10.45.0.1"
-
 // NSP configuration
 /* Change this IP address to that of your NanoService Platform installation */
-static const char* NSP_ADDRESS = "217.140.101.20"; /* demo NSP, web interface at http://nanoservice-demo.mbed.org*/ 
+static const char* NSP_ADDRESS = "nanoservice-demo.mbed.org"; /* demo NSP, web interface at http://nanoservice-demo.mbed.org*/ 
 static const int NSP_PORT = 5683;
 char endpoint_name[16] = "mbed-";
 uint8_t ep_type[] = {"mbed_device"};
 uint8_t lifetime_ptr[] = {"1200"};
 
 // ****************************************************************************
-// Ethernet initialization
-
-EthernetInterface eth;
-
-static void ethernet_init()
-{
-    char mbed_uid[33]; // for creating unique name for the board
-
-    /* Initialize network */
-#ifdef DHCP
-    NSDL_DEBUG("DHCP in use\r\n");
-    eth.init();
-#else
-    eth.init(IP, MASK, GW);
-#endif
-    if(eth.connect(30000) == 0)
-        pc.printf("Connect OK\n\r");
-
-    mbed_interface_uid(mbed_uid);
-    mbed_uid[32] = '\0';
-    strncat(endpoint_name, mbed_uid + 27, 15 - strlen(endpoint_name));
-
-    lcd.locate(0,11);
-    lcd.printf("IP:%s", eth.getIPAddress());
-
-    NSDL_DEBUG("IP Address:%s ", eth.getIPAddress());
-}
-
-// ****************************************************************************
 // NSP initialization
 
 UDPSocket server;
@@ -76,7 +56,8 @@
     
     NSDL_DEBUG("name: %s", endpoint_name);
     NSDL_DEBUG("NSP=%s - port %d\n", NSP_ADDRESS, NSP_PORT);
-
+    NSDL_DEBUG("NSDL Demo Portal\n  Website:  http://%s\n  Username: demo\n  Password: demo\n", NSP_ADDRESS);
+    
     lcd.locate(0,22);
     lcd.printf("EP name:%s\n", endpoint_name);
 }
@@ -118,9 +99,9 @@
         /* Register with NSP */
     endpoint_ptr = nsdl_init_register_endpoint(endpoint_ptr, (uint8_t*)endpoint_name, ep_type, lifetime_ptr);
     if(sn_nsdl_register_endpoint(endpoint_ptr) != 0)
-        pc.printf("NSP registering failed\r\n");
+        printf("NSP registering failed\r\n");
     else
-        pc.printf("NSP registering OK\r\n");
+        printf("NSP registering OK\r\n");
     nsdl_clean_register_endpoint(&endpoint_ptr);
 
     nsdl_free(resource_ptr->resource_parameters_ptr);
@@ -138,9 +119,13 @@
     lcd.printf("mbed NanoService demo");
     NSDL_DEBUG("mbed NanoService Example App 0.1\n");
     
-    // Initialize Ethernet interface first
-    ethernet_init();
-    
+    MDMSerial mdm;
+    //mdm.setDebug(4); // enable this for debugging issues 
+    if (!mdm.connect(SIMPIN, APN,USERNAME,PASSWORD))
+        return -1;
+
+    lcd.locate(0,11);
+
     // Initialize NSP node
     nsp_init();
     
@@ -152,4 +137,10 @@
     
     // Run the NSDL event loop (never returns)
     nsdl_event_loop();
+
+    mdm.disconnect();
+    mdm.powerOff();
+    
+    while(true);
+        
 }