インターフェース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通信する記事で使用したプログラムです。

Files at this revision

API Documentation at this revision

Comitter:
ntaka206
Date:
Thu Jul 17 13:47:03 2014 +0000
Parent:
30:e6c7827dfbe8
Child:
32:2ad9c1d1afd0
Commit message:
JSON???location?update???????; picojson??;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
picojson.lib Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Jul 17 10:06:02 2014 +0000
+++ b/main.cpp	Thu Jul 17 13:47:03 2014 +0000
@@ -15,6 +15,8 @@
 */
 #include "GPS.h"
 #include "MDM.h"
+#include "picojson.h"
+
 //------------------------------------------------------------------------------------
 // You need to configure these cellular modem / SIM parameters.
 // These parameters are ignored for LISA-C200 variants and can be left NULL.
@@ -41,10 +43,10 @@
 //#define XI_PATH     "POST /v2/feeds/" XI_FEED_ID ".csv?_method=put "
 //#define XI_HEADER   "X-ApiKey: " XI_API_KEY "\r\nContent-Type: text/csv\r\n"
 
-#define XI_PATH     "/v2/feeds/" XI_FEED_ID ".csv"
+#define XI_PATH     "/v2/feeds/" XI_FEED_ID ".json"
 #define XI_HEADER   "X-ApiKey: " XI_API_KEY
 
-#define XI_UPLOAD_INTERVAL   30  // sec
+#define XI_UPLOAD_INTERVAL   2  // sec
 //------------------------------------------------------------------------------------
 
 int main(void)
@@ -233,33 +235,43 @@
                         sprintf(link, "I am here!\n"
                                       "https://maps.google.com/?q=%.5f,%.5f", la, lo); 
 // Xively
-        if (xv_upload_cnt++ >= XI_UPLOAD_INTERVAL) {
-            xv_upload_cnt = 0;
-            int socket = mdm.socketSocket(MDMParser::IPPROTO_TCP);
-            if (socket >= 0)
-            {
-                mdm.socketSetBlocking(socket, 10000);
-                if (mdm.socketConnect(socket, XI_SERVER, 80))
-                {
-                    
-//                    const char http[] = "POST /media/uploads/mbed_official/hello.txt HTTP/1.0\r\n\r\n";
-//                    mdm.socketSend(socket, XI_PATH, sizeof(XI_PATH)-1);
-//                    mdm.socketSend(socket, XI_HEADER, sizeof(XI_HEADER)-1);
-                    char http[512];
-                    char data[128];
-                    sprintf(data, "lat,%f\r\nlon,%f\r\n", la, lo);
-                    sprintf(http, "PUT %s HTTP/1.1\r\nHost: %s\r\n%s\r\nContent-Length: %d\r\n\r\n%s", XI_PATH, XI_SERVER, XI_HEADER, strlen(data), data);
-printf(http);
-                    mdm.socketSend(socket, http, strlen(http));
+                        if (xv_upload_cnt++ >= XI_UPLOAD_INTERVAL) {
+                            xv_upload_cnt = 0;
+                            int socket = mdm.socketSocket(MDMParser::IPPROTO_TCP);
+                            if (socket >= 0)
+                            {
+                                mdm.socketSetBlocking(socket, 10000);
+                                if (mdm.socketConnect(socket, XI_SERVER, 80))
+                                {
+                //                    char data[128];
+                //                    sprintf(data, "lat,%f\r\nlon,%f\r\n", la, lo);
+                                    // JSON location
+                                    picojson::object v;
+                                    picojson::object loc;
+                                    string mb="mobile";
+                                 
+                                    loc["disposition"] =  picojson::value(mb);
+                                    loc["lat"] =  picojson::value(la);
+                                    loc["lon"] =  picojson::value(lo);
+                                    v["location"] =  picojson::value(loc);
+                                 
+                                    string str = picojson::value(v).serialize();
+//                                    printf("serialized content = %s\r\n" ,  str.c_str());
+                
+                                    char http[512];
+                                    sprintf(http, "PUT %s HTTP/1.1\r\nHost: %s\r\n%s\r\nContent-Length: %d\r\n\r\n%s\r\n", XI_PATH, XI_SERVER, XI_HEADER, strlen(str.c_str()), str.c_str());
+                                    printf(http);
 
-                    ret = mdm.socketRecv(socket, buf, sizeof(buf)-1);
-                    if (ret > 0)
-                        printf("Socket Recv \"%*s\"\r\n", ret, buf);
-                    mdm.socketClose(socket);
-                }
-                mdm.socketFree(socket);
-            }
-        }
+                                    mdm.socketSend(socket, http, strlen(http));
+                
+                                    ret = mdm.socketRecv(socket, buf, sizeof(buf)-1);
+                                    if (ret > 0)
+                                        printf("Socket Recv \"%*s\"\r\n", ret, buf);
+                                    mdm.socketClose(socket);
+                                }
+                                mdm.socketFree(socket);
+                            }
+                        }
                     }
                 } else if (!strncmp("$GPGGA", buf, 6)) {
                     double a = 0; 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/picojson.lib	Thu Jul 17 13:47:03 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mimil/code/picojson/#2bb500b021e2