NTPClientTest, working with SARA-G350 on C027

Dependencies:   C027 NTPClient UbloxUSBModem mbed

Fork of C027_USSDTest_SARA350 by Steffen Graf

Files at this revision

API Documentation at this revision

Comitter:
omega256
Date:
Sat Mar 08 17:27:09 2014 +0000
Parent:
15:6fdc76603237
Commit message:
First;

Changed in this revision

NTPClient.lib 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NTPClient.lib	Sat Mar 08 17:27:09 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/NTPClient/#881559865a93
--- a/main.cpp	Sat Mar 08 17:15:00 2014 +0000
+++ b/main.cpp	Sat Mar 08 17:27:09 2014 +0000
@@ -2,31 +2,41 @@
 #include "C027.h"
 #include "UbloxModem.h"
 
-#define USSD_COMMAND "*100#"
+#include "NTPClient.h"
+
 /*
- * Modified USSD example, working with SARA-G350
- * Based on USSDTest and HTTP Test from u-blox
+ * Modified NTP example, working with SARA-G350
+ * Based on NTPClentTest and HTTP Test from u-blox
  * Output to PC via USB Serial Port, 9600 Baud
+ * Output of mbed IDE tells that this example uses more RAM than available, but it's working somehow...
  */
 
+C027 c027;
 Serial pc(USBTX, USBRX);
-C027 c027;
 
 void test(void const*)
 {
     c027.mdmPower(true);
-    UbloxSerModem modem; // for LISA-C use the UbloxUSBCDMAModem instead
-    char result[128];
+    UbloxSerModem  modem; // for LISA-C use the UbloxUSBCDMAModem instead
+    NTPClient ntp;
 
-    pc.printf("Sending %s on USSD channel\n", USSD_COMMAND);
-
-    int ret = modem.sendUSSD(USSD_COMMAND, result, sizeof(result));
+    int ret = modem.connect("internet"); // eventaully set another apn here
     if(ret) {
-        pc.printf("Send USSD command returned %d\n", ret);
+        pc.printf("Could not connect\n");
+        return;
     }
 
-    pc.printf("Result of command: %s\n", result);
+    pc.printf("Trying to update time...\r\n");
+    if (ntp.setTime("0.pool.ntp.org") == 0) {
+        pc.printf("Set time successfully\r\n");
+        time_t ctTime;
+        ctTime = time(NULL);
+        pc.printf("Time is set to (UTC): %s\r\n", ctime(&ctTime));
+    } else {
+        pc.printf("Error\r\n");
+    }
 
+    modem.disconnect();
     c027.mdmPower(false);
     
     while(1) {