SmartREST client reference implementation for the u-blox C027 mbed compatible device.

Dependencies:   C027 C027_Support mbed mbed-rtos MbedSmartRest LM75B MMA7660 C12832

Fork of MbedSmartRestTest by Vincent Wochnik

Committer:
vwochnik
Date:
Thu Jan 30 11:47:29 2014 +0000
Revision:
3:32834ef7cb56
Parent:
0:ed4d6fd405ea
Child:
4:363b4cc49445
fix

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 3:32834ef7cb56 17 int ret = modem.connect("public4.m2minternet.com"); // 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 3:32834ef7cb56 24 http.basicAuth("vaillant/admin", "klanpi");
vwochnik 3:32834ef7cb56 25
vwochnik 3:32834ef7cb56 26 char *hkey = "X-Id";char *hval = "com_test_device";
vwochnik 3:32834ef7cb56 27 char *harr[] = {hkey, hval};
vwochnik 3:32834ef7cb56 28
vwochnik 3:32834ef7cb56 29 http.customHeaders(harr, 1);
vwochnik 3:32834ef7cb56 30
vwochnik 0:ed4d6fd405ea 31 //GET data
vwochnik 0:ed4d6fd405ea 32 printf("Trying to fetch page...\n");
vwochnik 3:32834ef7cb56 33 ret = http.get("http://nocore.info:8888", str, 128);
vwochnik 0:ed4d6fd405ea 34 if (!ret) {
vwochnik 0:ed4d6fd405ea 35 printf("Page fetched successfully - read %d characters\n", strlen(str));
vwochnik 0:ed4d6fd405ea 36 printf("Result: %s\n", str);
vwochnik 0:ed4d6fd405ea 37 } else {
vwochnik 0:ed4d6fd405ea 38 printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
vwochnik 0:ed4d6fd405ea 39 }
vwochnik 0:ed4d6fd405ea 40
vwochnik 0:ed4d6fd405ea 41 //POST data
vwochnik 0:ed4d6fd405ea 42 HTTPMap map;
vwochnik 0:ed4d6fd405ea 43 HTTPText text(str, 512);
vwochnik 0:ed4d6fd405ea 44 map.put("Hello", "World");
vwochnik 0:ed4d6fd405ea 45 map.put("test", "1234");
vwochnik 0:ed4d6fd405ea 46 printf("Trying to post data...\n");
vwochnik 3:32834ef7cb56 47 ret = http.post("http://nocore.info:8888", map, &text);
vwochnik 0:ed4d6fd405ea 48 if (!ret) {
vwochnik 0:ed4d6fd405ea 49 printf("Executed POST successfully - read %d characters\n", strlen(str));
vwochnik 0:ed4d6fd405ea 50 printf("Result: %s\n", str);
vwochnik 0:ed4d6fd405ea 51 } else {
vwochnik 0:ed4d6fd405ea 52 printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
vwochnik 0:ed4d6fd405ea 53 }
vwochnik 0:ed4d6fd405ea 54
vwochnik 0:ed4d6fd405ea 55 modem.disconnect();
vwochnik 0:ed4d6fd405ea 56 c027.mdmPower(false);
vwochnik 0:ed4d6fd405ea 57
vwochnik 0:ed4d6fd405ea 58 while(1) {
vwochnik 0:ed4d6fd405ea 59 }
vwochnik 0:ed4d6fd405ea 60 }
vwochnik 0:ed4d6fd405ea 61
vwochnik 0:ed4d6fd405ea 62
vwochnik 0:ed4d6fd405ea 63 int main()
vwochnik 0:ed4d6fd405ea 64 {
vwochnik 0:ed4d6fd405ea 65 Thread testTask(test, NULL, osPriorityNormal, 1024 * 4);
vwochnik 0:ed4d6fd405ea 66 DigitalOut led(LED); // on rev A you should reasign the signal to A0
vwochnik 0:ed4d6fd405ea 67 while(1) {
vwochnik 0:ed4d6fd405ea 68 led=!led;
vwochnik 0:ed4d6fd405ea 69 Thread::wait(1000);
vwochnik 0:ed4d6fd405ea 70 }
vwochnik 0:ed4d6fd405ea 71
vwochnik 0:ed4d6fd405ea 72 return 0;
vwochnik 0:ed4d6fd405ea 73 }