Skip to content

Commit

Permalink
[SYS] Reduce discovery msg size and increase buffer for ESP8266
Browse files Browse the repository at this point in the history
  • Loading branch information
1technophile committed Nov 11, 2024
1 parent 87228b5 commit 5f923da
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion main/User_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
# define JSON_MSG_BUFFER_MAX 1024 // Minimum size for the cover MQTT discovery message
# endif
# elif defined(ESP8266)
# define JSON_MSG_BUFFER 512 // Json message max buffer size, don't put 768 or higher it is causing unexpected behaviour on ESP8266, certificates handling with ESP8266 is not tested
# define JSON_MSG_BUFFER 544 // Json message max buffer size, don't put 768 or higher it is causing unexpected behaviour on ESP8266, certificates handling with ESP8266 is not tested
# define JSON_MSG_BUFFER_MAX 832 // Minimum size for MQTT discovery message
# endif
#endif
Expand Down
4 changes: 2 additions & 2 deletions main/ZgatewaySERIAL.ino
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ void SERIALtoX() {
if (SERIALdata.containsKey("origin") || SERIALdata.containsKey("topic")) {
# ifdef SecondaryModule
// We need to assign the discovery message to the primary module instead of the secondary module
if (SERIALdata.containsKey("device") && SERIALdata["device"].containsKey("via_device")) {
SERIALdata["device"]["via_device"] = gateway_name;
if (SERIALdata.containsKey("dev") && SERIALdata["dev"].containsKey("via_device")) {
SERIALdata["dev"]["via_device"] = gateway_name;
}
# endif
enqueueJsonObject(SERIALdata);
Expand Down
28 changes: 15 additions & 13 deletions main/ZmqttDiscovery.ino
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void announceDeviceTrigger(bool use_gateway_info, char* topic, char* type, char*
JsonObject sensor = jsonBuffer.to<JsonObject>();

// SET Default Configuration
sensor["automation_type"] = "trigger"; // The type of automation, must be ‘trigger’.
sensor["atype"] = "trigger"; // The type of automation, must be ‘trigger’.

//SET TYPE
if (type && type[0] != 0) {
Expand All @@ -117,9 +117,9 @@ void announceDeviceTrigger(bool use_gateway_info, char* topic, char* type, char*

//SET SUBTYPE
if (subtype && subtype[0] != 0) {
sensor["subtype"] = subtype;
sensor["stype"] = subtype;
} else {
sensor["subtype"] = "turn_on";
sensor["stype"] = "turn_on";
}

/* Set The topic */
Expand All @@ -136,20 +136,20 @@ void announceDeviceTrigger(bool use_gateway_info, char* topic, char* type, char*
/* Set The Devices */
StaticJsonDocument<JSON_MSG_BUFFER> jsonDeviceBuffer;
JsonObject device = jsonDeviceBuffer.to<JsonObject>();
JsonArray identifiers = device.createNestedArray("identifiers");
JsonArray identifiers = device.createNestedArray("ids");

if (use_gateway_info) {
device["name"] = gateway_name;
# ifndef GATEWAY_MODEL
String model = "";
serializeJson(modules, model);
device["model"] = model;
device["mdl"] = model;
# else
device["model"] = GATEWAY_MODEL;
device["mdl"] = GATEWAY_MODEL;
# endif

device["manufacturer"] = GATEWAY_MANUFACTURER;
device["sw_version"] = OMG_VERSION;
device["mf"] = GATEWAY_MANUFACTURER;
device["sw"] = OMG_VERSION;
identifiers.add(getMacAddress());

} else {
Expand All @@ -161,15 +161,15 @@ void announceDeviceTrigger(bool use_gateway_info, char* topic, char* type, char*

/*Set Connection */
if (device_id && device_id[0] != 0) {
JsonArray connections = device.createNestedArray("connections");
JsonArray connections = device.createNestedArray("cns");
JsonArray connection_mac = connections.createNestedArray();
connection_mac.add("mac");
connection_mac.add(device_id);
}

//Set manufacturer
if (device_manufacturer && device_manufacturer[0]) {
device["manufacturer"] = device_manufacturer;
device["mf"] = device_manufacturer;
}

//Set name
Expand All @@ -179,12 +179,12 @@ void announceDeviceTrigger(bool use_gateway_info, char* topic, char* type, char*

// set The Model
if (device_model && device_model[0]) {
device["model"] = device_model;
device["mdl"] = device_model;
}

device["via_device"] = gateway_name; //device name of the board
}
sensor["device"] = device; //device representing the board
sensor["dev"] = device; //device representing the board

/* Publish on the topic */
String topic_to_publish = String(discovery_prefix) + "/device_automation/" + String(Gateway_Short_Name) + "/" + String(unique_id) + "/config";
Expand Down Expand Up @@ -411,7 +411,9 @@ void createDiscovery(const char* sensor_type,
device["cu"] = String("http://") + String(ETH.localIP().toString()) + String("/"); //configuration_url
# endif
} else {
# ifdef ESP32
device["cu"] = String("http://") + String(WiFi.localIP().toString()) + String("/"); //configuration_url
# endif
}

device["sw"] = OMG_VERSION;
Expand Down Expand Up @@ -448,7 +450,7 @@ void createDiscovery(const char* sensor_type,
device["via_device"] = String(gateway_name); //device name of the board
}

sensor["device"] = device;
sensor["dev"] = device;

String topic = String(discovery_prefix) + "/" + String(sensor_type) + "/" + String(unique_id) + "/config";
Log.trace(F("Announce Device %s on %s" CR), String(sensor_type).c_str(), topic.c_str());
Expand Down

0 comments on commit 5f923da

Please sign in to comment.