Diaoul / arduino-ESP8266

An Arduino library to manage the ESP8266.
MIT License
68 stars 46 forks source link

http request timeout problem #28

Open bluedays000 opened 8 years ago

bluedays000 commented 8 years ago

I am working with Arduino Uno and ESP8266.

I connected ESP8266 with Arduino Uno, and downloaded this library. (https://github.com/Diaoul/arduino-ESP8266)..

'joinAP' was OK and 'connect' was also OK.

But the problem was http request.

"getStatus(wifi.send("GET / HTTP/1.0\r\n\r\n"))" in setup code always showed me 'TIMEOUT'.

I just changed SSID, PASS, DSP_IP and port number.. but it doesn't work well.. T.T

Below is my code.

Please save my code..


include

include "ESP8266.h"

define SSID "SSID" // WiFi ID

define PASS "PASS" // WiFi Password

define DST_IP "www.google.com" // IP address

SoftwareSerial esp8266Serial = SoftwareSerial(2, 3); // RX, TX pin num ESP8266 wifi = ESP8266(esp8266Serial);

void setup() { Serial.begin(9600);

// ESP8266 esp8266Serial.begin(9600); wifi.begin(); wifi.setTimeout(10);

/*_/ /* Basic commands ***/ /*_/ // test Serial.print("test: "); Serial.println(getStatus(wifi.test()));

// restart Serial.print("restart: "); Serial.println(getStatus(wifi.restart()));

// getVersion char version[16] = {}; Serial.print("getVersion: "); Serial.print(getStatus(wifi.getVersion(version, 16))); Serial.print(" : "); Serial.println(version);

// getWifiMode /// ESP8266WifiMode mode; Serial.print("getWifiMode: "); Serial.println(getStatus(wifi.getMode(&mode)));/// Serial.print("Wifi mode>>:"); Serial.println(mode); if( mode != ESP8266_WIFI_STATION) { // setWifiMode Serial.print("setWifiMode: "); // Serial.println(getStatus(wifi.setMode(ESP8266_WIFI_ACCESSPOINT))); Serial.println(getStatus(wifi.setMode(ESP8266_WIFI_STATION ))); } else Serial.println("already ESP8266_WIFI_STATION mode");

/*_/ /* WiFi commands ***/ /*_/ // joinAP Serial.print("joinAP: "); Serial.println(getStatus(wifi.joinAP(SSID, PASS)));

/*_/ /* TCP/IP commands ***/ /*_/ // connect Serial.print("connect: "); Serial.println(getStatus(wifi.connect(ESP8266_PROTOCOL_TCP, DST_IP, 80)));

// send Serial.print("send: "); Serial.println(getStatus(wifi.send("GET / HTTP/1.0\r\n\r\n")));

}

void loop() { /*_/ /* WiFi commands ***/ /*_/

// read data unsigned int id; int length; int totalRead; char buffer[300] = {};

if ((length = wifi.available()) > 0) { id = wifi.getId(); totalRead = wifi.read(buffer, 300);

if (length > 0) { Serial.print("Received "); Serial.print(totalRead); Serial.print("/"); Serial.print(length); Serial.print(" bytes from client "); //Serial.print("from client "); Serial.print(id); Serial.print(": "); Serial.println((char*)buffer); } } }

String getStatus(bool status) { if (status) return "OK";

return "KO"; }

String getStatus(ESP8266CommandStatus status) { switch (status) { case ESP8266_COMMAND_INVALID: return "INVALID"; break;

case ESP8266_COMMAND_TIMEOUT: return "TIMEOUT"; break;

case ESP8266_COMMAND_OK: return "OK"; break;

case ESP8266_COMMAND_NO_CHANGE: return "NO CHANGE"; break;

case ESP8266_COMMAND_ERROR: return "ERROR"; break;

case ESP8266_COMMAND_NO_LINK: return "NO LINK"; break;

case ESP8266_COMMAND_TOO_LONG: return "TOO LONG"; break;

case ESP8266_COMMAND_FAIL: return "FAIL"; break;

default: return "UNKNOWN COMMAND STATUS"; break; } }

String getRole(ESP8266Role role) { switch (role) { case ESP8266_ROLE_CLIENT: return "CLIENT"; break;

case ESP8266_ROLE_SERVER: return "SERVER"; break;

default: return "UNKNOWN ROLE"; break; } }

String getProtocol(ESP8266Protocol protocol) { switch (protocol) { case ESP8266_PROTOCOL_TCP: return "TCP"; break;

case ESP8266_PROTOCOL_UDP: return "UDP"; break;

default: return "UNKNOWN PROTOCOL"; break; } }