Skip to content

Commit bdc1cb8

Browse files
committed
fix: fixed flashing timeout (#160, #161)
1 parent fc7e3b8 commit bdc1cb8

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### Fixes
44
- [#150](https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino/pull/150) - `HTTPOptions::httpReadTimeout` is also set as the connect timeout for HTTP connection on ESP32. It doesn't work for HTTPS connection yet.
55
- [#156](https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino/pull/156) - Correctly rounding _writeBufferSize_, when _bufferSize/batchSize >= 256_.
6+
- [#162](https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino/pull/162) - Fixed flushing of not full buffer after to timeout.
67

78
## 3.8.0 [2021-04-01]
89
### Features

src/InfluxDbClient.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ bool InfluxDBClient::init() {
9898
INFLUXDB_CLIENT_DEBUG("[D] Org: %s\n", _connInfo.org.c_str());
9999
INFLUXDB_CLIENT_DEBUG("[D] Bucket: %s\n", _connInfo.bucket.c_str());
100100
INFLUXDB_CLIENT_DEBUG("[D] Token: %s\n", _connInfo.authToken.c_str());
101-
INFLUXDB_CLIENT_DEBUG("[D] DB version: %d\n", _dbVersion);
101+
INFLUXDB_CLIENT_DEBUG("[D] DB version: %d\n", _connInfo.dbVersion);
102102
if(_connInfo.serverUrl.length() == 0 || (_connInfo.dbVersion == 2 && (_connInfo.org.length() == 0 || _connInfo.bucket.length() == 0 || _connInfo.authToken.length() == 0))) {
103103
INFLUXDB_CLIENT_DEBUG("[E] Invalid parameters\n");
104104
_connInfo.lastError = F("Invalid parameters");
@@ -137,7 +137,7 @@ void InfluxDBClient::clean() {
137137
_service = nullptr;
138138
}
139139
_buckets = nullptr;
140-
_lastFlushed = 0;
140+
_lastFlushed = millis();
141141
_retryTime = 0;
142142
}
143143

@@ -359,11 +359,14 @@ bool InfluxDBClient::checkBuffer() {
359359
// in case we (over)reach batchSize with non full buffer
360360
bool bufferReachedBatchsize = _writeBuffer[_batchPointer] && _writeBuffer[_batchPointer]->isFull();
361361
// or flush interval timed out
362-
bool flushTimeout = _writeOptions._flushInterval > 0 && _lastFlushed > 0 && (millis()/1000 - _lastFlushed) > _writeOptions._flushInterval;
362+
bool flushTimeout = _writeOptions._flushInterval > 0 && ((millis() - _lastFlushed)/1000) >= _writeOptions._flushInterval;
363363

364+
INFLUXDB_CLIENT_DEBUG("[D] Flushing buffer: is oversized %s, is timeout %s, is buffer full %s\n",
365+
bool2string(bufferReachedBatchsize),bool2string(flushTimeout), bool2string(isBufferFull()));
366+
364367
if(bufferReachedBatchsize || flushTimeout || isBufferFull() ) {
365-
INFLUXDB_CLIENT_DEBUG("[D] Flushing buffer: is oversized %s, is timeout %s, is buffer full %s\n", bufferReachedBatchsize?"true":"false",flushTimeout?"true":"false", isBufferFull()?"true":"false");
366-
return flushBufferInternal(true);
368+
369+
return flushBufferInternal(!flushTimeout);
367370
}
368371
return true;
369372
}
@@ -412,7 +415,7 @@ bool InfluxDBClient::flushBufferInternal(bool flashOnlyFull) {
412415
success = statusCode >= 200 && statusCode < 300;
413416
// advance even on message failure x e <300;429)
414417
if(success || !retry) {
415-
_lastFlushed = millis()/1000;
418+
_lastFlushed = millis();
416419
dropCurrentBatch();
417420
} else if(retry) {
418421
_writeBuffer[_batchPointer]->retryCount++;
@@ -542,7 +545,7 @@ FluxQueryResult InfluxDBClient::query(String fluxQuery) {
542545
String header = httpClient->header(TransferEncoding);
543546
chunked = header.equalsIgnoreCase("chunked");
544547
}
545-
INFLUXDB_CLIENT_DEBUG("[D] chunked: %s\n", chunked?"true":"false");
548+
INFLUXDB_CLIENT_DEBUG("[D] chunked: %s\n", bool2string(chunked));
546549
HttpStreamScanner *scanner = new HttpStreamScanner(httpClient, chunked);
547550
reader = new CsvReader(scanner);
548551
return false;

src/InfluxDbClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class InfluxDBClient {
200200
// Index of bath start for next write
201201
uint8_t _batchPointer = 0;
202202
// Last time in sec buffer has been successfully flushed
203-
uint32_t _lastFlushed = 0;
203+
uint32_t _lastFlushed;
204204
// Bucket sub-client
205205
BucketsClient _buckets;
206206
protected:

0 commit comments

Comments
 (0)