公式ホームページのPlogramでエラーが発生してビルドに失敗するので作成しました。

Dependencies:   C12832 EthernetInterface HTTPClient mbed-rtos mbed

Committer:
txracing
Date:
Sat Apr 05 04:47:58 2014 +0000
Revision:
0:16eef181c81e
test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
txracing 0:16eef181c81e 1 #include "mbed.h"
txracing 0:16eef181c81e 2 #include "EthernetInterface.h"
txracing 0:16eef181c81e 3 #include "HTTPClient.h"
txracing 0:16eef181c81e 4 #include "C12832.h"
txracing 0:16eef181c81e 5
txracing 0:16eef181c81e 6 EthernetInterface eth;
txracing 0:16eef181c81e 7 HTTPClient http;
txracing 0:16eef181c81e 8 char str[512];
txracing 0:16eef181c81e 9
txracing 0:16eef181c81e 10 C12832 lcd(p5, p7, p6, p8, p11);
txracing 0:16eef181c81e 11
txracing 0:16eef181c81e 12 int main()
txracing 0:16eef181c81e 13 {
txracing 0:16eef181c81e 14 eth.init(); //Use DHCP
txracing 0:16eef181c81e 15
txracing 0:16eef181c81e 16 eth.connect();
txracing 0:16eef181c81e 17
txracing 0:16eef181c81e 18
txracing 0:16eef181c81e 19
txracing 0:16eef181c81e 20 //GET data
txracing 0:16eef181c81e 21
txracing 0:16eef181c81e 22 lcd.cls();
txracing 0:16eef181c81e 23 lcd.locate(0,3);
txracing 0:16eef181c81e 24 lcd.printf("\nTrying to fetch page...\n");
txracing 0:16eef181c81e 25 int ret = http.get("http://mbed.org/media/uploads/donatien/hello.txt", str, 128);
txracing 0:16eef181c81e 26 if (!ret)
txracing 0:16eef181c81e 27 {
txracing 0:16eef181c81e 28 lcd.cls();
txracing 0:16eef181c81e 29 lcd.locate(0,3);
txracing 0:16eef181c81e 30 lcd.printf("Page fetched successfully - read %d characters\n", strlen(str));
txracing 0:16eef181c81e 31 printf("Result: %s\n", str);
txracing 0:16eef181c81e 32 }
txracing 0:16eef181c81e 33 else
txracing 0:16eef181c81e 34 {
txracing 0:16eef181c81e 35 lcd.cls();
txracing 0:16eef181c81e 36 lcd.locate(0,3);
txracing 0:16eef181c81e 37 lcd.printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
txracing 0:16eef181c81e 38 }
txracing 0:16eef181c81e 39
txracing 0:16eef181c81e 40 //POST data
txracing 0:16eef181c81e 41 HTTPMap map;
txracing 0:16eef181c81e 42 HTTPText inText(str, 512);
txracing 0:16eef181c81e 43 map.put("Hello", "World");
txracing 0:16eef181c81e 44 map.put("test", "1234");
txracing 0:16eef181c81e 45 lcd.cls();
txracing 0:16eef181c81e 46 lcd.locate(0,3);
txracing 0:16eef181c81e 47 lcd.printf("\nTrying to post data...\n");
txracing 0:16eef181c81e 48 ret = http.post("http://httpbin.org/post", map, &inText);
txracing 0:16eef181c81e 49 if (!ret)
txracing 0:16eef181c81e 50 {
txracing 0:16eef181c81e 51 lcd.cls();
txracing 0:16eef181c81e 52 lcd.locate(0,3);
txracing 0:16eef181c81e 53 lcd.printf("Executed POST successfully - read %d characters\n", strlen(str));
txracing 0:16eef181c81e 54 lcd.printf("Result: %s\n", str);
txracing 0:16eef181c81e 55 }
txracing 0:16eef181c81e 56 else
txracing 0:16eef181c81e 57 {
txracing 0:16eef181c81e 58 lcd.cls();
txracing 0:16eef181c81e 59 lcd.locate(0,3);
txracing 0:16eef181c81e 60 lcd.printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
txracing 0:16eef181c81e 61 }
txracing 0:16eef181c81e 62
txracing 0:16eef181c81e 63 //PUT data
txracing 0:16eef181c81e 64 strcpy(str, "This is a PUT test!");
txracing 0:16eef181c81e 65 HTTPText outText(str);
txracing 0:16eef181c81e 66 //HTTPText inText(str, 512);
txracing 0:16eef181c81e 67 lcd.cls();
txracing 0:16eef181c81e 68 lcd.locate(0,3);
txracing 0:16eef181c81e 69 lcd.printf("\nTrying to put resource...\n");
txracing 0:16eef181c81e 70 ret = http.put("http://httpbin.org/put", outText, &inText);
txracing 0:16eef181c81e 71 if (!ret)
txracing 0:16eef181c81e 72 {
txracing 0:16eef181c81e 73 lcd.cls();
txracing 0:16eef181c81e 74 lcd.locate(0,3);
txracing 0:16eef181c81e 75 lcd.printf("Executed PUT successfully - read %d characters\n", strlen(str));
txracing 0:16eef181c81e 76 lcd.printf("Result: %s\n", str);
txracing 0:16eef181c81e 77 }
txracing 0:16eef181c81e 78 else
txracing 0:16eef181c81e 79 {
txracing 0:16eef181c81e 80 lcd.cls();
txracing 0:16eef181c81e 81 lcd.locate(0,3);
txracing 0:16eef181c81e 82 lcd.printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
txracing 0:16eef181c81e 83 }
txracing 0:16eef181c81e 84
txracing 0:16eef181c81e 85 //DELETE data
txracing 0:16eef181c81e 86 //HTTPText inText(str, 512);
txracing 0:16eef181c81e 87 lcd.cls();
txracing 0:16eef181c81e 88 lcd.locate(0,3);
txracing 0:16eef181c81e 89 lcd.printf("\nTrying to delete resource...\n");
txracing 0:16eef181c81e 90 ret = http.del("http://httpbin.org/delete", &inText);
txracing 0:16eef181c81e 91 if (!ret)
txracing 0:16eef181c81e 92 {
txracing 0:16eef181c81e 93 lcd.cls();
txracing 0:16eef181c81e 94 lcd.locate(0,3);
txracing 0:16eef181c81e 95 lcd.printf("Executed DELETE successfully - read %d characters\n", strlen(str));
txracing 0:16eef181c81e 96 lcd.printf("Result: %s\n", str);
txracing 0:16eef181c81e 97 }
txracing 0:16eef181c81e 98 else
txracing 0:16eef181c81e 99 {
txracing 0:16eef181c81e 100 lcd.cls();
txracing 0:16eef181c81e 101 lcd.locate(0,3);
txracing 0:16eef181c81e 102 lcd.printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
txracing 0:16eef181c81e 103 }
txracing 0:16eef181c81e 104
txracing 0:16eef181c81e 105 eth.disconnect();
txracing 0:16eef181c81e 106
txracing 0:16eef181c81e 107 while(1) {
txracing 0:16eef181c81e 108 }
txracing 0:16eef181c81e 109 }