Generalize the use of JSON_MSG_BUFFER (#1114)
* Generalize the use of JSON_MSG_BUFFER instead of calculated buffer
This commit is contained in:
1 parent
afd7a96537
commit
66ce0d5a41
6 files changed
+10
-28
No files matched your search
+1
-6
@@ -127,12 +127,7 @@ void setupRF() {
|
|||||||
|
|
||||||
void RFtoMQTT() {
|
void RFtoMQTT() {
|
||||||
if (mySwitch.available()) {
|
if (mySwitch.available()) {
|
||||||
# ifdef ZradioCC1101 //receiving with CC1101
|
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||||
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(8);
|
|
||||||
# else
|
|
||||||
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(7);
|
|
||||||
# endif
|
|
||||||
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
|
||||||
JsonObject RFdata = jsonBuffer.to<JsonObject>();
|
JsonObject RFdata = jsonBuffer.to<JsonObject>();
|
||||||
Log.trace(F("Rcv. RF" CR));
|
Log.trace(F("Rcv. RF" CR));
|
||||||
# ifdef ESP32
|
# ifdef ESP32
|
||||||
|
|||||||
@@ -119,8 +119,7 @@ void RF2toMQTTdiscovery(JsonObject& data) {
|
|||||||
void RF2toMQTT() {
|
void RF2toMQTT() {
|
||||||
if (rf2rd.hasNewData) {
|
if (rf2rd.hasNewData) {
|
||||||
Log.trace(F("Creating RF2 buffer" CR));
|
Log.trace(F("Creating RF2 buffer" CR));
|
||||||
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(5);
|
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||||
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
|
||||||
JsonObject RF2data = jsonBuffer.to<JsonObject>();
|
JsonObject RF2data = jsonBuffer.to<JsonObject>();
|
||||||
|
|
||||||
rf2rd.hasNewData = false;
|
rf2rd.hasNewData = false;
|
||||||
|
|||||||
@@ -36,8 +36,7 @@ void PairedDeviceAdded(byte newID) {
|
|||||||
Serial.print("ZgatewayWeatherStation: New device paired ");
|
Serial.print("ZgatewayWeatherStation: New device paired ");
|
||||||
Serial.println(newID, DEC);
|
Serial.println(newID, DEC);
|
||||||
# endif
|
# endif
|
||||||
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(2);
|
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||||
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
|
||||||
JsonObject RFdata = jsonBuffer.to<JsonObject>();
|
JsonObject RFdata = jsonBuffer.to<JsonObject>();
|
||||||
RFdata["sensor"] = newID;
|
RFdata["sensor"] = newID;
|
||||||
RFdata["action"] = "paired";
|
RFdata["action"] = "paired";
|
||||||
@@ -55,8 +54,7 @@ void setupWeatherStation() {
|
|||||||
void sendWindSpeedData(byte id, float wind_speed, byte battery_status) {
|
void sendWindSpeedData(byte id, float wind_speed, byte battery_status) {
|
||||||
unsigned long MQTTvalue = 10000 + round(wind_speed);
|
unsigned long MQTTvalue = 10000 + round(wind_speed);
|
||||||
if (!isAduplicateSignal(MQTTvalue)) { // conditions to avoid duplications of RF -->MQTT
|
if (!isAduplicateSignal(MQTTvalue)) { // conditions to avoid duplications of RF -->MQTT
|
||||||
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(3);
|
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||||
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
|
||||||
JsonObject RFdata = jsonBuffer.to<JsonObject>();
|
JsonObject RFdata = jsonBuffer.to<JsonObject>();
|
||||||
RFdata["sensor"] = id;
|
RFdata["sensor"] = id;
|
||||||
RFdata["wind_speed"] = wind_speed;
|
RFdata["wind_speed"] = wind_speed;
|
||||||
@@ -70,8 +68,7 @@ void sendWindSpeedData(byte id, float wind_speed, byte battery_status) {
|
|||||||
void sendRainData(byte id, float rain_volume, byte battery_status) {
|
void sendRainData(byte id, float rain_volume, byte battery_status) {
|
||||||
unsigned long MQTTvalue = 11000 + round(rain_volume * 10.0);
|
unsigned long MQTTvalue = 11000 + round(rain_volume * 10.0);
|
||||||
if (!isAduplicateSignal(MQTTvalue)) { // conditions to avoid duplications of RF -->MQTT
|
if (!isAduplicateSignal(MQTTvalue)) { // conditions to avoid duplications of RF -->MQTT
|
||||||
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(3);
|
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||||
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
|
||||||
JsonObject RFdata = jsonBuffer.to<JsonObject>();
|
JsonObject RFdata = jsonBuffer.to<JsonObject>();
|
||||||
RFdata["sensor"] = id;
|
RFdata["sensor"] = id;
|
||||||
RFdata["rain_volume"] = rain_volume;
|
RFdata["rain_volume"] = rain_volume;
|
||||||
@@ -85,8 +82,7 @@ void sendRainData(byte id, float rain_volume, byte battery_status) {
|
|||||||
void sendWindData(byte id, int wind_direction, float wind_gust, byte battery_status) {
|
void sendWindData(byte id, int wind_direction, float wind_gust, byte battery_status) {
|
||||||
unsigned long MQTTvalue = 20000 + round(wind_gust * 10.0) + wind_direction;
|
unsigned long MQTTvalue = 20000 + round(wind_gust * 10.0) + wind_direction;
|
||||||
if (!isAduplicateSignal(MQTTvalue)) { // conditions to avoid duplications of RF -->MQTT
|
if (!isAduplicateSignal(MQTTvalue)) { // conditions to avoid duplications of RF -->MQTT
|
||||||
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(4);
|
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||||
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
|
||||||
JsonObject RFdata = jsonBuffer.to<JsonObject>();
|
JsonObject RFdata = jsonBuffer.to<JsonObject>();
|
||||||
RFdata["sensor"] = id;
|
RFdata["sensor"] = id;
|
||||||
RFdata["wind_direction"] = wind_direction;
|
RFdata["wind_direction"] = wind_direction;
|
||||||
@@ -101,8 +97,7 @@ void sendWindData(byte id, int wind_direction, float wind_gust, byte battery_sta
|
|||||||
void sendTemperatureData(byte id, float temperature, int humidity, byte battery_status) {
|
void sendTemperatureData(byte id, float temperature, int humidity, byte battery_status) {
|
||||||
unsigned long MQTTvalue = 40000 + abs(round(temperature * 100.0)) + humidity;
|
unsigned long MQTTvalue = 40000 + abs(round(temperature * 100.0)) + humidity;
|
||||||
if (!isAduplicateSignal(MQTTvalue)) { // conditions to avoid duplications of RF -->MQTT
|
if (!isAduplicateSignal(MQTTvalue)) { // conditions to avoid duplications of RF -->MQTT
|
||||||
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(4);
|
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||||
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
|
||||||
JsonObject RFdata = jsonBuffer.to<JsonObject>();
|
JsonObject RFdata = jsonBuffer.to<JsonObject>();
|
||||||
RFdata["sensor"] = id;
|
RFdata["sensor"] = id;
|
||||||
RFdata["tempc"] = temperature;
|
RFdata["tempc"] = temperature;
|
||||||
|
|||||||
+1
-6
@@ -54,12 +54,7 @@ void MeasureADC() {
|
|||||||
} else {
|
} else {
|
||||||
if (val >= persistedadc + ThresholdReadingADC || val <= persistedadc - ThresholdReadingADC) {
|
if (val >= persistedadc + ThresholdReadingADC || val <= persistedadc - ThresholdReadingADC) {
|
||||||
Log.trace(F("Creating ADC buffer" CR));
|
Log.trace(F("Creating ADC buffer" CR));
|
||||||
# if defined(ADC_DIVIDER)
|
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||||
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(2);
|
|
||||||
# else
|
|
||||||
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(1);
|
|
||||||
# endif
|
|
||||||
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
|
||||||
JsonObject ADCdata = jsonBuffer.to<JsonObject>();
|
JsonObject ADCdata = jsonBuffer.to<JsonObject>();
|
||||||
ADCdata["adc"] = (int)val;
|
ADCdata["adc"] = (int)val;
|
||||||
# if defined(ADC_DIVIDER)
|
# if defined(ADC_DIVIDER)
|
||||||
|
|||||||
@@ -77,8 +77,7 @@ void MeasureGPIOInput() {
|
|||||||
if (reading != InputState) {
|
if (reading != InputState) {
|
||||||
InputState = reading;
|
InputState = reading;
|
||||||
Log.trace(F("Creating GPIOInput buffer" CR));
|
Log.trace(F("Creating GPIOInput buffer" CR));
|
||||||
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(1);
|
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||||
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
|
||||||
JsonObject GPIOdata = jsonBuffer.to<JsonObject>();
|
JsonObject GPIOdata = jsonBuffer.to<JsonObject>();
|
||||||
if (InputState == HIGH) {
|
if (InputState == HIGH) {
|
||||||
GPIOdata["gpio"] = "HIGH";
|
GPIOdata["gpio"] = "HIGH";
|
||||||
|
|||||||
@@ -41,8 +41,7 @@ void setupHCSR501() {
|
|||||||
|
|
||||||
void MeasureHCSR501() {
|
void MeasureHCSR501() {
|
||||||
if (millis() > TimeBeforeStartHCSR501) { //let time to init the PIR sensor
|
if (millis() > TimeBeforeStartHCSR501) { //let time to init the PIR sensor
|
||||||
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(1);
|
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
|
||||||
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
|
|
||||||
JsonObject HCSR501data = jsonBuffer.to<JsonObject>();
|
JsonObject HCSR501data = jsonBuffer.to<JsonObject>();
|
||||||
static int pirState = LOW;
|
static int pirState = LOW;
|
||||||
int PresenceValue = digitalRead(HCSR501_GPIO);
|
int PresenceValue = digitalRead(HCSR501_GPIO);
|
||||||
|
|||||||
Reference in new issue
Block a user