# MQTT publishing

**URL:** <https://forums.losant.com/t/mqtt-publishing/3026>\
**Category:** Help\
**Tags:** mqtt\
**Created:** [June 9, 2020, 2:08pm UTC](https://forums.losant.com/t/mqtt-publishing/3026 "2020-06-09T14:08:20Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![Heath](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/heath/32/3036_2.png) [@Heath](https://forums.losant.com/u/Heath)\
**Post date:** [June 10, 2020, 7:28pm UTC](https://forums.losant.com/t/mqtt-publishing/3026/13 "2020-06-10T19:28:01Z")

</div>

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.

 ![Screen Shot 2020-06-10 at 11.44.00 AM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/e/eb9f75c3d3fdf3905f210c7d64126c7ea34812e6.png)

Once you’re sending MQTT messages to that topic, you can use a JSON: Decode node to format the string to an Object.

 ![Screen Shot 2020-06-10 at 11.46.04 AM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/3/37c66c4cc0e6bbac2cf0c470fbe04033844c640e.png)

Using a Loop Node, you can loop through all the devices in the “devices” array sent along with the MQTT package.

 ![Screen Shot 2020-06-10 at 11.47.59 AM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/7/77cfd3ec3632277ede2fea5debaca94e0c6d8811.png)

The Loop Node can then report state to each deviceID listed in the “devices” array.

 ![Screen Shot 2020-06-10 at 11.49.18 AM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/e/e1037139854041b2a09ae9a976f263e9d849ad8f.png)

Here’s the example payload that was used to trigger this workflow.

```auto
{
  "devices": [ 
{
"deviceId":"5d35d2ece9bcf1000957fa02",
    "temperature": 72
  },
{
"deviceId":"5dcedf089285680007ea7974",
    "temperature": 40
  } 
] 
}

```

And, here’s the workflow export:  
[mqtt-state-ingest-develop.flow](https://forums.losant.com/uploads/short-url/tPq7N80geBm3J1uW0mKJZF45879.flow) (3.2 KB)

Thanks,  
Heath

---

_[View the full topic](https://forums.losant.com/t/mqtt-publishing/3026)._
