Description
Basic Infos
Hardware
Hardware: ?ESP-12E?
Core Version: ?2.1.0-rc2?
Description
Using the method setTimeout(value) does not work. The given value is not taken into considerationwhen posting requests.
Settings in IDE
Module: ?ESP8266-12E Module?
Flash Size: ?4MB/1MB?
CPU Frequency: ?80Mhz?
Flash Mode: ?qio?
Flash Frequency: ?40Mhz?
Upload Using: ?SERIAL?
Sketch
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
const boolean deb PROGMEM =true ; //if true, you will get debug messages
void setup() {
if(deb) Serial.begin(115200);
const char* ssid="mySSID";
const char* pwd="myWIFIPassword";
IPAddress ip(192,168,178,10);
IPAddress gw(192,168,178,1);
IPAddress sn(255,255,255,0);
WiFi.persistent(false);
WiFi.mode(WIFI_STA);
WiFi.config(ip, gw, sn);
WiFi.begin(ssid, pwd);
unsigned long start = millis();
while(WiFi.status() != WL_CONNECTED)
{
if(deb) Serial.print(".");
delay(50);
if((millis() - start) > 5000)
{
if(deb) Serial.println("[WIFI ] No Wifi connection after 5 seconds !");
WiFi.mode(WIFI_OFF);
WiFi.forceSleepBegin();
ESP.deepSleep(60*100000);
yield();
}
}
unsigned long startt = millis();
// >>>>>> THIS IS the relevant part to verify the problem
HTTPClient http;
http.setTimeout(200);
http.begin("http://192.168.178.20:8000/");
http.addHeader("Content-Type", "text/plain");
int httpCode = http.POST("This is just a sample text to post !");
if(httpCode > 0) {
if(deb) Serial.printf("[HTTP ] POST... code: %d\n", httpCode);
if(httpCode == HTTP_CODE_OK) {
if(deb) Serial.println("[HTTP ] POST... code was O.K ");
String payload = http.getString(); //get return from Server
if (deb) Serial.println(payload);
}
else {
if(deb) Serial.printf("[HTTP ] POST... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
} else {
if(deb) Serial.printf("[HTTP ] POST... failed with code: %d, error: %s\n", httpCode, http.errorToString(httpCode).c_str());
}
http.end();
yield();
if(deb) Serial.printf("[HTTP ] total duration of http-PUT: %d ms.\n", millis()- startt);
ESP.deepSleep(60*100000);
}
void loop() {
//I won't get here ....
ESP.deepSleep(60*100000);
}
Debug Messages
The above sketch was minimized and all crap not needed was removed. What I actually do is to measure some values via I2C bus and build a message, that is being sent to the server. As the server gets messages from several nodes it calculates a timespan and tells the sender of a post, how long to sleep before the receiver should wake up and transmit some new values - but this is unrelevant.
As you can see, I have set a timeout of 200 ms - You can change the value but what happens is the following (self created) debug output. It will transmit the data, and will get the message from the server
[HTTP ] POST... code: 200
[HTTP ] POST... code was O.K
12345 //<this is the value my server sends me ...
[HTTP ] total duration of http-PUT: 973 ms.
Basically: there seems to be an uninfluencable timout of 5000ms that I can not change.
What am I doing wrong?