![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Sample code for connecting u-blox c027 to AerCloud
Dependencies: C027_Support_AerCloud HTTPClient_AerCloud mbed
Fork of HTTPClient_Cellular_HelloWorld by
Diff: main.cpp
- Revision:
- 3:412a526d7054
- Parent:
- 2:270e2d0bb85a
- Child:
- 4:7fd97087e573
--- a/main.cpp Thu Aug 30 15:42:06 2012 +0000 +++ b/main.cpp Mon May 12 09:17:35 2014 +0000 @@ -1,79 +1,125 @@ #include "mbed.h" -#include "EthernetInterface.h" #include "HTTPClient.h" +#include "C027.h" +#include "MDM.h" -EthernetInterface eth; -HTTPClient http; +//---------------------------------------------------------------------- +// You may need to configure these parameters + +/** Set your secret SIM pin here "1234" +*/ +#define SIMPIN NULL + +/** The APN of your network operator, sometimes it is "internet" + check your contract with the network operator +*/ +#define APN "gprs.swisscom.ch" + +/** Set the user name for your APN, or NULL if not needed +*/ +#define USERNAME NULL + +/** Set the password for your APN, or NULL if not needed +*/ +#define PASSWORD NULL + +C027 c027; + char str[512]; int main() { - eth.init(); //Use DHCP - - eth.connect(); - - //GET data - printf("\nTrying to fetch page...\n"); - int ret = http.get("http://mbed.org/media/uploads/donatien/hello.txt", str, 128); - if (!ret) - { - printf("Page fetched successfully - read %d characters\n", strlen(str)); - printf("Result: %s\n", str); - } - else - { - printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); - } + // turn on the supplies of the Modem and the GPS + c027.mdmPower(true); + wait(2); + // Create the modem object + MDMSerial mdm; - //POST data - HTTPMap map; - HTTPText inText(str, 512); - map.put("Hello", "World"); - map.put("test", "1234"); - printf("\nTrying to post data...\n"); - ret = http.post("http://httpbin.org/post", map, &inText); - if (!ret) + // initialize the modem + printf("Modem Initialize\r\n"); + MDMParser::DevStatus devStatus; + bool mdmOk = mdm.init(SIMPIN, &devStatus); + if (mdmOk) { - printf("Executed POST successfully - read %d characters\n", strlen(str)); - printf("Result: %s\n", str); - } - else - { - printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); - } + // wait until we are connected + printf("Network Check\r\n"); + MDMParser::NetStatus netStatus; + while (!mdm.checkNetStatus(&netStatus)) + wait_ms(1000); + + printf("Network Join\r\n"); + // join the internet connection + MDMParser::IP ip = mdm.join(APN,USERNAME,PASSWORD); + if (ip != NOIP) + { + printf(" IP Address: " IPSTR "\r\n", IPNUM(ip)); + HTTPClient http; - //PUT data - strcpy(str, "This is a PUT test!"); - HTTPText outText(str); - //HTTPText inText(str, 512); - printf("\nTrying to put resource...\n"); - ret = http.put("http://httpbin.org/put", outText, &inText); - if (!ret) - { - printf("Executed PUT successfully - read %d characters\n", strlen(str)); - printf("Result: %s\n", str); - } - else - { - printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); - } + //GET data + printf("\nTrying to fetch page...\n"); + int ret = http.get("http://mbed.org/media/uploads/donatien/hello.txt", str, 128); + if (!ret) + { + printf("Page fetched successfully - read %d characters\n", strlen(str)); + printf("Result: %s\n", str); + } + else + { + printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); + } + + //POST data + HTTPMap map; + HTTPText inText(str, 512); + map.put("Hello", "World"); + map.put("test", "1234"); + printf("\nTrying to post data...\n"); + ret = http.post("http://httpbin.org/post", map, &inText); + if (!ret) + { + printf("Executed POST successfully - read %d characters\n", strlen(str)); + printf("Result: %s\n", str); + } + else + { + printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); + } + + //PUT data + strcpy(str, "This is a PUT test!"); + HTTPText outText(str); + //HTTPText inText(str, 512); + printf("\nTrying to put resource...\n"); + ret = http.put("http://httpbin.org/put", outText, &inText); + if (!ret) + { + printf("Executed PUT successfully - read %d characters\n", strlen(str)); + printf("Result: %s\n", str); + } + else + { + printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); + } + + //DELETE data + //HTTPText inText(str, 512); + printf("\nTrying to delete resource...\n"); + ret = http.del("http://httpbin.org/delete", &inText); + if (!ret) + { + printf("Executed DELETE successfully - read %d characters\n", strlen(str)); + printf("Result: %s\n", str); + } + else + { + printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); + } - //DELETE data - //HTTPText inText(str, 512); - printf("\nTrying to delete resource...\n"); - ret = http.del("http://httpbin.org/delete", &inText); - if (!ret) - { - printf("Executed DELETE successfully - read %d characters\n", strlen(str)); - printf("Result: %s\n", str); + mdm.disconnect(); + } } - else - { - printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); - } + mdm.powerOff(); + c027.mdmPower(false); - eth.disconnect(); - - while(1) { - } + while(true); }