Skip to content

Commit 44f4b11

Browse files
authored
Merge pull request #124 from bonitoo-io/fix/compilation_warnings
fix: fixing compilation warnings
2 parents 3dc101b + 78f6be4 commit 44f4b11

File tree

12 files changed

+191
-34
lines changed

12 files changed

+191
-34
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
### Fixes
55
- [#121](https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino/pull/121) - Fixed compile error in case of warning is treated as an error
66
- [#122](https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino/pull/122) - Deleting WiFiClient instance to avoid memory leaking when the InfluxDBClient is reinitialized
7+
- [#124](https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino/pull/124) - Fixed compilation warnings
8+
79
### Doc
810
- [#120](https://github.com/tobiasschuerg/InfluxDB-Client-for-Arduino/pull/120) - Improved language wording in the Readme
911

src/InfluxData.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
*
3+
* InfluxData.cpp: InfluxDB Client for Arduino
4+
*
5+
* MIT License
6+
*
7+
* Copyright (c) 2018-2020 Tobias Schürg
8+
*
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy
10+
* of this software and associated documentation files (the "Software"), to deal
11+
* in the Software without restriction, including without limitation the rights
12+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
* copies of the Software, and to permit persons to whom the Software is
14+
* furnished to do so, subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included in all
17+
* copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
* SOFTWARE.
26+
*/
27+
#include "InfluxData.h"
28+
#include "util/helpers.h"
29+
30+
void InfluxData::setTimestamp(long int seconds)
31+
{
32+
_timestamp = timeStampToString(seconds) + "000000000";
33+
}
34+
35+
String InfluxData::toString() const {
36+
String t;
37+
return createLineProtocol(t);
38+
}

src/InfluxData.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class InfluxData : public Point {
3232

3333
void addValue(String key, float value) { addField(key, value); }
3434
void addValueString(String key, String value) { addField(key, value); }
35-
void setTimestamp(long int seconds) { _timestamp = String(seconds) + "000000000"; }
36-
37-
String toString() const { return toLineProtocol(); }
35+
void setTimestamp(long int seconds);
36+
String toString() const;
3837
};

src/InfluxDb.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ boolean Influxdb::write() {
142142
* Write a single measurement into the db.
143143
*/
144144
boolean Influxdb::write(InfluxData data) {
145-
return write(data.toLineProtocol());
145+
return write(pointToLineProtocol(data));
146146
}
147147

148148
/**

src/InfluxDbClient.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ bool InfluxDBClient::flushBufferInternal(bool flashOnlyFull) {
509509
yield();
510510
}
511511
//Have we emptied the buffer?
512-
INFLUXDB_CLIENT_DEBUG("[D] Success: %d, _bufferPointer: %d, _batchPointer: %d, _writeBuffer[_bufferPointer]_%x\n",success,_bufferPointer,_batchPointer, _writeBuffer[_bufferPointer]);
512+
INFLUXDB_CLIENT_DEBUG("[D] Success: %d, _bufferPointer: %d, _batchPointer: %d, _writeBuffer[_bufferPointer]_%p\n",success,_bufferPointer,_batchPointer, _writeBuffer[_bufferPointer]);
513513
if(_batchPointer == _bufferPointer && !_writeBuffer[_bufferPointer]) {
514514
_bufferPointer = 0;
515515
_batchPointer = 0;
@@ -534,7 +534,7 @@ void InfluxDBClient::dropCurrentBatch() {
534534
}
535535

536536
String InfluxDBClient::pointToLineProtocol(const Point& point) {
537-
return point.toLineProtocol(_writeOptions._defaultTags);
537+
return point.createLineProtocol(_writeOptions._defaultTags);
538538
}
539539

540540
bool InfluxDBClient::validateConnection() {
@@ -693,7 +693,7 @@ static String escapeJSONString(String &value) {
693693
int i,from = 0;
694694
while((i = value.indexOf('"',from)) > -1) {
695695
d++;
696-
if(i == value.length()-1) {
696+
if(i == (int)value.length()-1) {
697697
break;
698698
}
699699
from = i+1;
@@ -711,7 +711,7 @@ static String escapeJSONString(String &value) {
711711
case '\r': ret += "\\r"; break;
712712
case '\t': ret += "\\t"; break;
713713
default:
714-
if ('\x00' <= c && c <= '\x1f') {
714+
if (c <= '\x1f') {
715715
ret += "\\u";
716716
char buf[3 + 8 * sizeof(unsigned int)];
717717
sprintf(buf, "\\u%04u", c);

src/InfluxDbClient.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ class InfluxDBClient {
9191
// flushInterval - maximum number of seconds data will be held in buffer before are written to the db.
9292
// Data are written either when number of points in buffer reaches batchSize or time of
9393
// preserveConnection - true if HTTP connection should be kept open. Usable for frequent writes.
94-
[[deprecated("Use setWriteOptions(const WriteOptions &writeOptions)")]]
95-
void setWriteOptions(WritePrecision precision, uint16_t batchSize = 1, uint16_t bufferSize = 5, uint16_t flushInterval = 60, bool preserveConnection = true);
94+
void setWriteOptions(WritePrecision precision, uint16_t batchSize = 1, uint16_t bufferSize = 5, uint16_t flushInterval = 60, bool preserveConnection = true) __attribute__ ((deprecated("Use setWriteOptions(const WriteOptions &writeOptions)")));
9695
// Sets custom write options. See WriteOptions doc for more info.
9796
// Must be called before calling any method initiating a connection to server.
9897
// Example:

src/Point.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,16 @@ void Point::putField(String name, String value) {
6060
}
6161

6262
String Point::toLineProtocol(String includeTags) const {
63-
String line = _measurement;
64-
line.reserve(1 + includeTags.length() + 1 + _tags.length() + 1 + _fields.length() + 1 + _timestamp.length());
65-
if(includeTags.length()>0) {
63+
return createLineProtocol(includeTags);
64+
}
65+
66+
String Point::createLineProtocol(String &incTags) const {
67+
String line;
68+
line.reserve(_measurement.length() + 1 + incTags.length() + 1 + _tags.length() + 1 + _fields.length() + 1 + _timestamp.length());
69+
line += _measurement;
70+
if(incTags.length()>0) {
6671
line += ",";
67-
line += includeTags;
72+
line += incTags;
6873
}
6974
if(hasTags()) {
7075
line += ",";
@@ -79,7 +84,7 @@ String Point::toLineProtocol(String includeTags) const {
7984
line += _timestamp;
8085
}
8186
return line;
82-
}
87+
}
8388

8489
void Point::setTime(WritePrecision precision) {
8590
struct timeval tv;

src/Point.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
* It defines data to be written to InfluxDB.
3636
*/
3737
class Point {
38+
friend class InfluxDBClient;
3839
public:
3940
Point(String measurement);
4041
// Adds string tag
@@ -67,17 +68,19 @@ class Point {
6768
bool hasTags() const { return _tags.length() > 0; }
6869
// True if a point contains timestamp
6970
bool hasTime() const { return _timestamp.length() > 0; }
70-
// Creates line protocol with optionaly added tags
71-
[[deprecated("Use InfluxDBClient::pointToLineProtocol()")]]
72-
String toLineProtocol(String includeTags = "") const;
71+
// Creates line protocol with optionally added tags
72+
String toLineProtocol(String includeTags = "") const __attribute__ ((deprecated("Use InfluxDBClient::pointToLineProtocol()")));
7373
// returns current timestamp
7474
String getTime() const { return _timestamp; }
7575
protected:
7676
String _measurement;
7777
String _tags;
7878
String _fields;
79-
String _timestamp;
79+
String _timestamp;
80+
protected:
8081
// method for formating field into line protocol
8182
void putField(String name, String value);
83+
// Creates line protocol string
84+
String createLineProtocol(String &incTags) const;
8285
};
8386
#endif //_POINT_H_

src/query/FluxParser.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ int FluxQueryResult::getColumnIndex(String columnName) {
6262

6363
FluxValue FluxQueryResult::getValueByIndex(int index) {
6464
FluxValue ret;
65-
if(index >= 0 && index < _data->_columnValues.size()) {
65+
if(index >= 0 && index < (int)_data->_columnValues.size()) {
6666
ret = _data->_columnValues[index];
6767
}
6868
return ret;
@@ -156,7 +156,7 @@ bool FluxQueryResult::next() {
156156
INFLUXDB_CLIENT_DEBUG("Error '%s'\n", _data->_error.c_str());
157157
return false;
158158
} else {
159-
for(int i=1;i < vals.size(); i++) {
159+
for(unsigned int i=1;i < vals.size(); i++) {
160160
_data->_columnNames.push_back(vals[i]);
161161
}
162162
}
@@ -174,7 +174,7 @@ bool FluxQueryResult::next() {
174174
INFLUXDB_CLIENT_DEBUG("Error '%s'\n", _data->_error.c_str());
175175
return false;
176176
}
177-
for(int i=1;i < vals.size(); i++) {
177+
for(unsigned int i=1;i < vals.size(); i++) {
178178
FluxBase *v = nullptr;
179179
if(vals[i].length() > 0) {
180180
v = convertValue(vals[i], _data->_columnDatatypes[i-1]);
@@ -191,7 +191,7 @@ bool FluxQueryResult::next() {
191191
_data->_tablePosition++;
192192
clearColumns();
193193
_data->_tableChanged = true;
194-
for(int i=1;i < vals.size(); i++) {
194+
for(unsigned int i=1;i < vals.size(); i++) {
195195
_data->_columnDatatypes.push_back(vals[i]);
196196
}
197197
parsingState = ParsingStateNameRow;

src/util/helpers.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void timeSync(const char *tzInfo, const char* ntpServer1, const char* ntpServer2
3434
// Wait till time is synced
3535
Serial.print("Syncing time");
3636
int i = 0;
37-
while (time(nullptr) < 1000000000ul && i < 40) {
37+
while (time(nullptr) < 1000000000l && i < 40) {
3838
Serial.print(".");
3939
delay(500);
4040
i++;
@@ -129,7 +129,7 @@ static char hex_digit(char c) {
129129
String urlEncode(const char* src) {
130130
int n=0;
131131
char c,*s = (char *)src;
132-
while (c = *s++) {
132+
while ((c = *s++)) {
133133
if(strchr(invalidChars, c)) {
134134
n++;
135135
}

0 commit comments

Comments
 (0)