Fix influxdb id regression

This commit is contained in:
Theo Arends 2021-08-16 11:44:27 +02:00
parent 0d9678eef6
commit 1ab2b2c865
2 changed files with 25 additions and 22 deletions

View File

@ -524,6 +524,7 @@ bool StrCaseStr_P(const char* source, const char* search) {
}
bool IsNumeric(const char* value) {
// Test for characters '-.0123456789'
char *digit = (char*)value;
while (isdigit(*digit) || *digit == '.' || *digit == '-') { digit++; }
return (*digit == '\0');

View File

@ -293,18 +293,21 @@ void InfluxDbProcessJson(void) {
} else {
// Level 2
// { ... "ANALOG":{"Temperature":184.72},"DS18B20":{"Id":"01144A0CB2AA","Temperature":24.88},"HTU21":{"Temperature":25.32,"Humidity":49.2,"DewPoint":13.88},"Global":{"Temperature":24.88,"Humidity":49.2,"DewPoint":13.47}, ... }
bool isarray = value2.isArray();
const char* value = InfluxDbNumber(number, (isarray) ? (value2.getArray())[0].getStr() : value2.getStr());
LowerCase(type, key2.getStr());
bool is_id = (!strcmp_P(type, PSTR("id"))); // Index for DS18B20
bool is_array = value2.isArray();
const char* value = nullptr;
if (is_id && !is_array) {
snprintf_P(sensor_id, sizeof(sensor_id), PSTR(",id=%s"), value2.getStr());
} else {
value = InfluxDbNumber(number, (is_array) ? (value2.getArray())[0].getStr() : value2.getStr());
}
if (value != nullptr) {
LowerCase(sensor, key1.getStr());
LowerCase(type, key2.getStr());
// AddLog(LOG_LEVEL_DEBUG, PSTR("IFX2: sensor %s (%s), type %s (%s)"), key1.getStr(), sensor, key2.getStr(), type);
if (strcmp(type, "id") == 0) { // Index for DS18B20
snprintf_P(sensor_id, sizeof(sensor_id), PSTR(",id=%s"), value);
} else {
if (isarray) {
if (is_array) {
JsonParserArray arr = value2.getArray();
uint32_t i = 0;
for (auto val : arr) {
@ -325,7 +328,6 @@ void InfluxDbProcessJson(void) {
}
}
}
}
} else {
// Level 1
// {"Time":"2021-08-13T14:15:56","Switch1":"ON","Switch2":"OFF", ... "TempUnit":"C"}