HTTPClient is only making one request
Posted: Fri Feb 24, 2017 3:52 am
Hello.
I'm new to ESP8266 programming and I'm having a problem with my Wemos D1 board.
I want to post data to thingspeak every five minutes
In my setup() function
The function is correctly fired but the connection is made only the first time (not from the ticker). When it is called from the ticker, POST() return always -1.
Maybe I'm missing something about closing the connection?
I'm new to ESP8266 programming and I'm having a problem with my Wemos D1 board.
I want to post data to thingspeak every five minutes
In my setup() function
Code: Select all
sendDataTS();
sendTicker.attach(5*60, sendDataTS);
Code: Select all
static HTTPClient httpClient;
void sendDataTS()
{
String s;
Serial.println(F("sendDataTS"));
s+=F("api_key=");
s+=apiKey;
s+=F("&field1=");
s+=String(SoilMoisture, 2);
httpClient.setReuse(true);
httpClient.begin(F("http://api.thingspeak.com/update"));
httpClient.addHeader(F("Content-Type"), F("application/x-www-form-urlencoded"));
int status=httpClient.POST(s);
String payload=httpClient.getString();
httpClient.end();
Serial.print(status);
Serial.print(payload);
Serial.println(F(" sendDataTS end"));
}
The function is correctly fired but the connection is made only the first time (not from the ticker). When it is called from the ticker, POST() return always -1.
Maybe I'm missing something about closing the connection?