Allow structured JSON data for device attributes

I’m new to Losant, and it looks great so far! I’m using it to monitor machines that have rather complex notions of “status,” including inventory counts for several items that the machines sell. To the best of my knowledge, we can’t use nested objects as device attributes, so I thought I might start a conversation on whether that is something the team has considered.

For example, it would be awesome if I could define my device’s attributes as a JSON object (using some shorthand here):

{
  status: string,
  inventory: {
    item1: {
      name: string,
      count: number
    },
    item2: {
      name: string,
      count: number
    }
  }
}

Even better if the data object could contain an array of other objects, rather than explicitly enumerating each item in the list (item1, item2, etc.).

I realize this is pretty complex compared to a flat list of attributes, but it would be awesome to, for example, trigger a conditional on payload.inventory.item1.count (or, better, payload.inventory.items[0].count) instead of trying to pack all of this type of nested attribute into a flat list. The only way I can picture doing this now is to “unroll” my nested object into a flat structure, giving rise to attribute names like inventory-items-0-count.

I noticed that the home page suggests some food-service vendors use Losant for inventory; do you have any advice on how to track more complex state like this?

Thanks!
Travis

1 Like

This is an interesting use-case and something we had not previously considered. We have a food service company using weight to track inventory. They treat each item as a separate device, which I believe would also work in your scenario as well.

So instead of unrolling this payload into a single device with a bunch of inventory-items-0-count attributes, you would have several item devices and report count as one of it’s attributes. Breaking them into separate devices also allows much more granular control over dashboarding and workflow triggering.

We’ll brainstorm a bit on how to potentially support nest attributes, but for now, I would recommend the multiple-device work-around.

A nested structure would be great for us too. In our case we have engine controllers which report Binary out and Binary In states. Now the meaning of indicidual bits vary between devices. The controllers have bit tables which describe the meaning of the bit. So we currently log a single field as follows

“BIN”: {
“0”: “Emergency stop”,
“5”: “Low Coolant”,
“6”: “Flow Switch”
},

In other words a dictionary with bit set and it’s meaning. Alternately I could do it as a list with empty elements for bits not set.

How ever we can have up to 16 possible bits for a single register.
And we can have multiple IO cards. By default we always have two 16bit registers. Only counting those two and excluding unused bits I would need approx 20 properties to account for each.

Thats a lot of potential additional properties.

A nested structure would be far more efficient.

Cheers

T

Hi everyone.
I am trying to implement nested array , and I see, that works locally but I dont see it on debug window…
Is not allowed yet? will ever be ?

Iam currently sendign one payload (flat) per sensor but it will get quite difficult to manage in the future with several sensors running at the same time reporting…

Thanks a lot

The first place I would recommend checking is the Application Communication Log. This will show any reported state for that application and indicate any errors. If there was an error with the state message, it may not show up in the debug window within a workflow.

Fixed. I am able to get nested array in payload, solved extending MAX_MQTT_PACKET_SIZE . Now I have a question . How can I retrieve that data from array and display it in a dashboard? I could but is a comma separated value in a gauge, not very nice… Help please. thanks a lot.

Array data is not something very well supported by our dashboard. Mostly because we don’t know what the array is supposed to represent. For example, what does it mean to display an array of values on a gauge? A gauge is typically used to display a single value. If you do display an array, the best we can do is display a string version of it.

For your use-case, what does the data in the array represent? There might be some processing you can do in the workflow to convert the array into a higher-level value that’s more easily displayed on the dashboard.

Hi Brandon, yes I was thinking about that, managing the array ( list of values of temperature sensors from one single device ) That clears out my doubts. I’ll try from workflow and start from there to see what comes out. Thanks a lot , very kind of you.