Example demonstrating the use of the Vodafone USB Modem library with the HTTP Client

Dependencies:   HTTPClient VodafoneUSBModem mbed-rtos mbed

Fork of VodafoneK3770HTTPClientTestBeta by Donatien Garnier

main.cpp

Committer:
donatien
Date:
2012-08-17
Revision:
1:6ea9ac27702c
Parent:
0:f3f18ac13e0c
Child:
2:d1a092234f72

File content as of revision 1:6ea9ac27702c:

#include "mbed.h"
#include "VodafoneUSBModem.h"
#include "HTTPClient.h"

void test(void const*) 
{
    VodafoneUSBModem modem;
    HTTPClient http;
    char str[512];
    
    //int ret = modem.connect("pp.vodafone.co.uk");
    //int ret = modem.connect("SMART");
    int ret = modem.connect("websfr");
    if(ret)
    {
      printf("Could not connect\n");
      return;
    }
    
    //GET data
    printf("Trying to fetch page...\n");
    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 text(str, 512);
    map.put("Hello", "World");
    map.put("test", "1234");
    printf("Trying to post data...\n");
    ret = http.post("http://httpbin.org/post", 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();  

    while(1) {
    }
}


int main()
{
  Thread testTask(test, NULL, osPriorityNormal, 1024 * 4);
  DigitalOut led(LED1);
  while(1)
  {
    led=!led;
    Thread::wait(1000);  
  }

  return 0;
}