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

Files at this revision

API Documentation at this revision

Comitter:
donatien
Date:
Fri Aug 17 15:53:46 2012 +0000
Parent:
0:f3f18ac13e0c
Child:
2:d1a092234f72
Commit message:
Initial Commit

Changed in this revision

HTTPClient.lib Show annotated file Show diff for this revision Revisions of this file
HTTPClientLibBeta.lib Show diff for this revision Revisions of this file
VodafoneK3770LibBeta.lib Show diff for this revision Revisions of this file
VodafoneUSBModem.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
rtos_net_beta.lib Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTPClient.lib	Fri Aug 17 15:53:46 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/HTTPClient/#be61104f4e91
--- a/HTTPClientLibBeta.lib	Thu May 31 16:06:19 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/donatien/code/HTTPClientLibBeta/#7789bc98c7f3
--- a/VodafoneK3770LibBeta.lib	Thu May 31 16:06:19 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/donatien/code/VodafoneK3770LibBeta/#0ac66acdfdc0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/VodafoneUSBModem.lib	Fri Aug 17 15:53:46 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/VodafoneUSBModem/#4d8fc9e81570
--- a/main.cpp	Thu May 31 16:06:19 2012 +0000
+++ b/main.cpp	Fri Aug 17 15:53:46 2012 +0000
@@ -1,140 +1,68 @@
-/* net_3g_basic_http_test.cpp */
-/*
-Copyright (C) 2012 ARM Limited.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-of the Software, and to permit persons to whom the Software is furnished to do
-so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-*/
-
-#define __DEBUG__ 4 //Maximum verbosity
-#ifndef __MODULE__
-#define __MODULE__ "net_3g_basic_http_test.cpp"
-#endif
-
-#include "core/fwk.h"
 #include "mbed.h"
-
-#include "rtos.h"
-
-#include "if/VodafoneK3770.h"
+#include "VodafoneUSBModem.h"
 #include "HTTPClient.h"
 
-DigitalOut led1(LED1);
-DigitalOut led2(LED2);
-DigitalOut led3(LED3);
-DigitalOut led4(LED4);
-void notify(bool a, bool b, bool c)
-{
-  led1 = a;
-  led2 = b;
-  led3 = c;
-}
-
-extern "C" void HardFault_Handler()
-{
-  error("Hard Fault!\n");
-}
-
-void test(void const*)
+void test(void const*) 
 {
-  VodafoneK3770 threeg;
-  HTTPClient http;
-  char str[512];
-
-  DBG("Hello!");
-  
-  int count = 0;
-
-  start:
-  count++;
-  DBG("iteration #%d", count);
-
-  notify(0, 1, 1);
-  //int ret = threeg.connect("pp.vodafone.co.uk");
-  int ret = threeg.connect("SMART");
-  notify(0, 1, 0);
-  if (ret == OK)
-  {
-    DBG("Trying to fetch page...");
+    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 == OK)
+    if (!ret)
     {
-      DBG("Page fetched successfully - read %d characters", strlen(str));
-      DBG("Result: %s", str);
+      printf("Page fetched successfully - read %d characters\n", strlen(str));
+      printf("Result: %s\n", str);
     }
     else
     {
-      WARN("Error - ret = %d - HTTP return code = %d", ret, http.getHTTPResponseCode());
+      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");
-    DBG("Trying to post data...");
+    printf("Trying to post data...\n");
     ret = http.post("http://httpbin.org/post", map, &text);
-    if (ret == OK)
+    if (!ret)
     {
-      DBG("Executed POST successfully - read %d characters", strlen(str));
-      DBG("Result: %s", str);
+      printf("Executed POST successfully - read %d characters\n", strlen(str));
+      printf("Result: %s\n", str);
     }
     else
     {
-      WARN("Error - ret = %d - HTTP return code = %d", ret, http.getHTTPResponseCode());
+      printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
     }
-  }
-  threeg.disconnect();
-  DBG("Disconnected");
+    
+    modem.disconnect();  
 
-  notify(1, 1, 1);
-
-  goto start;
-
-  while (1)
-  {
-    Thread::wait(100);
-  }
+    while(1) {
+    }
 }
 
-void keepAlive(void const*)
-{
-  while (1)
-  {
-    led1 = !led1;
-    Thread::wait(500);
-  }
-}
-
-void tick()
-{
-  led4 = !led4;
-}
 
 int main()
 {
-  Ticker t;
-  t.attach(tick, 1);
-  DBG_INIT();
-
-  notify(1, 0, 0);
-
   Thread testTask(test, NULL, osPriorityNormal, 1024 * 4);
-  keepAlive(NULL);
+  DigitalOut led(LED1);
+  while(1)
+  {
+    led=!led;
+    Thread::wait(1000);  
+  }
 
   return 0;
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Fri Aug 17 15:53:46 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#9654a71f5a90
--- a/mbed.bld	Thu May 31 16:06:19 2012 +0000
+++ b/mbed.bld	Fri Aug 17 15:53:46 2012 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/737756e0b479
+http://mbed.org/users/mbed_official/code/mbed/builds/10b9abbe79a6
\ No newline at end of file
--- a/rtos_net_beta.lib	Thu May 31 16:06:19 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/donatien/code/rtos_net_beta/#e6ccf0b3d718