HTTP Client test for AbitUSBModem. see: http://developer.mbed.org/users/phsfan/notebook/abitusbmodem/

Dependencies:   AbitUSBModem USBHost mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "AbitUSBModem.h"
00003 #include "TinyHTTP.h"
00004 #include <new>
00005 
00006 Serial pc(USBTX, USBRX);
00007 DigitalOut myled(LED1);
00008 
00009 void callback (char *buf, int len) {
00010     buf[len] = 0;
00011     printf(buf);
00012 }
00013 
00014 void test(void const*) 
00015 {
00016     AbitUSBModem modem;
00017 
00018     printf("connect\r\n");
00019     int ret = modem.connect("prin", "prin");
00020     if(ret) {
00021       printf("Could not connect\r\n");
00022       return;
00023     }
00024 
00025     printf("IP Address %s\r\n", modem.getIPAddress());
00026 
00027     //GET data
00028     printf("Trying to fetch page...\r\n");
00029     httpRequest(METHOD_GET, "developer.mbed.org", 80, "/media/uploads/phsfan/hello.txt", NULL, NULL, callback);
00030     printf("\r\n");
00031 
00032     Thread::wait(1000);
00033     printf("exit\r\n");
00034     modem.disconnect();  
00035 }
00036 
00037 int main()
00038 {
00039     pc.baud(115200); 
00040     printf("** PHS\r\n");
00041 
00042     Thread testTask(test, NULL, osPriorityNormal, 1024 * 4);
00043     while(1) {
00044         myled = !myled;
00045         Thread::wait(1000);  
00046     }
00047 }