NanoService Example for u-blox Cellular modems

Dependencies:   Beep LM75B MMA7660 mbed nsdl_lib

Fork of NSDL_HelloWorld by Sensinode

Revision:
8:8452c1eaa690
Parent:
7:6b068978be9a
Child:
9:ccb9e53d5471
--- a/main.cpp	Tue Oct 22 10:50:05 2013 +0000
+++ b/main.cpp	Mon Oct 28 19:38:15 2013 +0000
@@ -1,5 +1,10 @@
 #include "mbed.h"
-#include "EthernetInterface.h"
+#include "UbloxUSBGSMModem.h"
+#include "UbloxUSBCDMAModem.h"
+#include "CellularModem.h"
+#include "Socket.h"
+#include "Endpoint.h"
+#include "UDPSocket.h"
 #include "C12832_lcd.h"
 #include "nsdl_support.h"
 #include "dbg.h"
@@ -15,6 +20,21 @@
 // ****************************************************************************
 // Configuration section
 
+#ifndef MODEM_APN
+#warning APN not specified, using "internet"
+#define MODEM_APN "internet"
+#endif
+
+#ifndef MODEM_USERNAME
+#warning username not specified
+#define MODEM_USERNAME NULL
+#endif
+
+#ifndef MODEM_PASSWORD
+#warning password not specified
+#define MODEM_PASSWORD NULL
+#endif
+
 // Ethernet configuration
 /* Define this to enable DHCP, otherwise manual address configuration is used */
 #define DHCP
@@ -32,41 +52,40 @@
 uint8_t ep_type[] = {"mbed_device"};
 uint8_t lifetime_ptr[] = {"1200"};
 
-// ****************************************************************************
-// Ethernet initialization
+#ifdef MODEM_UBLOX_GSM
+    UbloxUSBGSMModem modem;
+#else
+    UbloxUSBCDMAModem modem(p18, true, 1);
+#endif
+UDPSocket server;
+Endpoint nsp;
 
-EthernetInterface eth;
+// ****************************************************************************
+// u-blox Cellular initialization
 
-static void ethernet_init()
+static void cellular_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");
+    modem.power(true);
+    Thread::wait(1000);
+    int ret = modem.connect(MODEM_APN, MODEM_USERNAME, MODEM_PASSWORD);
+    if(ret)
+    {
+      NSDL_DEBUG("Could not connect\n");
+    }
+    NSDL_DEBUG("Connection OK\n");
 
     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;
-Endpoint nsp;
-
 static void nsp_init()
 {
     server.init();
@@ -135,11 +154,11 @@
 {
     lcd.cls();
     lcd.locate(0,0);
-    lcd.printf("mbed NanoService demo");
-    NSDL_DEBUG("mbed NanoService Example App 0.1\n");
+    lcd.printf("mbed NanoService u-blox");
+    NSDL_DEBUG("mbed NanoService u-blox Example App 0.1\n");
     
-    // Initialize Ethernet interface first
-    ethernet_init();
+    // Initialize Cellular interface first
+    cellular_init();
     
     // Initialize NSP node
     nsp_init();