Both are fine, so whichever makes your code easier to read. One Publisher per topic sounds easiest. One Publisher per topic takes more memory though.
Pay attention to MQTT.MQTTParam.g_udiMaxPublishersAndSubscribers which has a default value of 20. You can change this through Library Manager.
π
2
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Since the only difference between the topics is the building number, I thought this would be a good use case for a "FOR LOOP". I put my subscribe function block inside the for loop and increment the building number. The issue is that I receive the payload for the last topic only.
Hello,
I would like to ask for some advice.
Given a couple of sensors (lets say 10 pieces) which data I would like to send to an MQTT broker.
So which one idea is more favorable?
wsTopicNameattribute while publishing.Thanks for your help in advance!
Reading up on it you alter the wsTopicName attribute.
Source
Source 2
Both are fine, so whichever makes your code easier to read. One Publisher per topic sounds easiest. One Publisher per topic takes more memory though.
Pay attention to MQTT.MQTTParam.g_udiMaxPublishersAndSubscribers which has a default value of 20. You can change this through Library Manager.
Thanks for giving a better answer and correcting me
(β’ββ’ )
Hello, I know this is an older thread, but I am running into issues trying to use one subscribe function block and altering the subscription topic.
I want to subscribe to 31 topics. See topic examples below:
Since the only difference between the topics is the building number, I thought this would be a good use case for a "FOR LOOP". I put my subscribe function block inside the for loop and increment the building number. The issue is that I receive the payload for the last topic only.
Below are my variables:
Below is my for loop with the subscribe function block:
Any assistance to point me in the right direction would be appreciated!
Last edit: aott33 2023-04-02