Skip to content

Commit 712e1e3

Browse files
author
shennongmin
committed
Add example:HTTPGET.ino
1 parent 11c3bf9 commit 712e1e3

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

examples/HTTPGET/HTTPGET.ino

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
* @example HTTPGET.ino
3+
* @brief The HTTPGET demo of library WeeESP8266.
4+
* @author Wu Pengfei<pengfei.wu@itead.cc>
5+
* @date 2015.03
6+
*
7+
* @par Copyright:
8+
* Copyright (c) 2015 ITEAD Intelligent Systems Co., Ltd. \n\n
9+
* This program is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU General Public License as
11+
* published by the Free Software Foundation; either version 2 of
12+
* the License, or (at your option) any later version. \n\n
13+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
* THE SOFTWARE.
20+
*/
21+
22+
#include "ESP8266.h"
23+
24+
#define SSID "ITEAD"
25+
#define PASSWORD "12345678"
26+
#define HOST_NAME "www.baidu.com"
27+
#define HOST_PORT (80)
28+
29+
ESP8266 wifi(Serial1);
30+
31+
void setup(void)
32+
{
33+
Serial.begin(9600);
34+
Serial.print("setup begin\r\n");
35+
36+
Serial.print("FW Version:");
37+
Serial.println(wifi.getVersion().c_str());
38+
39+
if (wifi.setOprToStationSoftAP()) {
40+
Serial.print("to station + softap ok\r\n");
41+
} else {
42+
Serial.print("to station + softap err\r\n");
43+
}
44+
45+
if (wifi.joinAP(SSID, PASSWORD)) {
46+
Serial.print("Join AP success\r\n");
47+
48+
Serial.print("IP:");
49+
Serial.println( wifi.getLocalIP().c_str());
50+
} else {
51+
Serial.print("Join AP failure\r\n");
52+
}
53+
54+
if (wifi.disableMUX()) {
55+
Serial.print("single ok\r\n");
56+
} else {
57+
Serial.print("single err\r\n");
58+
}
59+
60+
Serial.print("setup end\r\n");
61+
}
62+
63+
void loop(void)
64+
{
65+
uint8_t buffer[1024] = {0};
66+
67+
if (wifi.createTCP(HOST_NAME, HOST_PORT)) {
68+
Serial.print("create tcp ok\r\n");
69+
} else {
70+
Serial.print("create tcp err\r\n");
71+
}
72+
73+
char *hello = "GET / HTTP/1.1\r\nHost: www.baidu.com\r\nConnection: close\r\n\r\n";
74+
wifi.send((const uint8_t*)hello, strlen(hello));
75+
76+
uint32_t len = wifi.recv(buffer, sizeof(buffer), 10000);
77+
if (len > 0) {
78+
Serial.print("Received:[");
79+
for(uint32_t i = 0; i < len; i++) {
80+
Serial.print((char)buffer[i]);
81+
}
82+
Serial.print("]\r\n");
83+
}
84+
85+
if (wifi.releaseTCP()) {
86+
Serial.print("release tcp ok\r\n");
87+
} else {
88+
Serial.print("release tcp err\r\n");
89+
}
90+
91+
while(1);
92+
93+
}
94+

0 commit comments

Comments
 (0)