Combine MQTT payloads to one device state update

Problem: Application Workflow is triggered multiple times by each device because the data is split between MQTT payloads

My Attempted Solution:
I am trying to combine two different MQTT payloads into 1 device state update. What I have tried to do is set up a latch that connects once both MQTT payloads come in. I got that working and the latch connects only once both topics have come in but the state update still happens twice. Is there a better way to make sure that the information from both payloads is put into a single device state update?

This image shows the MQTT processing workflow. After the device is updated that triggers a separate workflow that takes actions based on the data. It is important that the second workflow only triggers once per device and that it has all the data it needs.

I know a solution would be to try to put all the data into one MQTT payload before it is sent out, but in the meantime and if that’s not possible I need a workaround to combine the data

Hello @Jackson_Miller,

Thank you for the great explanation and the screenshot, it’s a huge help

Are you sending along a timestamp in the messages? Are the two MQTT messages coming into Losant at about the same time? Or is there some measurable amount of time between them?

Any additional information you can provide about your use case will greatly help me give you the best answer I can.

Thank you,
Heath

Hi Heath,

The messages are essentially coming in around the same time within a few milliseconds and its just the fact that they have to arrive as two separate packets. Hope that helps.

Jackson

@Jackson_Miller,

Thanks for that information. Are you sending a timestamp in each MQTT message? Would you be able to include a timestamp if not?

Without a timestamp, combining two MQTT messages in a single workflow only milliseconds apart will be very difficult to do due to race conditions.

Thank you,
Heath

Yes there is a timestamp
image

Assuming the “Time” property in each of your MQTT messages is the same timestamp - and I make that assumption because you are trying to tie the two state reports together as one - then you should be able to use the value of that property in a Device: State Node to record the values in each message at the same time in our time series database.

You’ll want to use the “Use the time at the specified payload path” option and define where to find that time. You’ll need to parse the message property first, which you can do using a JSON: Decode Node.

That worked thank you