![](/media/cache/profiles/6d042df5f90546ecee8736241d28dbe1.jpg.50x50_q85.jpg)
HTTP Client test for AbitUSBModem. see: http://developer.mbed.org/users/phsfan/notebook/abitusbmodem/
Dependencies: AbitUSBModem USBHost mbed
main.cpp@0:35cf1b2fc6e2, 2015-02-19 (annotated)
- Committer:
- phsfan
- Date:
- Thu Feb 19 00:08:49 2015 +0000
- Revision:
- 0:35cf1b2fc6e2
1st build;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
phsfan | 0:35cf1b2fc6e2 | 1 | #include "mbed.h" |
phsfan | 0:35cf1b2fc6e2 | 2 | #include "AbitUSBModem.h" |
phsfan | 0:35cf1b2fc6e2 | 3 | #include "TinyHTTP.h" |
phsfan | 0:35cf1b2fc6e2 | 4 | #include <new> |
phsfan | 0:35cf1b2fc6e2 | 5 | |
phsfan | 0:35cf1b2fc6e2 | 6 | Serial pc(USBTX, USBRX); |
phsfan | 0:35cf1b2fc6e2 | 7 | DigitalOut myled(LED1); |
phsfan | 0:35cf1b2fc6e2 | 8 | |
phsfan | 0:35cf1b2fc6e2 | 9 | void callback (char *buf, int len) { |
phsfan | 0:35cf1b2fc6e2 | 10 | buf[len] = 0; |
phsfan | 0:35cf1b2fc6e2 | 11 | printf(buf); |
phsfan | 0:35cf1b2fc6e2 | 12 | } |
phsfan | 0:35cf1b2fc6e2 | 13 | |
phsfan | 0:35cf1b2fc6e2 | 14 | void test(void const*) |
phsfan | 0:35cf1b2fc6e2 | 15 | { |
phsfan | 0:35cf1b2fc6e2 | 16 | AbitUSBModem modem; |
phsfan | 0:35cf1b2fc6e2 | 17 | |
phsfan | 0:35cf1b2fc6e2 | 18 | printf("connect\r\n"); |
phsfan | 0:35cf1b2fc6e2 | 19 | int ret = modem.connect("prin", "prin"); |
phsfan | 0:35cf1b2fc6e2 | 20 | if(ret) { |
phsfan | 0:35cf1b2fc6e2 | 21 | printf("Could not connect\r\n"); |
phsfan | 0:35cf1b2fc6e2 | 22 | return; |
phsfan | 0:35cf1b2fc6e2 | 23 | } |
phsfan | 0:35cf1b2fc6e2 | 24 | |
phsfan | 0:35cf1b2fc6e2 | 25 | printf("IP Address %s\r\n", modem.getIPAddress()); |
phsfan | 0:35cf1b2fc6e2 | 26 | |
phsfan | 0:35cf1b2fc6e2 | 27 | //GET data |
phsfan | 0:35cf1b2fc6e2 | 28 | printf("Trying to fetch page...\r\n"); |
phsfan | 0:35cf1b2fc6e2 | 29 | httpRequest(METHOD_GET, "developer.mbed.org", 80, "/media/uploads/phsfan/hello.txt", NULL, NULL, callback); |
phsfan | 0:35cf1b2fc6e2 | 30 | printf("\r\n"); |
phsfan | 0:35cf1b2fc6e2 | 31 | |
phsfan | 0:35cf1b2fc6e2 | 32 | Thread::wait(1000); |
phsfan | 0:35cf1b2fc6e2 | 33 | printf("exit\r\n"); |
phsfan | 0:35cf1b2fc6e2 | 34 | modem.disconnect(); |
phsfan | 0:35cf1b2fc6e2 | 35 | } |
phsfan | 0:35cf1b2fc6e2 | 36 | |
phsfan | 0:35cf1b2fc6e2 | 37 | int main() |
phsfan | 0:35cf1b2fc6e2 | 38 | { |
phsfan | 0:35cf1b2fc6e2 | 39 | pc.baud(115200); |
phsfan | 0:35cf1b2fc6e2 | 40 | printf("** PHS\r\n"); |
phsfan | 0:35cf1b2fc6e2 | 41 | |
phsfan | 0:35cf1b2fc6e2 | 42 | Thread testTask(test, NULL, osPriorityNormal, 1024 * 4); |
phsfan | 0:35cf1b2fc6e2 | 43 | while(1) { |
phsfan | 0:35cf1b2fc6e2 | 44 | myled = !myled; |
phsfan | 0:35cf1b2fc6e2 | 45 | Thread::wait(1000); |
phsfan | 0:35cf1b2fc6e2 | 46 | } |
phsfan | 0:35cf1b2fc6e2 | 47 | } |