mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-11 02:09:57 +03:00
check for max sensors - #327
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
// Dallas external temp sensors
|
// Dallas external temp sensors
|
||||||
#include "ds18.h"
|
#include "ds18.h"
|
||||||
DS18 ds18;
|
DS18 ds18;
|
||||||
|
#define DS18_MQTT_PAYLOAD_MAXSIZE 400
|
||||||
|
|
||||||
// public libraries
|
// public libraries
|
||||||
#include <ArduinoJson.h> // https://github.com/bblanchon/ArduinoJson
|
#include <ArduinoJson.h> // https://github.com/bblanchon/ArduinoJson
|
||||||
@@ -565,8 +566,13 @@ void publishSensorValues() {
|
|||||||
return; // no sensors attached
|
return; // no sensors attached
|
||||||
}
|
}
|
||||||
|
|
||||||
StaticJsonDocument<400> doc;
|
// each payload per sensor is 30 bytes so calculate if we have enough space
|
||||||
JsonObject sensors = doc.to<JsonObject>();
|
if ((EMSESP_Settings.dallas_sensors * 30) > DS18_MQTT_PAYLOAD_MAXSIZE) {
|
||||||
|
myDebug("Error: too many Dallas sensors for MQTT payload");
|
||||||
|
}
|
||||||
|
|
||||||
|
StaticJsonDocument<DS18_MQTT_PAYLOAD_MAXSIZE> doc;
|
||||||
|
JsonObject sensors = doc.to<JsonObject>();
|
||||||
|
|
||||||
bool hasdata = false;
|
bool hasdata = false;
|
||||||
char buffer[128] = {0};
|
char buffer[128] = {0};
|
||||||
@@ -583,7 +589,7 @@ void publishSensorValues() {
|
|||||||
return; // nothing to send
|
return; // nothing to send
|
||||||
}
|
}
|
||||||
|
|
||||||
char data[400] = {0};
|
char data[DS18_MQTT_PAYLOAD_MAXSIZE] = {0};
|
||||||
serializeJson(doc, data, sizeof(data));
|
serializeJson(doc, data, sizeof(data));
|
||||||
myDebugLog("Publishing external sensor data via MQTT");
|
myDebugLog("Publishing external sensor data via MQTT");
|
||||||
myESP.mqttPublish(TOPIC_EXTERNAL_SENSORS, data);
|
myESP.mqttPublish(TOPIC_EXTERNAL_SENSORS, data);
|
||||||
|
|||||||
@@ -10,8 +10,9 @@
|
|||||||
|
|
||||||
#include "ems.h"
|
#include "ems.h"
|
||||||
|
|
||||||
// TOPICS with _CMD_ are used for receiving commands from an MQTT Broker
|
// TOPICS with *_CMD_* are used for receiving commands from an MQTT Broker
|
||||||
// EMS-ESP will subscribe to these topics
|
// EMS-ESP will subscribe to these topics
|
||||||
|
|
||||||
#define TOPIC_GENERIC_CMD "generic_cmd" // for receiving generic system commands via MQTT
|
#define TOPIC_GENERIC_CMD "generic_cmd" // for receiving generic system commands via MQTT
|
||||||
|
|
||||||
// MQTT for thermostat
|
// MQTT for thermostat
|
||||||
|
|||||||
Reference in New Issue
Block a user