MQTT: Asset - Update attribute by AttributeEvent

Hello,

My question is simple, but I’m not able to move forward, so I came to ask for some help.

Through HTTP I can update an attribute of an asset through this endpoint:
- http://localhost/api/{{realm}}/asset/{{assetId}}

with a payload similar to this:

    {
      "ref": {
            "id": "BCkOADICFykhLh8EFhMKAz",
            "name": "notes"
        },
        "value": "HTTP method update"
    }

I would like something similar for MQTT, which describes in the payload which asset and attribute I want to change (as they are different attributes)

I took a look at these documentations:


This seems to be the solution I’m looking for, but I can’t find the JSON structure. I’m always getting this exception:

com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Could not resolve subtype of [simple type, class org.openremote.model.attribute.AttributeEvent]: missing type id property 'eventType'
 at [Source: (String)"{
  "ID": "BCkOADICFykhLh8EFhMKAz",
  "name": "KModel_F_WI",
  "attribute": {
    "name": "notes",
    "value":"Next Try"
  }
}"; line: 8, column: 1]

I’m currently trying to send my payload to this topic:
/{{realm}}/{{clientId}}/writeattribute

These were the payloads I tried:

{
  "id": "BCkOADICFykhLh8EFhMKAz",
  "name": "Name_Asset",
  "attribute": {
    "name": "notes",
    "value":"Next Try"
  }
}
{
    "ref": {
        "id": "BCkOADICFykhLh8EFhMKAz",
        "name": "notes"
    },
    "value": "Next Try"
}
{
    "id": "BCkOADICFykhLh8EFhMKAz",
    "name": "Name_Asset",
    "type": "ThingAsset",
    "attributes": {
        "notes": {
            "type": "text",
            "value": "Next Try",
            "name": "notes"
        }
    }
}

I would like to know what exactly is the structure needed to work with the AttributeEvent, what should I send in the payload?

Any help would be appreciated, thanks.

Again, I don’t know if this is the best method, but I got a satisfactory resolution for me.
This was the minimum structure I identified after subscribing to the topic of an attribute:

Topic:
{{realm}}/{{MQTT-ClientID}}/writeattribute

Payload:

{
  "eventType" : "attribute",
  "attributeState" : {
    "ref" : {
      "id" : "BCkOADICFykhLh8EFhMKAz",
      "name" : "notes"
    },
    "value" : "MQTT OK!",
    "deleted" : false
  }
}

It worked for me.
If there are any best practices for working with this class, please share, thanks.

1 Like