Simple IoT Board用のHTTP GETサンプルです。

Dependencies:   SimpleIoTBoardLib mbed

Committer:
jksoft
Date:
Sun Nov 15 13:29:46 2015 +0000
Revision:
0:0ae1235453b0
??

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 0:0ae1235453b0 1 #include "mbed.h"
jksoft 0:0ae1235453b0 2 #include "HTTPClient.h"
jksoft 0:0ae1235453b0 3 #include "ESP8266Interface.h"
jksoft 0:0ae1235453b0 4 #include "TCPSocketConnection.h"
jksoft 0:0ae1235453b0 5 #include "SoftSerialSendOnry.h"
jksoft 0:0ae1235453b0 6
jksoft 0:0ae1235453b0 7 ESP8266Interface wifi(dp16,dp15,dp4,"SSID","Password",115200); // TX,RX,Reset,SSID,Password,Baud
jksoft 0:0ae1235453b0 8
jksoft 0:0ae1235453b0 9 SoftSerialSendOnry pc(dp10);
jksoft 0:0ae1235453b0 10 int main()
jksoft 0:0ae1235453b0 11 {
jksoft 0:0ae1235453b0 12 HTTPClient http;
jksoft 0:0ae1235453b0 13 char str[512];
jksoft 0:0ae1235453b0 14
jksoft 0:0ae1235453b0 15 pc.baud(9600);
jksoft 0:0ae1235453b0 16
jksoft 0:0ae1235453b0 17 wifi.init(); //Reset
jksoft 0:0ae1235453b0 18 wifi.connect(); //Use DHCP
jksoft 0:0ae1235453b0 19 pc.printf("IP Address is %s\n", wifi.getIPAddress());
jksoft 0:0ae1235453b0 20
jksoft 0:0ae1235453b0 21 //GET
jksoft 0:0ae1235453b0 22 pc.printf("\nTrying to fetch page using GET...\n\r");
jksoft 0:0ae1235453b0 23 int ret = http.get("http://jksoft.cocolog-nifty.com/msg.txt", str, 512);//IP address is httpbin.org/get
jksoft 0:0ae1235453b0 24
jksoft 0:0ae1235453b0 25 if (ret == 0) {
jksoft 0:0ae1235453b0 26 pc.printf("Page fetched successfully - read %d characters\n\r", strlen(str));
jksoft 0:0ae1235453b0 27 pc.printf("Result: %s\n\r", str);
jksoft 0:0ae1235453b0 28 } else {
jksoft 0:0ae1235453b0 29 pc.printf("Error - ret = %d - HTTP return code = %d\n\r", ret, http.getHTTPResponseCode());
jksoft 0:0ae1235453b0 30 }
jksoft 0:0ae1235453b0 31 }