インターフェース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
インターフェース2014年10月号のu-blox C027で3G通信する記事で使用したプログラムです。
Revision 33:65bcfee03271, committed 2014-07-28
- Comitter:
- ntaka206
- Date:
- Mon Jul 28 03:25:18 2014 +0000
- Parent:
- 32:2ad9c1d1afd0
- Commit message:
- Modify comments
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 2ad9c1d1afd0 -r 65bcfee03271 main.cpp --- a/main.cpp Thu Jul 24 11:08:18 2014 +0000 +++ b/main.cpp Mon Jul 28 03:25:18 2014 +0000 @@ -44,8 +44,6 @@ #define XI_API_KEY "SET your Feed API KEY" // set Xively API key (double-quoted string) #define XI_SERVER "api.xively.com" -//#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 ".json" #define XI_HEADER "X-ApiKey: " XI_API_KEY @@ -56,21 +54,14 @@ int main(void) { int ret; -#ifdef LARGE_DATA - char buf[2048] = ""; -#else char buf[512] = ""; -#endif -// ntaka -Serial pc(USBTX,USBRX); -pc.baud(115200); + // Add by ntaka for USB Console + Serial pc(USBTX,USBRX); + pc.baud(115200); // Create the GPS object -#if 1 // use GPSI2C class + // use GPSI2C class GPSI2C gps; -#else // or GPSSerial class - GPSSerial gps; -#endif // Create the modem object MDMSerial mdm; //mdm.setDebug(4); // enable this for debugging issues @@ -99,8 +90,6 @@ mdmOk = mdm.registerNet(&netStatus); mdm.dumpNetStatus(&netStatus); } -#if 1 - if (mdmOk) { // http://www.geckobeach.com/cellular/secrets/gsmcodes.php @@ -139,31 +128,6 @@ const char* host = "echo.u-blox.com"; MDMParser::IP ip = mdm.gethostbyname(host); char data[] = "\r\nxxx Socket Hello World\r\n" -#ifdef LARGE_DATA - "00 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" - "01 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" - "02 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" - "03 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" - "04 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" - - "05 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" - "06 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" - "07 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" - "08 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" - "09 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" - - "10 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" - "11 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" - "12 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" - "13 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" - "14 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" - - "15 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" - "16 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" - "17 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" - "18 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" - "19 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" -#endif "End\r\n"; printf("Testing TCP sockets with ECHO server\r\n"); @@ -209,10 +173,8 @@ // mdm.disconnect(); } } -#endif -// Xively - + // Upload GPS data to Xively printf("SMS and GPS Loop\r\n"); char link[128] = ""; unsigned int i = 0xFFFFFFFF; @@ -238,7 +200,7 @@ 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 + // Upload to Xively if (xv_upload_cnt++ >= XI_UPLOAD_INTERVAL) { xv_upload_cnt = 0; int socket = mdm.socketSocket(MDMParser::IPPROTO_TCP); @@ -249,7 +211,7 @@ { // char data[128]; // sprintf(data, "lat,%f\r\nlon,%f\r\n", la, lo); - // JSON location + // Make JSON location picojson::object v; picojson::object loc; string mb="mobile"; @@ -258,16 +220,16 @@ loc["lat"] = picojson::value(la); loc["lon"] = picojson::value(lo); v["location"] = picojson::value(loc); - + // JSON serialize string str = picojson::value(v).serialize(); // printf("serialized content = %s\r\n" , str.c_str()); - + // PUT HTTP data to Xively 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); mdm.socketSend(socket, http, strlen(http)); - + // Recv responce ret = mdm.socketRecv(socket, buf, sizeof(buf)-1); if (ret > 0) printf("Socket Recv \"%*s\"\r\n", ret, buf);