Browse Source

Do not quote numbers in MQTT JSON payloads

webui
Xose Pérez 6 years ago
parent
commit
dd12251e43
2 changed files with 11 additions and 1 deletions
  1. +10
    -1
      code/espurna/mqtt.ino
  2. +1
    -0
      code/espurna/utils.ino

+ 10
- 1
code/espurna/mqtt.ino View File

@ -574,7 +574,16 @@ unsigned char _mqttBuildTree(JsonObject& root, char parent) {
JsonObject& elements = root.createNestedObject(element.topic);
unsigned char num = _mqttBuildTree(elements, i);
if (0 == num) {
root.set(element.topic, element.message);
if (isNumber(element.message)) {
double value = atof(element.message);
if (value == int(value)) {
root.set(element.topic, int(value));
} else {
root.set(element.topic, value);
}
} else {
root.set(element.topic, element.message);
}
}
}
}


+ 1
- 0
code/espurna/utils.ino View File

@ -451,6 +451,7 @@ int __get_adc_mode() {
bool isNumber(const char * s) {
unsigned char len = strlen(s);
if (0 == len) return false;
bool decimal = false;
for (unsigned char i=0; i<len; i++) {
if (s[i] == '-') {


Loading…
Cancel
Save