Custom MQTT topic subscribtion in firmware

Hi here,

sorry for re-opening, but I went through this topic and I’m still not sure, how to deal with it.

At this moment, I can see following topics with values on my mqtt brooker:

node/kit-flood-detector:0/thermometer/0:1/temperature 9.00
node/kit-lcd-thermostat:0/thermometer/0:1/temperature 20.81

And I’m trying to subscribe it in my code (also, an example), but it does not work:

static const bc_radio_sub_t subscribes[] = {
        {"kit-flood-detector:0/thermometer/0:1/temperature",  BC_RADIO_SUB_PT_FLOAT, temperature_outdoor_roof_set, NULL},
        {"kit-lcd-thermostat:0/thermometer/0:1/temperature",  BC_RADIO_SUB_PT_FLOAT, temperature_outdoor_set,      NULL},
};
bc_radio_init(BC_RADIO_MODE_NODE_LISTENING);
bc_radio_set_rx_timeout_for_sleeping_node(2000);
bc_radio_set_subs((bc_radio_sub_t *) subscribes, sizeof(subscribes) / sizeof(bc_radio_sub_t));
bc_radio_pairing_request(FIRMWARE, VERSION);

It looks like there are two problems:

  1. correct format of subscribes
  2. length of topic name to subscribes

Some of my messages are generated by nodes not so easily available to update, so I’m thinking about resending those messages by Node-RED. In this case, what will be the best name to publish and subscribe?

I’m thinking about following format to be sent by Node-RED:

meteo/-/temp/outdoor
meteo/-/temp/indoor

What will be be the right name to subscribe?

Thank you in advance for any advice.

Hi expee,

in firmware the MQTT topic text has to have 4 levels (a/b/c/d) and also you cannot prepend the node name, because that is converted by gateway and the node itself is addressed by ID. (this post)

Since I don’t know exactly what are trying to achieve to send I will guess that you would like to display value from one node to other node to display it for example on LCD Module.

So your code

static const bc_radio_sub_t subscribes[] = {
        {"kit-flood-detector:0/thermometer/0:1/temperature",  BC_RADIO_SUB_PT_FLOAT, temperature_outdoor_roof_set, NULL},
        {"kit-lcd-thermostat:0/thermometer/0:1/temperature",  BC_RADIO_SUB_PT_FLOAT, temperature_outdoor_set,      NULL},
};

Should be something like this

static const bc_radio_sub_t subscribes[] = {
        {"meteo/-/temp/outdoor",  BC_RADIO_SUB_PT_FLOAT, temperature_outdoor_set, NULL},
        {"meteo/-/temp/indoor",  BC_RADIO_SUB_PT_FLOAT, temperature_indoor_set,      NULL},
};

Then if this module has alias for example lcd-display:0 you publish float value message to:
node/lcd-display:0/meteo/-/temp/outdoor.

Hi @hub.martin,

thank you for answer. Yes, I’m trying to display data from other nodes on LCD.

Now it makes sense. I will try this and will update you here how it works.

Thank you!

Best regards,
Pavel

1 Like

Hi @hub.martin,

works as expected. Thank you very much for your help.

Best regards,
Pavel

1 Like

Thanks for posting the picture. Is your code for Core Module public?

Yes, sure.

https://bitbucket.org/xpjninja/bigclown-meteo-station

1 Like