Diaoul / arduino-ESP8266

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

Canot get IP #3

Closed toanmh closed 9 years ago

toanmh commented 9 years ago
Serial.begin(9600);      // sets the serial port to 9600
Serial1.begin(9600); 
wifi.begin(Serial1);
wifi.setTimeout(20000);
wifi.quitAP();
//get version
char versions[16] = {};
Serial.print("getVersion: ");
Serial.print(getStatus(wifi.getVersion(versions, 16)));
Serial.print(" : ");
Serial.println(versions);
Serial.print("setWifiMode: ");
Serial.println(getStatus(wifi.setWifiMode(ESP8266_WIFI_BOTH)));    
// setAPConfiguration
Serial.print("setAPConfiguration: ");
Serial.println(getStatus(wifi.joinAP("tamhoa.house", "")));
// setMultipleConnections
Serial.print("setMultipleConnections: ");
Serial.println(getStatus(wifi.setMultipleConnections(true)));
Serial.print("IP: ");    
char ap[32] = {};
Serial.print("getAP: ");
Serial.print(getStatus(wifi.getAP(ap)));
Serial.print(" : ");
Serial.println(ap);
  // getIP
IPAddress ip;
Serial.print("getIP STA: ");
Serial.print(getStatus(wifi.getIP(ESP8266_WIFI_STATION, ip)));
Serial.print(" : ");
Serial.println(ip);
Serial.print("getIP AP: ");
Serial.print(getStatus(wifi.getIP(ESP8266_WIFI_ACCESSPOINT, ip)));
Serial.print(" : ");
Serial.println(ip);
Serial.println("READY");

The results: setAPConfgetVersion: OK : 0018000902-AI03 setWifiMode: NO CHANGE setAPConfiguration: OK setMultipleConnections: OK IP: getAP: OK : tamhoa.house getIP STA: TIMEOUT : 0.0.0.0 getIP AP: TIMEOUT : 0.0.0.0 READY I viewed the router that module have ip: 192.168.0.104 Why I can not received IP? And execute command: Serial.println(getStatus(wifi.connect(ESP8266_PROTOCOL_TCP, IPAddress(184,106,153,149), 80))); have result: ERROR

Diaoul commented 9 years ago

You need a newer firmware for this command to work. One which supports the v0.20 AT command set.

Diaoul commented 9 years ago

With multiple connections enabled you need to specify an id for the connection so use the other connect method.

toanmh commented 9 years ago

I don't think cause of version. I've update to 0.9.2.2 firmware but still get error:

getVersion: OK : 0018000902 setWifiMode: NO CHANGE setAPConfiguration: OK setMultipleConnections: OK IP: getAP: OK : tamhoa.house getIP STA: TIMEOUT : 0.0.0.0 getIP AP: TIMEOUT : 0.0.0.0 READY

And I changed multiple connection to single wifi.setMultipleConnections(false).

lasselukkari commented 9 years ago

Try the AT firmware version v0.20 that is using the SDK v0.9.3. https://github.com/esp8266/esp8266-wiki/tree/master/sdk

toanmh commented 9 years ago

Ok I fixed it when I updated to the AT firmware 0.2. But TCP get error:

String GET = "GET /update?key=YDK23CBZ93I4SAPV&field1=1.80&field2=56.30"; char tempBuff[GET.length()+1]; GET.toCharArray(tempBuff,GET.length()+1); if(wifi.connect(ESP8266_PROTOCOL_TCP, IPAddress(184,106,153,149), 80)==ESP8266_COMMAND_OK) { Serial.print("Upload data: "); Serial.println(tempBuff); Serial.print("Result:"); Serial.println(getStatus(wifi.send(tempBuff))); } Serial.println(getStatus(wifi.close())); Serial.println("Update completed");

The results: Upload data: GET /update?key=YDK23CBZ93I4SAPV&field1=1.80&field2=56.30 Result:TIMEOUT TIMEOUT It mean wifi.send(tempBuff) and wifi.close() has Time out.

Diaoul commented 9 years ago

The send function might need some rework. @lasselukkari is working on Stream interface implementation, I think we should make it dependent on the _timeout somehow, I don't know exactly which part of the function trigger the timeout. I suggest you manually change the timeout of 20ms in the library and try higher values.

lasselukkari commented 9 years ago

Altought this doesn't help with too strict timeout settings to debug the actual AT commands that are generated you can temporarily switch the ESP8266 library to use the Serial that outputs to your serial monitor. Then try to playback the commands manually to the ESP8266 and see where it goes wrong.

toanmh commented 9 years ago

Yes, may be set read timeout too short. I modified the code is: ESP8266CommandStatus ESP8266::send(unsigned int id, char* data, unsigned int length) { int c; clear(); _serial->print(F("AT+CIPSEND=")); if (id != ESP8266_SINGLE_CLIENT) { _serial->print(id); _serial->print(F(",")); } _serial->println(length); //c = timedPeek(20); c = timedPeek(_timeout); if (c == -1) return ESP8266_COMMAND_TIMEOUT; if (c != '>') return readStatus(20); _serial->write(data, length); //return readStatus(20); return readStatus(_timeout); } It run good. The _timeout is set 10000. I think you don't need set fixed timeout because you have function setTimeout yet.

Diaoul commented 9 years ago

Yes we need to define a different timeout. Some responses are expected instantaneoulsy from the ESP8266, some are not. The timeout is for the Stream interface and timed read/write network operations, not for communication with the underlying ESP8266.

Anyway, the send part can be improved and probably will change in a near future.

pastukhov commented 9 years ago

Can you provide firmware that fit all the needs? Cloud updated isn't support 9600 baud rate and http://www.electrodragon.com/w/Wi07c is too old.

Diaoul commented 9 years ago

https://github.com/espressif/esp8266_at/

pastukhov commented 9 years ago

These 115200 only.

AT+CIOBAUD=9600 ERROR

Diaoul commented 9 years ago

The standard AT command for that is AT+IPR, they changed it.

pastukhov commented 9 years ago

Thanks!!

Jinugc commented 9 years ago

I am getting error while initiate the TCP connection. Could you please help getVersion: OK : 0020000903 setWifiMode: OK getWifiMode: OK joinAP: OK getAP: OK : test connect: TIMEOUT send: NO LINK setMultipleConnections: OK