From 51ee22273b2aaef490a17c218ebc04b6d317f94e Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 25 Oct 2018 10:44:59 +0200 Subject: [PATCH] Fix invalid JSON Fix invalid JSON floating point result from nan into null (#4147) --- sonoff/_changelog.ino | 3 ++- sonoff/support.ino | 16 +++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index c3daa6e42..0c13b2ef7 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,6 +1,7 @@ /* 6.2.1.19 20181023 * Fix header file execution order by renaming user_config.h to my_user_config.h - * + * Fix invalid JSON floating point result from nan into null (#4147) + * * 6.2.1.18 20181019 * Add more API callbacks and document API.md * Add support for La Crosse TX20 Anemometer (#2654, #3146) diff --git a/sonoff/support.ino b/sonoff/support.ino index fad0064be..1e960bb16 100644 --- a/sonoff/support.ino +++ b/sonoff/support.ino @@ -196,7 +196,12 @@ int TextToInt(char *str) char* dtostrfd(double number, unsigned char prec, char *s) { - return dtostrf(number, 1, prec, s); + if (isnan(number)) { + strcpy(s, "null"); + return s; + } else { + return dtostrf(number, 1, prec, s); + } } char* Unescape(char* buffer, uint16_t* size) @@ -630,10 +635,6 @@ boolean GetUsedInModule(byte val, uint8_t *arr) if (GPIO_I2C_SCL == val) { return true; } if (GPIO_I2C_SDA == val) { return true; } #endif -#ifndef USE_SR04 - if (GPIO_SR04_TRIG == val) { return true; } - if (GPIO_SR04_ECHO == val) { return true; } -#endif #ifndef USE_WS2812 if (GPIO_WS2812 == val) { return true; } #endif @@ -706,6 +707,11 @@ boolean GetUsedInModule(byte val, uint8_t *arr) if (GPIO_HX711_SCK == val) { return true; } if (GPIO_HX711_DAT == val) { return true; } #endif +#ifndef USE_TX20_WIND_SENSOR + if (GPIO_TX20_TXD_BLACK == val) { return true; } +#endif + + if ((val >= GPIO_REL1) && (val < GPIO_REL1 + MAX_RELAYS)) { offset = (GPIO_REL1_INV - GPIO_REL1); }