gateway: adapt it to publish sensors on MQTT #1

Merged
nicu merged 5 commits from gateway into master 2022-10-13 20:28:48 +02:00
2 changed files with 10 additions and 10 deletions
Showing only changes of commit c084a8c5be - Show all commits

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,