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

main.cpp

Committer:
vwochnik
Date:
2014-01-30
Revision:
3:32834ef7cb56
Parent:
0:ed4d6fd405ea
Child:
4:363b4cc49445

File content as of revision 3:32834ef7cb56:

#include "mbed.h"
#include "C027.h"
#include "UbloxUSBGSMModem.h"
#include "UbloxUSBCDMAModem.h"

#include "HTTPClient.h"

C027 c027;

void test(void const*)
{
    c027.mdmPower(true);
    UbloxUSBGSMModem modem; // for LISA-C use the UbloxUSBCDMAModem instead
    HTTPClient http;
    char str[512];

    int ret = modem.connect("public4.m2minternet.com"); // eventaully set another apn here
    if(ret)
    {
        printf("Could not connect %d\n", ret);
        return;
    }
    
    http.basicAuth("vaillant/admin", "klanpi");
    
    char *hkey = "X-Id";char *hval = "com_test_device";
    char *harr[] = {hkey, hval};
    
    http.customHeaders(harr, 1);
    
    //GET data
    printf("Trying to fetch page...\n");
    ret = http.get("http://nocore.info:8888", 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 text(str, 512);
    map.put("Hello", "World");
    map.put("test", "1234");
    printf("Trying to post data...\n");
    ret = http.post("http://nocore.info:8888", map, &text);
    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());
    }

    modem.disconnect();
    c027.mdmPower(false);
    
    while(1) {
    }
}


int main()
{
    Thread testTask(test, NULL, osPriorityNormal, 1024 * 4);
    DigitalOut led(LED); // on rev A you should reasign the signal to A0
    while(1) {
        led=!led;
        Thread::wait(1000);
    }

    return 0;
}