Skip to content

Commit 64e5e3e

Browse files
authored
Merge pull request #200 from tobiasschuerg/fix/override_compilation_error
fix: backward compatible compilation of Stream API
2 parents 12612be + 00f2806 commit 64e5e3e

File tree

4 files changed

+38
-14
lines changed

4 files changed

+38
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Changelog
2+
## unreleased
3+
### Fixes
4+
- [200](https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino/pull/200) - Backward compatible compilation. Solves _marked 'override', but does not override_ errors.
5+
26
## 3.12.2 [2022-09-30]
37
### Fixes
48
- [198](https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino/pull/198) - Effective passing Point by value

src/InfluxDbClient.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ int InfluxDBClient::postData(Batch *batch) {
578578

579579
BatchStreamer *bs = new BatchStreamer(batch);
580580
INFLUXDB_CLIENT_DEBUG("[D] Writing to %s\n", _writeUrl.c_str());
581-
INFLUXDB_CLIENT_DEBUG("[D] Sending:\n");
581+
INFLUXDB_CLIENT_DEBUG("[D] Sending %d:\n", bs->available());
582582

583583
if(!_service->doPOST(_writeUrl.c_str(), bs, PSTR("text/plain"), 204, nullptr)) {
584584
INFLUXDB_CLIENT_DEBUG("[D] error %d: %s\n", _service->getLastStatusCode(), _service->getLastErrorMessage().c_str());
@@ -724,15 +724,23 @@ int InfluxDBClient::BatchStreamer::availableForWrite() {
724724
return 0;
725725
}
726726

727-
#if defined(ESP8266)
727+
void InfluxDBClient::BatchStreamer::reset() {
728+
_read = 0;
729+
_pointer = 0;
730+
_linePointer = 0;
731+
}
732+
728733
int InfluxDBClient::BatchStreamer::read(uint8_t* buffer, size_t len) {
729-
INFLUXDB_CLIENT_DEBUG("BatchStream::read %d\n", len);
734+
INFLUXDB_CLIENT_DEBUG("BatchStream::read\n");
730735
return readBytes((char *)buffer, len);
731736
}
732-
#endif
733-
size_t InfluxDBClient::BatchStreamer::readBytes(char* buffer, size_t len) {
734737

735-
INFLUXDB_CLIENT_DEBUG("BatchStream::readBytes %d\n", len);
738+
size_t InfluxDBClient::BatchStreamer::readBytes(char* buffer, size_t len) {
739+
#if defined(ESP8266)
740+
INFLUXDB_CLIENT_DEBUG("BatchStream::readBytes %d, free_heap %d, max_alloc_heap %d, heap_fragmentation %d\n", len, ESP.getFreeHeap(), ESP.getMaxFreeBlockSize(), ESP.getHeapFragmentation());
741+
#elif defined(ESP32)
742+
INFLUXDB_CLIENT_DEBUG("BatchStream::readBytes %d, free_heap %d, max_alloc_heap %d\n", len, ESP.getFreeHeap(), ESP.getMaxAllocHeap());
743+
#endif
736744
unsigned int r=0;
737745
for(unsigned int i=0;i<len;i++) {
738746
if(available()) {

src/InfluxDbClient.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,17 +204,17 @@ class InfluxDBClient {
204204
public:
205205
BatchStreamer(Batch *batch) ;
206206
virtual ~BatchStreamer() {};
207+
// Clears pointers to start reading from beginning
208+
void reset();
207209

208210
// Stream overrides
209211
virtual int available() override;
210212

211-
virtual int availableForWrite() override;
213+
virtual int availableForWrite();
212214

213215
virtual int read() override;
214-
#if defined(ESP8266)
215-
virtual int read(uint8_t* buffer, size_t len) override;
216-
#endif
217-
virtual size_t readBytes(char* buffer, size_t len) override;
216+
virtual int read(uint8_t* buffer, size_t len);
217+
virtual size_t readBytes(char* buffer, size_t len);
218218

219219
virtual void flush() override {};
220220
virtual int peek() override;

test/Test.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ void Test::run() {
5050
testFluxTypes();
5151
testFluxTypesSerialization();
5252
testTimestampAdjustment();
53-
5453
testFluxParserEmpty();
5554
testFluxParserSingleTable();
5655
testFluxParserNilValue();
@@ -74,7 +73,6 @@ void Test::run() {
7473
testLargeBatch();
7574
testFailedWrites();
7675
testTimestamp();
77-
7876
testRetryOnFailedConnection();
7977
testRetryOnFailedConnectionWithFlush();
8078
testNonRetry();
@@ -430,6 +428,18 @@ void Test::testBatch() {
430428
TEST_ASSERT(buff[i++] == line[j]);
431429
}
432430
TEST_ASSERT(buff[i++] == '\n');
431+
buff[0] = 0;
432+
str.reset();
433+
//Test Stream API
434+
Stream *s = &str;
435+
TEST_ASSERT(s->available() == len*2+2);
436+
TEST_ASSERT(s->readBytes(buff, len+1) == len+1);
437+
TEST_ASSERT(s->available() == len+1);
438+
TEST_ASSERT(s->readBytes(buff+len+1, len) == len);
439+
TEST_ASSERT(s->available() == 1);
440+
TEST_ASSERT(s->readBytes(buff+2*len+1, 1) == 1);
441+
TEST_ASSERT(s->available() == 0);
442+
433443
delete [] buff;
434444
TEST_END();
435445
}
@@ -2459,7 +2469,8 @@ void Test::testLargeBatch() {
24592469
#if defined(ESP8266)
24602470
int batchSize = 330;
24612471
#elif defined(ESP32)
2462-
int batchSize = 2047;
2472+
// 2.0.4. introduces a memory hog which causes original 2048 lines cannot be sent
2473+
int batchSize = 1950;
24632474
#endif
24642475
int len =strlen(line);
24652476
int points = free/len;
@@ -2477,6 +2488,7 @@ void Test::testLargeBatch() {
24772488
WS_DEBUG_RAM("Full batch");
24782489
}
24792490
TEST_ASSERTM(client.writeRecord(line),client.getLastErrorMessage());
2491+
yield();
24802492
}
24812493
WS_DEBUG_RAM("Data sent");
24822494
String query = "select";

0 commit comments

Comments
 (0)