test

Dependencies:   C027 HTTPClient UbloxUSBModem mbed

Fork of C027_HTTPClientTest by u-blox

Committer:
vwochnik
Date:
Wed Feb 19 16:10:01 2014 +0000
Revision:
11:ab536fc3a722
Parent:
10:e2315bcdd7be
Child:
13:bcdb607b2c76
fix

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 0:f3f18ac13e0c 1 #include "mbed.h"
mazgch 6:77c131006c67 2 #include "C027.h"
mazgch 6:77c131006c67 3 #include "UbloxUSBGSMModem.h"
mazgch 6:77c131006c67 4
donatien 0:f3f18ac13e0c 5 #include "HTTPClient.h"
donatien 0:f3f18ac13e0c 6
mazgch 10:e2315bcdd7be 7 C027 c027;
mazgch 10:e2315bcdd7be 8
vwochnik 11:ab536fc3a722 9 int main(void)
donatien 0:f3f18ac13e0c 10 {
vwochnik 11:ab536fc3a722 11 c027.mdmWakeup();
vwochnik 11:ab536fc3a722 12 c027.mdmReset();
vwochnik 11:ab536fc3a722 13 c027.mdmPower(true);
mazgch 6:77c131006c67 14 UbloxUSBGSMModem modem; // for LISA-C use the UbloxUSBCDMAModem instead
donatien 1:6ea9ac27702c 15 HTTPClient http;
donatien 1:6ea9ac27702c 16 char str[512];
mazgch 7:c558c74ceb0f 17
vwochnik 11:ab536fc3a722 18 puts("Trying to connect to modem...");
vwochnik 11:ab536fc3a722 19 int ret = modem.connect("public4.m2minternet.com"); // eventaully set another apn here
mazgch 8:95a97898084a 20 if(ret)
mazgch 8:95a97898084a 21 {
mazgch 8:95a97898084a 22 printf("Could not connect %d\n", ret);
mazgch 7:c558c74ceb0f 23 return;
donatien 1:6ea9ac27702c 24 }
mazgch 8:95a97898084a 25
donatien 1:6ea9ac27702c 26 //GET data
donatien 1:6ea9ac27702c 27 printf("Trying to fetch page...\n");
vwochnik 11:ab536fc3a722 28 ret = http.get("http://nocore.info:8888/", str, 128);
mazgch 7:c558c74ceb0f 29 if (!ret) {
mazgch 7:c558c74ceb0f 30 printf("Page fetched successfully - read %d characters\n", strlen(str));
mazgch 7:c558c74ceb0f 31 printf("Result: %s\n", str);
mazgch 7:c558c74ceb0f 32 } else {
mazgch 7:c558c74ceb0f 33 printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
donatien 0:f3f18ac13e0c 34 }
mazgch 7:c558c74ceb0f 35
donatien 1:6ea9ac27702c 36 //POST data
donatien 0:f3f18ac13e0c 37 HTTPText text(str, 512);
vwochnik 11:ab536fc3a722 38 HTTPText data("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890");
vwochnik 11:ab536fc3a722 39 //HTTPText data("23123123lala");
donatien 1:6ea9ac27702c 40 printf("Trying to post data...\n");
vwochnik 11:ab536fc3a722 41 ret = http.post("http://nocore.info:8888/", data, &text);
mazgch 7:c558c74ceb0f 42 if (!ret) {
mazgch 7:c558c74ceb0f 43 printf("Executed POST successfully - read %d characters\n", strlen(str));
mazgch 7:c558c74ceb0f 44 printf("Result: %s\n", str);
mazgch 7:c558c74ceb0f 45 } else {
mazgch 7:c558c74ceb0f 46 printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
donatien 0:f3f18ac13e0c 47 }
mazgch 7:c558c74ceb0f 48
mazgch 7:c558c74ceb0f 49 modem.disconnect();
mazgch 10:e2315bcdd7be 50 c027.mdmPower(false);
mazgch 10:e2315bcdd7be 51
mazgch 7:c558c74ceb0f 52 return 0;
donatien 0:f3f18ac13e0c 53 }