NanoService Example for u-blox Cellular modems
Dependencies: Beep LM75B MMA7660 mbed nsdl_lib
Fork of NSDL_HelloWorld by
Revision 8:8452c1eaa690, committed 2013-10-28
- Comitter:
- zdshelby
- Date:
- Mon Oct 28 19:38:15 2013 +0000
- Parent:
- 7:6b068978be9a
- Child:
- 9:ccb9e53d5471
- Commit message:
- - Converted to the u-blox Cellular interface;
Changed in this revision
--- a/EthernetInterface.lib Tue Oct 22 10:50:05 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/EthernetInterface/#dd9794ce1d64
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UbloxUSBModem.lib Mon Oct 28 19:38:15 2013 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/mbed_official/code/UbloxUSBModem/#6e9d98f8c237
--- 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();
--- a/mbed-rtos.lib Tue Oct 22 10:50:05 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed-rtos/#53e6cccd8782
--- a/nsdl_support.cpp Tue Oct 22 10:50:05 2013 +0000 +++ b/nsdl_support.cpp Mon Oct 28 19:38:15 2013 +0000 @@ -4,10 +4,15 @@ #include "nsdl_support.h" #include "mbed.h" #include "rtos.h" -#include "EthernetInterface.h" +#include "UbloxUSBGSMModem.h" +#include "UbloxUSBCDMAModem.h" +#include "CellularModem.h" +#include "Socket.h" +#include "Endpoint.h" +#include "UDPSocket.h" extern Serial pc; -extern EthernetInterface eth; +extern UbloxUSBGSMModem modem; extern Endpoint nsp; extern UDPSocket server; extern char endpoint_name[16];



