Callbacks for Subscriptions? #39
Unanswered
spmatthews03
asked this question in
Q&A
Replies: 1 comment
-
Hello, do you mean the callback for when a PUBLISH message is received? Since a PUBLISH can only be received if you have subscribed to a specific topic or topic filter, I assume that's what you need. You define the callback when instantiating the client just like this: val client = MQTTClient(
MQTTVersion.MQTT5,
"test.mosquitto.org",
1883,
null
) {
// Callback where it is the PUBLISH packet received. You can check the topic of the packet to understand from which subscription you got it
println(it.topicName)
println(it.payload?.toByteArray()?.decodeToString())
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I can see how to subscribe, but how do I call a callback when a subscription is triggered? Does it go inside the client block with a when statement? or somewhere else?
Beta Was this translation helpful? Give feedback.
All reactions