Skip to content

Commit

Permalink
Option for "flat" MQTT hierarchy without category number by using #de…
Browse files Browse the repository at this point in the history
…fine NO_MQTT_CATEGORY in BSB_LAN_config.h
  • Loading branch information
fredlcore committed Dec 4, 2024
1 parent 195cef0 commit efa4172
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion BSB_LAN/include/mqtt_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ void mqtt_sendtoBroker(parameter param) {
StringBuffer sb_topic;
initStringBuffer(&sb_payload, MQTTPayload, sizeof(MQTTPayload));
initStringBuffer(&sb_topic, MQTTTopic, sizeof(MQTTTopic));
#if defined(NO_MQTT_CATEGORY)
appendStringBuffer(&sb_topic, "%s/%d/%g/status", MQTTTopicPrefix, (param.dest_addr==-1?bus->getBusDest():param.dest_addr), param.number);
#else
appendStringBuffer(&sb_topic, "%s/%d/%d/%g/status", MQTTTopicPrefix, (param.dest_addr==-1?bus->getBusDest():param.dest_addr), decodedTelegram.cat, param.number);

#endif
switch(mqtt_mode)
{
// =============================================
Expand Down Expand Up @@ -441,7 +444,11 @@ boolean mqtt_send_discovery(boolean create=true) {
loadPrognrElementsFromTable(line, i);
loadCategoryDescAddr();
appendStringBuffer(&sb_topic, "homeassistant/");
#if defined(NO_MQTT_CATEGORY)
appendStringBuffer(&sb_payload, "{\"~\":\"%s/%d/%g\",\"unique_id\":\"%g-%d-%d-%d\",\"state_topic\":\"~/status\",", MQTTTopicPrefix, bus->getBusDest(), line, line, cmdtbl[i].dev_fam, cmdtbl[i].dev_var, my_dev_serial);
#else
appendStringBuffer(&sb_payload, "{\"~\":\"%s/%d/%d/%g\",\"unique_id\":\"%g-%d-%d-%d\",\"state_topic\":\"~/status\",", MQTTTopicPrefix, bus->getBusDest(), decodedTelegram.cat, line, line, cmdtbl[i].dev_fam, cmdtbl[i].dev_var, my_dev_serial);
#endif
if (decodedTelegram.isswitch) {
appendStringBuffer(&sb_payload, "\"icon\":\"mdi:toggle-switch\",");
} else if (!strcmp(decodedTelegram.unit, U_DEG) || !strcmp(decodedTelegram.unit, U_TEMP_PER_MIN) || !strcmp(decodedTelegram.unit, U_CEL_MIN)) {
Expand Down

0 comments on commit efa4172

Please sign in to comment.