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

Dependencies:   SimpleIoTBoardLib mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "HTTPClient.h"
00003 #include "ESP8266Interface.h"
00004 #include "TCPSocketConnection.h"
00005 #include "SoftSerialSendOnry.h"
00006 
00007 ESP8266Interface wifi(dp16,dp15,dp4,"SSID","Password",115200); // TX,RX,Reset,SSID,Password,Baud
00008 
00009 SoftSerialSendOnry pc(dp10);
00010 int main()
00011 {
00012     HTTPClient http;
00013     char str[512];
00014 
00015     pc.baud(9600);
00016 
00017     wifi.init(); //Reset
00018     wifi.connect(); //Use DHCP
00019     pc.printf("IP Address is %s\n", wifi.getIPAddress());
00020 
00021     //GET
00022     pc.printf("\nTrying to fetch page using GET...\n\r");
00023     int ret = http.get("http://jksoft.cocolog-nifty.com/msg.txt", str, 512);//IP address is httpbin.org/get
00024     
00025     if (ret == 0) {
00026         pc.printf("Page fetched successfully - read %d characters\n\r", strlen(str));
00027         pc.printf("Result: %s\n\r", str);
00028     } else {
00029         pc.printf("Error - ret = %d - HTTP return code = %d\n\r", ret, http.getHTTPResponseCode());
00030     }
00031 }