use builtin NaN for 0 voltage
This commit is contained in:
parent
0143191cb5
commit
c084a8c5be
@ -1,8 +1,10 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <RCSwitch.h>
|
#include <RCSwitch.h>
|
||||||
#include <Adafruit_Sensor.h>
|
#include <Adafruit_Sensor.h>
|
||||||
#include <ArduinoJson.h>
|
|
||||||
#include "Tiny.h"
|
#include "Tiny.h"
|
||||||
|
|
||||||
|
#define ARDUINOJSON_ENABLE_NAN 1
|
||||||
|
#include <ArduinoJson.h>
|
||||||
#include "Dht.h"
|
#include "Dht.h"
|
||||||
|
|
||||||
|
|
||||||
@ -48,20 +50,18 @@ bool buildSensorJson(JsonDocument& jsonDoc, unsigned long value) {
|
|||||||
|
|
||||||
JsonObject sensor = jsonDoc.createNestedObject("sensor");
|
JsonObject sensor = jsonDoc.createNestedObject("sensor");
|
||||||
|
|
||||||
float voltage = (float)GET_VCC(value)/1000;
|
unsigned long voltage = GET_VCC(value);
|
||||||
if (voltage != 0) {
|
sensor["voltage"] = voltage == 0 ? NAN : (float)voltage / 1000;
|
||||||
sensor["voltage"] = voltage;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (GET_TYPE(value)) {
|
switch (GET_TYPE(value)) {
|
||||||
case SensorType::GENERIC:
|
case SensorType::GENERIC:
|
||||||
sensor["value"] = GET_VALUE(value);
|
sensor["value"] = GET_VALUE(value);
|
||||||
break;
|
break;
|
||||||
case SensorType::TEMPERATURE:
|
case SensorType::TEMPERATURE:
|
||||||
sensor["temperature"] = (float)GET_TEMP(value)/10;
|
sensor["temperature"] = (float)GET_TEMP(value) / 10;
|
||||||
break;
|
break;
|
||||||
case SensorType::HUMIDITY:
|
case SensorType::HUMIDITY:
|
||||||
sensor["humidity"] = (float)GET_HUMIDITY(value)/10;
|
sensor["humidity"] = (float)GET_HUMIDITY(value) / 10;
|
||||||
break;
|
break;
|
||||||
case SensorType::CONTACT:
|
case SensorType::CONTACT:
|
||||||
sensor["state"] = GET_STATE(value) ? "on" : "off";
|
sensor["state"] = GET_STATE(value) ? "on" : "off";
|
||||||
@ -69,7 +69,7 @@ bool buildSensorJson(JsonDocument& jsonDoc, unsigned long value) {
|
|||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ void runJsonCommand(String cmd) {
|
|||||||
DeserializationError err = deserializeJson(jsonArray, cmd);
|
DeserializationError err = deserializeJson(jsonArray, cmd);
|
||||||
if (err == DeserializationError::Ok) {
|
if (err == DeserializationError::Ok) {
|
||||||
JsonArray array = jsonArray.as<JsonArray>();
|
JsonArray array = jsonArray.as<JsonArray>();
|
||||||
for(JsonVariant jsonDoc : array) {
|
for (JsonVariant jsonDoc : array) {
|
||||||
if (jsonDoc.containsKey("rcSwitch")) {
|
if (jsonDoc.containsKey("rcSwitch")) {
|
||||||
JsonObject rcSwitch = jsonDoc["rcSwitch"];
|
JsonObject rcSwitch = jsonDoc["rcSwitch"];
|
||||||
unsigned int protocol = rcSwitch["protocol"];
|
unsigned int protocol = rcSwitch["protocol"];
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
#define GET_TEMP(value) (((unsigned long)value >> 18) & 0x2FF)
|
#define GET_TEMP(value) (((unsigned long)value >> 18) & 0x2FF)
|
||||||
#define GET_HUMIDITY(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_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 {
|
enum SensorType {
|
||||||
GENERIC = 4,
|
GENERIC = 4,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user