Generalize the use of JSON_MSG_BUFFER (#1114)

* Generalize the use of JSON_MSG_BUFFER

instead of calculated buffer
This commit is contained in:
Florian authored and GitHub committed 2021-12-20 19:37:06 -06:00
1 parent afd7a96537
commit 66ce0d5a41
6 files changed
+10 -28

No files matched your search

+1 -6
View File
@@ -127,12 +127,7 @@ void setupRF() {
void RFtoMQTT() {
if (mySwitch.available()) {
# ifdef ZradioCC1101 //receiving with CC1101
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;
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
JsonObject RFdata = jsonBuffer.to<JsonObject>();
Log.trace(F("Rcv. RF" CR));
# ifdef ESP32
+1 -2
View File
@@ -119,8 +119,7 @@ void RF2toMQTTdiscovery(JsonObject& data) {
void RF2toMQTT() {
if (rf2rd.hasNewData) {
Log.trace(F("Creating RF2 buffer" CR));
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(5);
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
JsonObject RF2data = jsonBuffer.to<JsonObject>();
rf2rd.hasNewData = false;
+5 -10
View File
@@ -36,8 +36,7 @@ void PairedDeviceAdded(byte newID) {
Serial.print("ZgatewayWeatherStation: New device paired ");
Serial.println(newID, DEC);
# endif
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(2);
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
JsonObject RFdata = jsonBuffer.to<JsonObject>();
RFdata["sensor"] = newID;
RFdata["action"] = "paired";
@@ -55,8 +54,7 @@ void setupWeatherStation() {
void sendWindSpeedData(byte id, float wind_speed, byte battery_status) {
unsigned long MQTTvalue = 10000 + round(wind_speed);
if (!isAduplicateSignal(MQTTvalue)) { // conditions to avoid duplications of RF -->MQTT
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(3);
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
JsonObject RFdata = jsonBuffer.to<JsonObject>();
RFdata["sensor"] = id;
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) {
unsigned long MQTTvalue = 11000 + round(rain_volume * 10.0);
if (!isAduplicateSignal(MQTTvalue)) { // conditions to avoid duplications of RF -->MQTT
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(3);
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
JsonObject RFdata = jsonBuffer.to<JsonObject>();
RFdata["sensor"] = id;
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) {
unsigned long MQTTvalue = 20000 + round(wind_gust * 10.0) + wind_direction;
if (!isAduplicateSignal(MQTTvalue)) { // conditions to avoid duplications of RF -->MQTT
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(4);
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
JsonObject RFdata = jsonBuffer.to<JsonObject>();
RFdata["sensor"] = id;
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) {
unsigned long MQTTvalue = 40000 + abs(round(temperature * 100.0)) + humidity;
if (!isAduplicateSignal(MQTTvalue)) { // conditions to avoid duplications of RF -->MQTT
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(4);
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
JsonObject RFdata = jsonBuffer.to<JsonObject>();
RFdata["sensor"] = id;
RFdata["tempc"] = temperature;
+1 -6
View File
@@ -54,12 +54,7 @@ void MeasureADC() {
} else {
if (val >= persistedadc + ThresholdReadingADC || val <= persistedadc - ThresholdReadingADC) {
Log.trace(F("Creating ADC buffer" CR));
# if defined(ADC_DIVIDER)
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;
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
JsonObject ADCdata = jsonBuffer.to<JsonObject>();
ADCdata["adc"] = (int)val;
# if defined(ADC_DIVIDER)
+1 -2
View File
@@ -77,8 +77,7 @@ void MeasureGPIOInput() {
if (reading != InputState) {
InputState = reading;
Log.trace(F("Creating GPIOInput buffer" CR));
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(1);
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
JsonObject GPIOdata = jsonBuffer.to<JsonObject>();
if (InputState == HIGH) {
GPIOdata["gpio"] = "HIGH";
+1 -2
View File
@@ -41,8 +41,7 @@ void setupHCSR501() {
void MeasureHCSR501() {
if (millis() > TimeBeforeStartHCSR501) { //let time to init the PIR sensor
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(1);
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonBuffer;
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
JsonObject HCSR501data = jsonBuffer.to<JsonObject>();
static int pirState = LOW;
int PresenceValue = digitalRead(HCSR501_GPIO);