smart rest test program

Dependencies:   C027 MbedSmartRest UbloxUSBModem mbed

Committer:
vwochnik
Date:
Fri Jan 24 21:06:09 2014 +0000
Revision:
0:ed4d6fd405ea
program

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vwochnik 0:ed4d6fd405ea 1 #include "mbed.h"
vwochnik 0:ed4d6fd405ea 2 #include "C027.h"
vwochnik 0:ed4d6fd405ea 3 #include "UbloxUSBGSMModem.h"
vwochnik 0:ed4d6fd405ea 4 #include "UbloxUSBCDMAModem.h"
vwochnik 0:ed4d6fd405ea 5
vwochnik 0:ed4d6fd405ea 6 #include "HTTPClient.h"
vwochnik 0:ed4d6fd405ea 7
vwochnik 0:ed4d6fd405ea 8 C027 c027;
vwochnik 0:ed4d6fd405ea 9
vwochnik 0:ed4d6fd405ea 10 void test(void const*)
vwochnik 0:ed4d6fd405ea 11 {
vwochnik 0:ed4d6fd405ea 12 c027.mdmPower(true);
vwochnik 0:ed4d6fd405ea 13 UbloxUSBGSMModem modem; // for LISA-C use the UbloxUSBCDMAModem instead
vwochnik 0:ed4d6fd405ea 14 HTTPClient http;
vwochnik 0:ed4d6fd405ea 15 char str[512];
vwochnik 0:ed4d6fd405ea 16
vwochnik 0:ed4d6fd405ea 17 int ret = modem.connect("internet"); // eventaully set another apn here
vwochnik 0:ed4d6fd405ea 18 if(ret)
vwochnik 0:ed4d6fd405ea 19 {
vwochnik 0:ed4d6fd405ea 20 printf("Could not connect %d\n", ret);
vwochnik 0:ed4d6fd405ea 21 return;
vwochnik 0:ed4d6fd405ea 22 }
vwochnik 0:ed4d6fd405ea 23
vwochnik 0:ed4d6fd405ea 24 //GET data
vwochnik 0:ed4d6fd405ea 25 printf("Trying to fetch page...\n");
vwochnik 0:ed4d6fd405ea 26 ret = http.get("http://mbed.org/media/uploads/donatien/hello.txt", str, 128);
vwochnik 0:ed4d6fd405ea 27 if (!ret) {
vwochnik 0:ed4d6fd405ea 28 printf("Page fetched successfully - read %d characters\n", strlen(str));
vwochnik 0:ed4d6fd405ea 29 printf("Result: %s\n", str);
vwochnik 0:ed4d6fd405ea 30 } else {
vwochnik 0:ed4d6fd405ea 31 printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
vwochnik 0:ed4d6fd405ea 32 }
vwochnik 0:ed4d6fd405ea 33
vwochnik 0:ed4d6fd405ea 34 //POST data
vwochnik 0:ed4d6fd405ea 35 HTTPMap map;
vwochnik 0:ed4d6fd405ea 36 HTTPText text(str, 512);
vwochnik 0:ed4d6fd405ea 37 map.put("Hello", "World");
vwochnik 0:ed4d6fd405ea 38 map.put("test", "1234");
vwochnik 0:ed4d6fd405ea 39 printf("Trying to post data...\n");
vwochnik 0:ed4d6fd405ea 40 ret = http.post("http://httpbin.org/post", map, &text);
vwochnik 0:ed4d6fd405ea 41 if (!ret) {
vwochnik 0:ed4d6fd405ea 42 printf("Executed POST successfully - read %d characters\n", strlen(str));
vwochnik 0:ed4d6fd405ea 43 printf("Result: %s\n", str);
vwochnik 0:ed4d6fd405ea 44 } else {
vwochnik 0:ed4d6fd405ea 45 printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
vwochnik 0:ed4d6fd405ea 46 }
vwochnik 0:ed4d6fd405ea 47
vwochnik 0:ed4d6fd405ea 48 modem.disconnect();
vwochnik 0:ed4d6fd405ea 49 c027.mdmPower(false);
vwochnik 0:ed4d6fd405ea 50
vwochnik 0:ed4d6fd405ea 51 while(1) {
vwochnik 0:ed4d6fd405ea 52 }
vwochnik 0:ed4d6fd405ea 53 }
vwochnik 0:ed4d6fd405ea 54
vwochnik 0:ed4d6fd405ea 55
vwochnik 0:ed4d6fd405ea 56 int main()
vwochnik 0:ed4d6fd405ea 57 {
vwochnik 0:ed4d6fd405ea 58 Thread testTask(test, NULL, osPriorityNormal, 1024 * 4);
vwochnik 0:ed4d6fd405ea 59 DigitalOut led(LED); // on rev A you should reasign the signal to A0
vwochnik 0:ed4d6fd405ea 60 while(1) {
vwochnik 0:ed4d6fd405ea 61 led=!led;
vwochnik 0:ed4d6fd405ea 62 Thread::wait(1000);
vwochnik 0:ed4d6fd405ea 63 }
vwochnik 0:ed4d6fd405ea 64
vwochnik 0:ed4d6fd405ea 65 return 0;
vwochnik 0:ed4d6fd405ea 66 }