use builtin NaN for 0 voltage

This commit is contained in:
Nicu Hodos 2022-10-13 12:13:13 +02:00
parent 88ddfb824a
commit 9acc4e3802
2 changed files with 10 additions and 10 deletions

View File

@ -1,8 +1,10 @@
#include <Arduino.h>
#include <RCSwitch.h>
#include <Adafruit_Sensor.h>
#include <ArduinoJson.h>
#include "Tiny.h"
#define ARDUINOJSON_ENABLE_NAN 1
#include <ArduinoJson.h>
#include "Dht.h"
@ -48,10 +50,8 @@ bool buildSensorJson(JsonDocument& jsonDoc, unsigned long value) {
JsonObject sensor = jsonDoc.createNestedObject("sensor");
float voltage = (float)GET_VCC(value)/1000;
if (voltage != 0) {
sensor["voltage"] = voltage;
}
unsigned long voltage = GET_VCC(value);
sensor["voltage"] = voltage == 0 ? NAN : (float)voltage / 1000;
switch (GET_TYPE(value)) {
case SensorType::GENERIC:

View File

@ -13,7 +13,7 @@
#define GET_TEMP(value) (((unsigned long)value >> 18) & 0x2FF)
#define GET_HUMIDITY(value) (((unsigned long)value >> 18) & 0x2FF)
#define GET_VALUE(value) (((unsigned long)value >> 18) & 0x2FF)
#define GET_VCC(value) ((value >> 5) & 0x1FFF)
#define GET_VCC(value) (((unsigned long)value >> 5) & 0x1FFF)
enum SensorType {
GENERIC = 4,