| API For Arduino developers

- Main Page
- Related Pages
- Classes
- Files
- Examples

- File List

HTTPGET.ino
1
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
ESP8266::send
bool send(const uint8_t *buffer, uint32_t len)
Send data based on TCP or UDP builded already in single mode.
Definition: ESP8266.cpp:261
ESP8266::getVersion
String getVersion(void)
Get the version of AT Command Set.
Definition: ESP8266.cpp:80
ESP8266::releaseTCP
bool releaseTCP(void)
Release TCP connection in single mode.
Definition: ESP8266.cpp:196
ESP8266::recv
uint32_t recv(uint8_t *buffer, uint32_t buffer_size, uint32_t timeout=1000)
Receive data from TCP or UDP builded already in single mode.
Definition: ESP8266.cpp:271
ESP8266::getLocalIP
String getLocalIP(void)
Get the IP address of ESP8266.
Definition: ESP8266.cpp:174
ESP8266.h
The definition of class ESP8266.
ESP8266::setOprToStationSoftAP
bool setOprToStationSoftAP(void)
Set operation mode to station + softap.
Definition: ESP8266.cpp:121
ESP8266::createTCP
bool createTCP(String addr, uint32_t port)
Create TCP connection in single mode.
Definition: ESP8266.cpp:191
ESP8266::disableMUX
bool disableMUX(void)
Disable IP MUX(single connection mode).
Definition: ESP8266.cpp:186
ESP8266::joinAP
bool joinAP(String ssid, String pwd)
Join in AP.
Definition: ESP8266.cpp:145
ESP8266
Provide an easy-to-use way to manipulate ESP8266.
Definition: ESP8266.h:38