pengfei wu
/
ESP8266Program
For test
Diff: main.cpp
- Revision:
- 34:65cd9c6eedb8
- Parent:
- 33:f721a46ef2f2
--- a/main.cpp Thu Feb 05 02:28:09 2015 +0000 +++ b/main.cpp Thu Feb 05 03:38:10 2015 +0000 @@ -23,15 +23,15 @@ #include "ESP8266.h" -void httpRequest(); + ESP8266 wifi(p28, p27); - const char *server = "www.163.com"; char message[4096]; void setup() { printf("setup begin\r\n"); + if(wifi.reset()) { printf("reset ok\r\n"); } else { @@ -40,29 +40,21 @@ if(wifi.setStationMode(SSID, PASSWORD)) { printf("setStationMode ok\r\n"); + printf("AP:%s\r\n", wifi.showJAP().c_str()); + printf("IP:%s\r\n", wifi.showIP().c_str()); } else { printf("setStationMode err\r\n"); } - printf("IP:%s\r\n", wifi.showIP().c_str()); - printf("AP:%s\r\n", wifi.showJAP().c_str()); printf("setup end\r\n"); } void loop() { - httpRequest(); - while(1); -} - -// this method makes a HTTP connection to the server: -void httpRequest() { unsigned long t; - // if there's a successful connection: if (wifi.ipConfig(ESP8266_COMM_TCP, server, 80)) { - printf("connecting...\r\n"); + printf("connected and get /\r\n"); wifi.send("GET / HTTP/1.1\r\n\r\n"); - t = millis(); printf("Recv:\r\n["); while(millis() - t <= 10000) { @@ -74,12 +66,11 @@ printf("]\r\n"); } else { - // if you couldn't make a connection: - printf("connection failed\r\n"); - printf("disconnecting.\r\n"); - wifi.closeMux(); + printf("connect failed\r\n"); } + while(1); } + #endif #ifdef EXAMPLE_TCPSERVER