When posting device data via MQTT, and since the ClientID is the DeviceID, can one device publish data to other devices topics?
Hey @Lars_Andersson,
I think I know what youâre asking, but please correct me if Iâm wrong.
Connection to the clientID will happen regardless, but if you try to report state to a different deviceID than the clientID, the connection to the clientID will break, and no state will be published.
Please let me know if Iâve interpreted incorrectly, or if you have any further questions.
Thank so much!
Heath
I think you understood me correctly.
So there is not another way I could do this?
Iâm doing a demo and already have dashboards made using several devices.
But now I want to test another device submitting data in place of several devices. Does it help if I create a gate device that will do this?
Hey @Lars_Andersson,
There are two options based on your use case:
- You can set up a gateway/peripherals relationship to for your devices. Like you mentioned, the gateway can report state on behalf of your peripherals.
- You could set up a custom topic to accept state data for all of the devices. You would trigger the custom topic from the broker and include your device information and values in the JSON. You can then add nodes to ârouteâ your workflow and report state for the devices.
If you have any additional information on your use case, please let me know, just in case neither of the above work for you.
Thank you!
Heath
So if I go with option 1 and create a new deviceID as a gateway type deice, will I then be able to use the gatewayâs deviceID as MQTT client ID and publish data for the other device IDâs as part of the /state topic?
Unfortunately, no. To do this, you would need to set up a custom topic as I mentioned above in option 2.
Thanks!
Heath
Can you show some screenshots of how I would do that?
Hey @Lars_Andersson!
Below are some screenshots on how you can set a custom MQTT topic and set up a workflow to report state for devices. It is important to note that for this example, the MQTT message included a âdevicesâ array in the message.
First, with an MQTT node, you can set the custom MQTT topic.
Once youâre sending MQTT messages to that topic, you can use a JSON: Decode node to format the string to an Object.
Using a Loop Node, you can loop through all the devices in the âdevicesâ array sent along with the MQTT package.
The Loop Node can then report state to each deviceID listed in the âdevicesâ array.
Hereâs the example payload that was used to trigger this workflow.
{
"devices": [
{
"deviceId":"5d35d2ece9bcf1000957fa02",
"temperature": 72
},
{
"deviceId":"5dcedf089285680007ea7974",
"temperature": 40
}
]
}
And, hereâs the workflow export:
mqtt-state-ingest-develop.flow (3.2 KB)
Thanks,
Heath
Iâm trying to change the âadditional mqtt topic accessâ values for an access key assigned to a device.
I selected âOnly the following additional topicâ and entered âdevicesâ as the topic name, and âPublishâ in topic access.
When trying to publish from this device , should I specify topic as : âlosant/{{deviceID}}/devicesâ or something else?
When I try this I see permission errors in the device debug log.
When granting access to additional MQTT topics, they can only be non-device MQTT topics, and not MQTT system or Losant-specific topics. In your above example, including the word Losant in that path will result in permission errors.
The docs can help explain this a bit more: https://docs.losant.com/applications/access-keys/#additional-mqtt-topics-access
If you are creating a custom topic, you can follow Heathâs workflow example above (option 2), and the topic subscription path in the configuration could be for example: myapplication/{{deviceID}}/devices.
Thanks,
@Aidan_Zebertavage
before I received your reply, I tested with just using topic âdevicesâ from the device, and that worked!
What if someone else would use that same topic? Is that possible?
Or is it still tied to the client ID used so that canât happen?
Glad you were able to get it working.
In response to your follow up question, the custom topic is scoped only to your application and therefore the client ID associated with your application. So even if another user defined that custom topic, it would only be referencing values within their application.
Thanks,
@Aidan_Zebertavage
Iâve seen a couple of threads of this issue, Iâve read them extensively but Iâm still having some questions. In my case, the MQTT client and Losant MQTT broker work as long as:
- MQTT Broker URL is correct (which it is)
- MQTT path matches (whether device or non-device, depending on access key; which it does)
- Access Key and Secret are correct (which they are)
- ClientID matches device clientID (which it does but for just that one device):
#4 is my predicament (and what Iâm getting at in the threads, seems to be, the same issue) because the clientâs MQTT message is/will not just be on that one device but many. How do I solve the clientID for not just this one particular device but for all MQTT device msgs? I know Iâm beating a dead
here, but is the solution to my case the same as discussed herewith? I want to make sure, before I keep
that Iâm on the right
track⌠
Hi @Jose_Cruz,
As I understand it, your issue stems from using a single MQTT client to report data for multiple devices. While there is not a perfect way to resolve this, I do think weâve identified a workable solution.
Youâll need to create a custom MQTT topic to report to. Then, in an application workflow, begin with an MQTT Trigger Node with the same MQTT Topic/Path that is configured in your MQTT client - so in your case the topic configured in your MQTT Client should match what is configured in the MQTT Trigger node, which is devices.
With this setup, we need a way to differentiate your devices as they report on the same topic to the Application Workflow. A unique identifier needs to be sent with each device report through your MQTT client, such as a custom unique number that you manage, a serial number, mac address, or something along those lines.
From there, use a Device: Get node and query to Match All Tags, with your key template set to the macId of your devices (or some other unique identifier) - this allows you to make the association between the specific device that is currently reporting data and its deviceID in Losant. Should that device be recognized, you can then set the device state using the Device: State node.
Iâve provided a couple of screenshots below of what this configured workflow would look like.
Hope this helps!
@Aidan_Zebertavage
@Aidan_Zebertavage, I got it working including following your advice on âmatchingâ the device to a unique identifier that comes along with the MQTT message. Problem is, Client/Losant broker still expect a âClientIDâ as shown above as #4 as part of the MQTT âauthenticationâ, which of course belongs ONLY to 1 device in Losant regardless of my unique identifier (i.e. macID-ish). If I donât provide this specific ClientID, the MQTT message is not even routed. What could I be missing and/or need to do in this case? Thanks, 
I see more MQTT discussions, including @Alex_Ullrich 's Managing Multiple MQTT CONXs . @Aidan_Zebertavage, @anaptfox mentioned on that post that there will be a âfollow up on that featureâ - does this mean Losant is âworkingâ on some kind of âaddedâ feature(s) to the current MQTT brokerage, and if so, when can we âexpectâ +/- an update on it? Thanks! 
Unfortunately, we canât give exact updates on when new features will be released. However, yes, this is a feature ticket within our system right now.
But, what I can do is, add your +1 to that, and if you have any ideas and expectations, I can provide that input to the product team!
Excellent; thanks! 





