インターフェース2014年10月号のu-blox C027で3G通信する記事で使用したプログラム。   CQ publishing Interface 2014.10 issue, C027 3G test program.

Dependencies:   C027_Support C027_SupportTest mbed picojson

Fork of C027_SupportTest by u-blox

インターフェース2014年10月号のu-blox C027で3G通信する記事で使用したプログラムです。

Revision:
29:1f18e74ff972
Parent:
28:d504a106c124
Child:
30:e6c7827dfbe8
--- a/main.cpp	Wed Jul 16 12:56:24 2014 +0000
+++ b/main.cpp	Thu Jul 17 02:52:30 2014 +0000
@@ -34,8 +34,8 @@
 #define PASSWORD    "nnku62"
 
 //---- Xively --------------------------------------------------------------
-#define XI_FEED_ID 128488 // set Xively Feed ID (numerical, no quoutes)
-#define XI_API_KEY "T4KXAH_dasgw1PWBPc3fdsfsdgsdy-dUc4ND0g" // set Xively API key (double-quoted string)
+#define XI_FEED_ID 1016719601 // set Xively Feed ID (numerical, no quoutes)
+#define XI_API_KEY "Y1mN05SzFgxjwiB9xFj42KYaTzdhohBLaKN8a9juznDrGsvK" // set Xively API key (double-quoted string)
 
 #include "xively.h"
 #include "xi_err.h"
@@ -88,32 +88,7 @@
         mdmOk = mdm.registerNet(&netStatus);
         mdm.dumpNetStatus(&netStatus);
     }
-// Xively
-    xi_feed_t feed;
-    memset( &feed, NULL, sizeof( xi_feed_t ) );
-    
-    feed.feed_id = XI_FEED_ID;
-    feed.datastream_count = 2;
-
-    feed.datastreams[0].datapoint_count = 1;
-    xi_datastream_t* lat_datastream = &feed.datastreams[0];
-    strcpy( lat_datastream->datastream_id, "lat" );
-    xi_datapoint_t* current_lat = &lat_datastream->datapoints[0];
-
-    feed.datastreams[1].datapoint_count = 1;
-    xi_datastream_t* lon_datastream = &feed.datastreams[1];
-    strcpy( lon_datastream->datastream_id, "lon" );
-    xi_datapoint_t* current_lon = &lon_datastream->datapoints[0];
-    
-    // create the cosm library context
-    xi_context_t* xi_context
-        = xi_create_context( XI_HTTP, XI_API_KEY, feed.feed_id );
-
-    // check if everything works
-    if( xi_context == NULL )
-    {
-        return -1;
-    }
+#if 1
 
     if (mdmOk)
     {
@@ -220,6 +195,53 @@
             mdm.disconnect();
         }
     }
+#endif
+#if 0
+    EthernetInterface eth;
+    
+    int s = eth.init(); //Use DHCP
+    if( s != NULL ) {
+        printf( "Could not initialise. Will halt!\n" );        
+        exit( 0 );
+    }    
+        
+    s = eth.connect();
+    if( s != NULL ) {
+        printf( "Could not connect. Will halt!\n" );
+        exit( 0 );
+    } else {
+        printf( "IP: %s\n", eth.getIPAddress() );    
+    }
+#endif
+
+// Xively
+    xi_feed_t feed;
+    memset( &feed, NULL, sizeof( xi_feed_t ) );
+    
+    feed.feed_id = XI_FEED_ID;
+    feed.datastream_count = 2;
+
+    feed.datastreams[0].datapoint_count = 1;
+    xi_datastream_t* lat_datastream = &feed.datastreams[0];
+    strcpy( lat_datastream->datastream_id, "lat" );
+    xi_datapoint_t* current_lat = &lat_datastream->datapoints[0];
+
+    feed.datastreams[1].datapoint_count = 1;
+    xi_datastream_t* lon_datastream = &feed.datastreams[1];
+    strcpy( lon_datastream->datastream_id, "lon" );
+    xi_datapoint_t* current_lon = &lon_datastream->datapoints[0];
+    
+    // create the cosm library context
+    xi_context_t* xi_context
+        = xi_create_context( XI_HTTP, XI_API_KEY, feed.feed_id );
+
+    // check if everything works
+    if( xi_context == NULL )
+    {
+        printf("xi_context NULL!\n");
+        return -1;
+    }
+
     printf("SMS and GPS Loop\r\n");
     char link[128] = "";
     unsigned int i = 0xFFFFFFFF;
@@ -244,6 +266,11 @@
                         printf("GPS Location: %.5f %.5f\r\n", la, lo); 
                         sprintf(link, "I am here!\n"
                                       "https://maps.google.com/?q=%.5f,%.5f", la, lo); 
+                        // Xively
+                        xi_set_value_f32( current_lat, la );
+                        xi_set_value_f32( current_lon, lo );
+                        xi_feed_update( xi_context, &feed );
+
                     }
                 } else if (!strncmp("$GPGGA", buf, 6)) {
                     double a = 0;