Do I have to http.begin/http.end for every http.post?
Posted: Wed Jan 23, 2019 1:12 pm
Hi, I have a data collection sketch that stores data (in the form of SQL formatted commands) in a text file to be posted at midnight.
I am looking for some help from someone with experience in this sort of arrangements in order to save some development/testing time.
Currently I am doing as follows:
I would like to make the process more efficient and potentially faster by opening and closing http only once .
Something like:
Sorry for the generic code but the original sketch is 1000+ lines long and I hope this simplification will be enough to get the idea.
Thanks in advance.
Paulo
I am looking for some help from someone with experience in this sort of arrangements in order to save some development/testing time.
Currently I am doing as follows:
Code: Select all
while(file){
dataBuffer = SD.open(file.name(), FILE_READ);
while (dataBuffer.available()) {
//open channel
HTTPClient http;
http.begin(URLtxt);
//send request + data
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
SQLtxt = dataBuffer.readStringUntil('\n');
_post = "query=" + urlencode(SQLtxt);
httpResponseCode = http.POST(_post);
..... check if response is ok or not
http.end()
}
}
Something like:
Code: Select all
while(file){
dataBuffer = SD.open(file.name(), FILE_READ);
//open channel
HTTPClient http;
http.begin(URLtxt);
//send request + data
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
while (dataBuffer.available()) {
SQLtxt = dataBuffer.readStringUntil('\n');
_post = "query=" + urlencode(SQLtxt);
httpResponseCode = http.POST(_post);
..... check if response is ok or not
}
http.end()
}
Thanks in advance.
Paulo