Suggest including message-type in the json of mqtt messages

As of current the type of message (rx, status, error, ack,…) is not given in the body of the json, only in the topic of the mqtt.

I have an application where a ‘pay’ per topic subscribed, meaning I will want to minimize the subscriptions and subscribe only to application/# . Thus to know what kind of message I’m reciving and routing it to the correct handler I would want a key ‘messageType’ in the json-body.

example of how an acknowledge message would look.

{
"messageType:“ack”,
“applicationID”: “123”,
“applicationName”: “temperature-sensor”,
“deviceName”: “garden-sensor”,
“devEUI”: “0202020202020202”,
“acknowledged”: true,
“fCnt”: 12,
“tags”: {
“key”: “value”
}
}

Many thanks and cheers for a great product. :beers:

Regards
Nathan

Even when the client subscribes to application/#, the full MQTT topic should be available per received message, which should make it possible to route it to the correct handler in your application. Adding a messageType seems therefore redundant to me.

E.g. in Go a MQTT message has the following interface:

type Message interface {
    Duplicate() bool
    Qos() byte
    Retained() bool
    Topic() string
    MessageID() uint16
    Payload() []byte
    Ack()
}

(mqtt package - github.com/eclipse/paho.mqtt.golang - Go Packages)

1 Like

Could not find topic data availible in the MQTT driver I use in my controller. It only give me the message body (i.e. Payload).

What I can do is to subscribe on all rx messages, on all status messages and so forth, that will separate the messages into 6 streams (rx, ack, status,…) , while still not having to setup a stream for every device.

I see that in the configuration file it is possible to change the template for MQTT topics, is it possible to change so that it will publish all the messages on single topic? Example for rx message set it to

plink_topic_template="application/device/rx"

This given that I don’t use the topic and the application and devUEI are availible in the body of each message.

However I found identifier keys I can use to identify what kind of message it is even though lacking message type:

Identifiers I found are:
For rx messages: Contains key “data”:
For status message: Contains key “externalPowerSource”:
For ack messages: contain key “acknowledged”:
For error: contains key: “error”:
For join messages: Do not contain any of above keys